This circuit is designed to control an incubator's temperature using a DHT22 temperature and humidity sensor, a 5V relay to switch an AC bulb (used as a heater), and a 120mm 12V fan for air circulation. The system is controlled by an Arduino UNO microcontroller, which interfaces with an LCD display for user feedback and three pushbuttons for user input to set the desired temperature. The relay controls the power to the AC bulb, and the fan is connected to a 12V power supply. The circuit includes resistors for current limiting and pull-up configurations.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
// Configuration of pins
#define DHTPIN 4 // Data pin for DHT22 sensor
#define DHTTYPE DHT22 // DHT sensor type
#define RELAY_PIN 7 // Relay pin for the heater
#define BUTTON_INC 8 // Pushbutton 1: Increase target temperature
#define BUTTON_DEC 9 // Pushbutton 2: Decrease target temperature
#define BUTTON_TOGGLE 10 // Pushbutton 3: Toggle heater on/off
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
float targetTemp = 37.5; // Initial target temperature
bool heating = false; // Heater status
void setup() {
pinMode(RELAY_PIN, OUTPUT);
pinMode(BUTTON_INC, INPUT_PULLUP);
pinMode(BUTTON_DEC, INPUT_PULLUP);
pinMode(BUTTON_TOGGLE, INPUT_PULLUP);
lcd.begin(16, 2); // Initialize the LCD
lcd.backlight();
dht.begin();
Serial.begin(9600);
lcd.setCursor(0, 0);
lcd.print("Incubator Ready");
delay(2000);
lcd.clear();
}
void loop() {
// Read temperature from the sensor
float temperature = dht.readTemperature();
if (isnan(temperature)) {
Serial.println("Failed to read temperature");
return;
}
// Target temperature control with pushbuttons
if (digitalRead(BUTTON_INC) == LOW) {
targetTemp += 0.5;
delay(300);
}
if (digitalRead(BUTTON_DEC) == LOW) {
targetTemp -= 0.5;
delay(300);
}
// Manual heater control
if (digitalRead(BUTTON_TOGGLE) == LOW) {
heating = !heating; // Toggle heater status
delay(300);
}
// Automatic heater control based on temperature
if (temperature < targetTemp) {
heating = true;
} else if (temperature >= targetTemp) {
heating = false;
}
// Heater relay control
digitalWrite(RELAY_PIN, heating ? HIGH : LOW);
// Display temperature, target, and heater status on LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Target: ");
lcd.print(targetTemp);
lcd.print(" C ");
lcd.print(heating ? "ON" : "OFF");
// Delay for the next reading
delay(2000);
}
This code is responsible for reading the temperature from the DHT22 sensor, controlling the relay based on the temperature and user input, and displaying the current temperature, target temperature, and heater status on the LCD. The pushbuttons allow the user to adjust the target temperature and toggle the heater on or off.