0% found this document useful (0 votes)
2 views6 pages

Arduino Code Temp and Hum

This document contains an Arduino code for a temperature and humidity monitoring system using a DHT22 sensor and an LCD display. It defines thresholds for temperature and humidity, controls LED indicators based on sensor readings, and displays the values on the LCD. The system updates readings every 2 seconds and handles sensor errors appropriately.

Uploaded by

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

Arduino Code Temp and Hum

This document contains an Arduino code for a temperature and humidity monitoring system using a DHT22 sensor and an LCD display. It defines thresholds for temperature and humidity, controls LED indicators based on sensor readings, and displays the values on the LCD. The system updates readings every 2 seconds and handles sensor errors appropriately.

Uploaded by

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

#include <Adafruit_Sensor.

h>
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Define pins
#define DHTPIN 2
#define DHTTYPE DHT22
#define TEMP_RED_LED 3
#define TEMP_GREEN_LED 4
#define HUM_RED_LED 5
#define HUM_GREEN_LED 6

// Define thresholds
#define TEMP_MIN 20.0
#define TEMP_MAX 30.0
#define HUM_MIN 40.0
#define HUM_MAX 60.0

DHT dht(DHTPIN, DHTTYPE);


LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C
address 0x27, adjust if needed

void setup() {
[Link](9600);
[Link]();
[Link]();
[Link]();
// Initialize LEDs
pinMode(TEMP_RED_LED, OUTPUT);
pinMode(TEMP_GREEN_LED,
OUTPUT);
pinMode(HUM_RED_LED, OUTPUT);
pinMode(HUM_GREEN_LED, OUTPUT);
}

void loop() {
// Read sensor values
float temp = [Link]();
float hum = [Link]();

// Check for sensor read errors


if (isnan(temp) || isnan(hum)) {
[Link]("Failed to read from DHT
sensor!");
[Link](0, 0);
[Link]("Sensor Error!");
return;
}

// Display on LCD
[Link](0, 0);
[Link]("Temp: ");
[Link](temp);
[Link](" C");
[Link](0, 1);
[Link]("Hum: ");
[Link](hum);
[Link](" %");

// Temperature LED control


if (temp < TEMP_MIN || temp >
TEMP_MAX) {
digitalWrite(TEMP_RED_LED, HIGH);
digitalWrite(TEMP_GREEN_LED,
LOW);
} else {
digitalWrite(TEMP_RED_LED, LOW);
digitalWrite(TEMP_GREEN_LED,
HIGH);
}

// Humidity LED control


if (hum < HUM_MIN || hum > HUM_MAX)
{
digitalWrite(HUM_RED_LED, HIGH);
digitalWrite(HUM_GREEN_LED, LOW);
} else {
digitalWrite(HUM_RED_LED, LOW);
digitalWrite(HUM_GREEN_LED, HIGH);
}
delay(2000); // Update every 2 seconds
}

You might also like