0% found this document useful (0 votes)
12 views2 pages

PHTMCODE

This document contains an Arduino sketch for a temperature and humidity monitoring system using a DHT11 sensor and an ultrasonic distance sensor. It controls a fan based on temperature readings and activates a buzzer if water levels are low. The system displays the temperature, humidity, fan status, and water level on an I2C LCD screen.

Uploaded by

Arabel Fig
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

PHTMCODE

This document contains an Arduino sketch for a temperature and humidity monitoring system using a DHT11 sensor and an ultrasonic distance sensor. It controls a fan based on temperature readings and activates a buzzer if water levels are low. The system displays the temperature, humidity, fan status, and water level on an I2C LCD screen.

Uploaded by

Arabel Fig
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <LiquidCrystal_I2C.

h>
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

#define TRIGPIN 3
#define ECHOPIN 4

#define FANPIN 8
#define BUZZERPIN 7

DHT dht(DHTPIN, DHTTYPE);


LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C LCD address

void setup() {
[Link]();
[Link]();
[Link]();

pinMode(TRIGPIN, OUTPUT);
pinMode(ECHOPIN, INPUT);
pinMode(FANPIN, OUTPUT);
pinMode(BUZZERPIN, OUTPUT);

[Link](0, 0);
[Link]("PH&TM READY! :)");
delay(2000);
[Link]();
}

void loop() {
float temp = [Link]();
float hum = [Link]();

// NaN Check
if (isnan(temp) || isnan(hum)) {
[Link]();
[Link](0, 0);
[Link]("Sensor Error");
digitalWrite(FANPIN, LOW);
noTone(BUZZERPIN);
delay(2000);
return;
}

digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);

long duration = pulseIn(ECHOPIN, HIGH, 30000);


float distanceCM = duration * 0.034 / 2;

bool fanOn = temp >= 28;


digitalWrite(FANPIN, fanOn ? HIGH : LOW);
bool waterLow = (duration == 0 || distanceCM > 8);
if (waterLow) {
tone(BUZZERPIN, 1000);
delay(100);
noTone(BUZZERPIN);
} else {
noTone(BUZZERPIN);
}

// LCD Display
[Link](0, 0);
[Link]("T:");
[Link](temp, 1);
[Link]((char)223);
[Link]("C H:");
[Link](hum, 0);
[Link]("%");

[Link](0, 1);
[Link]("FAN:");
[Link](fanOn ? "ON " : "OFF");
[Link](" W:");
[Link](waterLow ? "LOW " : "OK ");

delay(1000);
}

You might also like