BREAKING NEWS

19 April 2016

PROGRAMMABLE THERMOSTAT WITH ARDUINO

What I'm about to describe is a thicker design of the previous year. The idea came analyzing the consumption related to heating my house. Unfortunately, the thermostat is currently installed does not allow a change of time in fiction temperature of the day and night, also fear that the probe does not acquire a very precise temperature, for this reason, consumption is higher than necessary. So I decided to build one, which allows to automatically vary the temperature for the day and the night, and that indicates the temperature and humidity of the room in a precise manner.


 the following components are required:
and the following libraries:

Connections to the LCD module is for information only, connect it according to the model you choose, as described in the library.
The thermostat will only interface to the user via the potentiometer dial, the display, and the RGB LED. For this reason, it is necessary to leave the accessible USB port of the Arduino also closed container module, to allow the RTC module programming and updating of the code.


The only user-editable variable is the daily temperature; the LED indicates by GREEN light when the heating is on, and through the RED off the same. The night temperature is the intervention zone are set through code; the operation hysteresis is always set by 1 ° C code. To schedule the time in the RTC module is required uncomment the section in the code.




Source code 
*/
#include “Arduino.h”
#include “Wire.h”
#include "DS1307.h"
#include "LiquidCrystal.h"
#include "idDHT11.h"
int relay = 4;
int pot_pin = 1;
int red_led = 5;
int green_led = 3;
int lcd_bkl = 13;
float act_temp = 0.0;
float set_temp = 15.0;
int hum = 0;
int last_time = 0;
int hys = 1;
int night_temp = 17;
int prev_temp = 0;
int prev_time = 0;
int delay_set = 5;
byte degree[8] = {
B01000,
B10100,
B01000,
B00011,
B00100,
B00100,
B00011,
};
//INITS
LiquidCrystal lcd(12, 11, 10, 7, 8, 9, 6); //LCD
init
int idDHT11pin = 2;
//Digital pin for comunications DHT11
int idDHT11intNumber = 0;
//interrupt number (must be the one that use the previus defined pin (see
table above) DHT11
void dht11_wrapper(); //
must be declared before the lib initialization
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);
DS1307 clock;
//define a object of DS1307 class
void setup()
{
Serial.begin(9600);
pinMode(relay, OUTPUT);
pinMode(green_led, OUTPUT);
pinMode(red_led, OUTPUT);
pinMode(lcd_bkl, OUTPUT);
clock.begin();
lcd.createChar(0, degree);
/* *******************SET DATE-TIME******************
clock.fillByYMD(2013,11,20);//Jan 19,2013
clock.fillByHMS(02,03,00);//15:28 30"
clock.fillDayOfWeek(TUE);//Saturday
clock.setTime();//write time to the RTC chip
// ****************************************************/
lcd.begin(16, 2); // start the LCD library
lcd.setCursor(0,0); // set cursor to 0 pos
}
void dht11_wrapper() //necessary to initialize the idDHT11 library
{
DHT11.isrCallback();
}
void stop_pump() //turn off the relay and set the LED to RED
{
digitalWrite(relay, 0);
analogWrite(red_led, 255);
analogWrite(green_led, 0);
}
void start_pump() //turn on the relay and set the LED to GREEN
{
digitalWrite(relay, 1);
analogWrite(red_led, 0);
analogWrite(green_led, 255);
}
void print_LCD() //Print status on 16x2 LCD display
{ //line0
lcd.setCursor(0,0);
lcd.print(act_temp, 0);
lcd.setCursor(2,0);
lcd.write(byte(0));
lcd.setCursor(4,0);
lcd.print("|");
lcd.setCursor(5,0);
if(clock.hour < 10) // print 0 before hour < 10
{
lcd.print("0");
lcd.setCursor(6,0);
lcd.print(clock.hour, DEC);
} else (
lcd.print(clock.hour, DEC));
lcd.setCursor(7,0);
lcd.print(":");
lcd.setCursor(8,0);
if(clock.minute < 10) // print 0 before minutes < 10
{
lcd.print("0");
lcd.setCursor(9,0);
lcd.print(clock.minute, DEC);
} else (
lcd.print(clock.minute, DEC));
lcd.setCursor(10,0);
lcd.print("|");
lcd.setCursor(12,0);
lcd.setCursor(12,1);
lcd.print(set_temp, 1);
//line1
lcd.setCursor(2,1);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print(DHT11.getHumidity(), 0);
lcd.setCursor(4,1);
lcd.print("|");
lcd.setCursor(5,1);
lcd.print(clock.dayOfMonth, DEC);
lcd.setCursor(7,1);
lcd.print("/");
lcd.setCursor(8,1);
lcd.print(clock.month, DEC);
lcd.setCursor(10,1);
lcd.print("|");
lcd.setCursor(12,1);
lcd.print(set_temp, 1);
lcd.setCursor(4,0);
}
void DHT11_acquiring() // get informations from DHT11 sensor
{
DHT11.acquire();
while (DHT11.acquiring());
int result = DHT11.getStatus();
switch (result)
{
case IDDHTLIB_OK:
Serial.println("OK");
break;
case IDDHTLIB_ERROR_CHECKSUM:
Serial.println("Error\n\r\tChecksum error");
break;
case IDDHTLIB_ERROR_ISR_TIMEOUT:
Serial.println("Error\n\r\tISR Time out error");
break;
case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
Serial.println("Error\n\r\tResponse time out error");
break;
case IDDHTLIB_ERROR_DATA_TIMEOUT:
Serial.println("Error\n\r\tData time out error");
break;
case IDDHTLIB_ERROR_ACQUIRING:
Serial.println("Error\n\r\tAcquiring");
break;
case IDDHTLIB_ERROR_DELTA:
Serial.println("Error\n\r\tDelta time to small");
break;
case IDDHTLIB_ERROR_NOTSTARTED:
Serial.println("Error\n\r\tNot started");
break;
default:
Serial.println("Unknown error");
break;
}
}
int day_time() //set the value according to day - hour
{
int x = (clock.hour);
if(x > 6 && x < 23)
return 1; //if daytime set 1
else
return 2; //if nighttime set 2
}
int seconds_elapsed()
{
int elapsed_secs = 0;
if(prev_time > clock.second) //necessary to work with
60 base count
{ elapsed_secs =
(
60-prev_time)+clock.second;
}
else
{ elapsed_secs =
clock.second -
prev_time;
}
return elapsed_secs;
}
int minutes_elapsed()
{
int elapsed_mins = 0;
if(last_time > clock.minute) //necessary to work
with 60 base count
{ elapsed_mins =
(
60-last_time)+clock.minute;
}
else
{ elapsed_mins =
clock.minute - last_time;
}
return elapsed_mins;
}
void loop()
{
int x = 0;
bool change_temp = 0;
//get temp and date-time
DHT11_acquiring();
act_temp = (DHT11.getCelsius());
clock.getTime();
//Read pot pin
x = analogRead(pot_pin);
x = map(x, 0, 1023, 15, 45);
//if temp is set to the minumum turn off the control and backlight
if (x == 15)
{ stop_pump();
print_LCD();
lcd.setCursor(11,0);
lcd.print("-OFF-");
digitalWrite(lcd_bkl, 0);
goto stop;
}
//5 seconds after the last set turn off backlight
if(seconds_elapsed() >= delay_set)
digitalWrite(lcd_bkl, 0);
//if the potentiometer is turn set a new target temp and turn on backlight
if(x != prev_temp)
{ digitalWrite(lcd_bkl, 1);
prev_time = (clock.second);
change_temp = 1;
delay(100);
}
//if is daytime set the target temp by the potentiometer
if (day_time() == 1)
{ set_temp =
(((x+15)*10)/2)/10.00; // set temperature by
potentiometer in 0.5°C
lcd.setCursor(11,0);
lcd.print(" set");
lcd.setCursor(15,0);
lcd.write(byte(0));
}
//else if is night time set the temp to night_temp value
else if (day_time() == 2)
{ set_temp =
night_temp;
lcd.setCursor(11,0);
lcd.print("sleep");
}
//if delay_time is past turn on the temp control
if (minutes_elapsed() >= delay_set || change_temp == 1)
{ if (
act_temp <
(
set_temp -
hys)) //if room is cold turn on the
heater
{ start_pump();
last_time = (clock.minute);
}
else //else if room is warm keep off the heater
{ stop_pump();
last_time = (clock.minute);
}
change_temp = 0;
}
// print SET on LCD, set prev_temp value
print_LCD();
prev_temp = x;
delay(100);
stop:
delay(500);
}
The thermostat is working well, I can be satisfied. Definitely improved in various aspects, perhaps with a future integration for control via LAN or WiFi, but for now does what little he should do.

Share this:

2 comments :

  1. Shutting down the AC unit before cleaning and maintenance always helps out.Heating and Cooling Toronto Nice tips given above.

    ReplyDelete
  2. Where can I get the DS1307 lib? (#include "DS1307.h")

    ReplyDelete

 
Back To Top
Distributed By Blogger Templates | Designed By OddThemes