This circuit is designed to monitor temperature using a DHT11 sensor and control a relay based on the temperature readings. The temperature data is displayed on a 16x2 I2C LCD screen. The Arduino UNO serves as the central microcontroller unit to read sensor data, control the relay, and manage the display. The relay is activated when the temperature reaches or exceeds 36 degrees Celsius and is turned off when the temperature drops to 34 degrees Celsius or lower.
/*
* I2C Temperature Controller
*
* This Arduino Sketch reads temperature data from a DHT11 sensor and controls
* a relay module based on the temperature. If the temperature is 36 degrees
* Celsius or higher, the relay is turned on. If the temperature drops to 34
* degrees Celsius or lower, the relay is turned off. The temperature and
* relay status are displayed on a 16x2 I2C LCD screen.
*/
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 7 // Define the pin connected to the DHT11 data pin
#define DHTTYPE DHT11 // Specify the type of DHT sensor
#define RELAY_PIN 13 // Define the pin controlling the relay module
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize the LCD display with I2C address 0x27
void setup() {
pinMode(RELAY_PIN, OUTPUT); // Set the relay pin as an output
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
dht.begin(); // Start the DHT sensor
}
void loop() {
float temp = dht.readTemperature(); // Read the temperature from the DHT sensor
if (isnan(temp)) { // Check if the reading failed
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Error reading");
lcd.setCursor(0, 1);
lcd.print("temperature");
return;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");
if (temp >= 36) { // If the temperature is 36C or higher
digitalWrite(RELAY_PIN, HIGH); // Turn on the relay
lcd.setCursor(0, 1);
lcd.print("Status: ON ");
} else if (temp <= 34) { // If the temperature is 34C or lower
digitalWrite(RELAY_PIN, LOW); // Turn off the relay
lcd.setCursor(0, 1);
lcd.print("Status: OFF");
}
delay(2000); // Wait for 2 seconds before reading again
}
This code is saved as sketch.ino
and is intended to be uploaded to the Arduino UNO microcontroller.