This tutorial will show you how to build a temperature and humidity controlled relay box to control a green house, chicken egg incubator, or any other application that needs a controlled temperature.
Click on the video below for full tutorial…
Check us out on Facebook!
PARTS LIST:
#affiliate links#
SCHEMATIC:
ARDUINO CODE:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
#define light 5 // back light on – off transistor pin
#include <SimpleDHT.h>
#define pinDHT11 6 //data pin
SimpleDHT11 dht11;
byte temperature = 0;
byte humidity = 0;
#define relay 12 // low relay on pin 12
#define relay2 11 // high relay on pin 11
#define button 8 // switch
int last = 1; // button state
int val;
int pot;
int val2;
int pot2;
int pval;
int pval2;
int temp;
int ptemp;
#define dif 5 // temp diff
void setup()
{
lcd.begin(16, 2); // initialize the lcd for 16 chars 2 lines
lcd.clear();
pinMode(relay, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(button, INPUT_PULLUP);
pinMode(light, OUTPUT);
digitalWrite(light, HIGH);
lcd.setCursor(1, 0);
lcd.print(“Temperature”);
lcd.setCursor(0, 1);
lcd.print(“LOW”);
lcd.setCursor(8, 1);
lcd.print(“HIGH”);
lcd.setCursor(15, 0);
lcd.print(“C”);
lcd.setCursor(6, 1);
lcd.print(“C”);
lcd.setCursor(15, 1);
lcd.print(“C”);
pval = analogRead(A0);
}
void loop()
{
pot = analogRead(A0);
val = map(pot, 0, 1023, 0, 40);
pot2 = analogRead(A1);
val2 = map(pot2, 0, 1023, 0, 40);
if (dht11.read(pinDHT11, &temperature, &humidity, NULL))
{
return;
}
temp = (int)temperature;
if (val <= 9 && pval >= 10) // keep LCD correct //
{
lcd.setCursor(4, 1);
lcd.print(” “);
}
pval = val;
if (val2 <= 9 && pval2 >= 10)
{
lcd.setCursor(13, 1);
lcd.print(” “);
}
pval2 = val2;
temp = constrain(temp, 0, 50);
if (temp <= 9 && ptemp >= 10)
{
lcd.setCursor(13, 0);
lcd.print(” “);
}
ptemp = temp;
lcd.setCursor(13, 0);
lcd.print(temp);
lcd.setCursor(4, 1);
lcd.print(val);
lcd.setCursor(13, 1);
lcd.print(val2);
if (digitalRead(button) == LOW ) { // lcd button
if (last == 0)
{
digitalWrite(light, HIGH);
last = 1;
}
else if (last == 1)
{
digitalWrite(light, LOW);
last = 0;
}
}
if (temp <= val) // relay 1
{
digitalWrite(relay, HIGH);
}
else if (temp >= val + dif)
{
digitalWrite(relay, LOW);
}
if (temp >= val2) // relay 2
{
digitalWrite(relay2, HIGH);
}
else if (temp <= val2 – dif)
{
digitalWrite(relay2, LOW);
}
delay(500);
}