This circuit is designed to monitor temperature using a DHT11 sensor and control an output based on the temperature readings. When the temperature reaches 36 degrees Celsius, the output is turned on, and when it drops to 34 degrees Celsius, the output is turned off. The status of the output and the current temperature are displayed on a 16x2 LCD. The circuit is powered by an Arduino UNO, which also controls the LCD and the relay module that acts as the output. The LCD's contrast is set via a voltage divider.
/*
* This Arduino Sketch turns on an output when the DHT11 sensor senses
* a temperature of 36 degrees Celsius and turns it off when the
* temperature drops to 34 degrees Celsius. It also displays the
* status (ON/OFF) and the temperature on a 16:2 LCD.
* The LCD contrast is controlled via a voltage divider.
* The code avoids debouncing of temperature control and clears the LCD.
*/
#include <DHT.h>
#include <LiquidCrystal.h>
#define DHTPIN 7 // Define the pin connected to the DHT11 data pin
#define DHTTYPE DHT11 // Specify the type of DHT sensor
#define OUTPUT_PIN 13 // Define the pin connected to the Relay Module input
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
// Initialize the LCD and specify the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
pinMode(OUTPUT_PIN, OUTPUT); // Set the relay control pin as output
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
dht.begin(); // Start the DHT sensor
}
void loop() {
float temp = dht.readTemperature(); // Read temperature in Celsius
if (isnan(temp)) { // Check if the reading failed
lcd.clear(); // Clear the LCD
lcd.setCursor(0, 0); // Set the cursor to the top-left position
lcd.print("Error reading"); // Print an error message
lcd.setCursor(0, 1); // Move to the second line
lcd.print("temperature"); // Continue the error message
return; // Skip the rest of the loop
}
lcd.clear(); // Clear the LCD for fresh data
lcd.setCursor(0, 0); // Set the cursor to the top-left position
lcd.print("Temp: "); // Print "Temp: "
lcd.print(temp); // Print the temperature value
lcd.print(" C"); // Print the Celsius symbol
if (temp >= 36) { // If the temperature is high enough
digitalWrite(OUTPUT_PIN, HIGH); // Turn on the relay
lcd.setCursor(0, 1); // Move to the second line
lcd.print("Status: ON "); // Print the status
} else if (temp <= 34) { // If the temperature is low enough
digitalWrite(OUTPUT_PIN, LOW); // Turn off the relay
lcd.setCursor(0, 1); // Move to the second line
lcd.print("Status: OFF"); // Print the status
}
delay(2000); // Wait for 2 seconds before the next reading
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the DHT11 sensor and the 16x2 LCD, reads the temperature, and controls the relay module based on the temperature readings. It also handles the display of temperature and status information on the LCD.