loading
Picture of Arduino LCD Thermostat!
In this project we'll use an arduino uno, an LCD and a temperature sensor to control your air conditioning.! Also You can modify the code for a heater. The code is well explained! I show even how I made mine permanent!  
Great your beginners to learn arduino and for hot room that have an old manual a/c. This is a project to try!
 
Remove these adsRemove these ads by Signing Up

Step 1: Prototyping the Test Circuit

Picture of Prototyping the Test Circuit
CIMG5773.JPG

This circuit is to test if the thermostat is working or not. The lcd should display a hello,world! sketch, the the current temperature of the room, and below is the ideal temperature or settemp. If the current temperature is off by a little you may need to adjust the code which calculates the 10 bit number read from A0 into a temperature reading in degrees Fahrenheit. If you need Celsius will will also need to change the line of code the calculates the temperature. If you wan to control an a/c,  you can remove the led and replace it with an N-Channel MOSFET ( Metal Oxide Semi-conductor Field Effect Transistor). Then TO USE A PROTECTION DIODE!  I will go over this as well. In the next step. 

Parts list:
12 volt power supply 
7805 5 volt voltage regulator
arduino uno or other arduino dev board
3x 10k ohm resistors
led
jumper wire
solderless breadboard 
arduino ide
10k potentiometer ( or a 1k ohm and a 220 ohm resistor) (or the 3rd pin can go to ground) 
16x2 Hitachi driven hdd44780 LCD
10k thermistor a.k.a. (10k ohm NTC, (Negative Thermal Coefficient)
2x tactile button switches ( or any other button switch)
usb b type connector to program arduino

For use with an a/c:
N-channel MOSFET 
120VAC 20-40A relay
1N4007 - 1N4004 rectifier diode
a/c

To finalize:
perfboard / PCB
Project enclosure
And tool that everyone should have 

Let's get started!
 

hjaber11 month ago

How to change the set temp???????

Dylon124 (author)  hjaber11 month ago

You use the push buttons with a pull down resistor in this configuration to change the set temp. But do change it for your application, this is a rough version that still could use a little tweaking because the subtle temperature changes trigger the a/c on and off a million times. Good luck!

BonzNumber14 months ago

I made it FINALLY after months of problems!!! i reworked the code a bit and added 3 relays total and a toggle switch cause where i live sometimes you just want it off!

the relays are for

1. hot

2. cold

3. fan

and my switch is a 4 way switch so it can click to heat, cool, fan, and off

thanks a bunch!!! if i get a nice sheild made i may do a kickstarter! do you have a way for me to donate some $ to you?

metalarm10 months ago

Hi Dylon,

Your project seems useful so I tried to replicate it but using Grove-LCD RGB Backlight display instead.

Everything is flowing nicely until I get to the user buttons. Im using a-pushto-off button with only 2 connecting wires.

So the problem I'm facing is, when I pressed the up button, the temperature (settemp) will go up and not stop. Same goes if I press the down button.

I'll give you my codes below but Im sure it's similar..

Please help me if you can. It's giving me sleepless nights... :(

// Declare variables

#include <Wire.h>

#include <EEPROM.h>

#include <Bounce2.h>

#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 30;

const int colorG = 30;

const int colorB = 60;

float tempC;

float settemp;

int tempPin = A0; //temp sensor plugged in pin 0

int ledPin = 13; //closest to ground

int fan1 = 2; // fan connected to pin 6

int swtu = 7;

int swtd = 6;

Bounce bouncer = Bounce();

// Write setup programme

void setup()

{

Serial.begin(9600); //Open serial port to communicate. sets data rate to 9600

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// initialize the serial communications:

lcd.setRGB(colorR, colorG, colorB);

lcd.print("Temp = ");

delay(250);

pinMode(ledPin, OUTPUT);

pinMode(fan1, OUTPUT);

pinMode(swtu, INPUT);

bouncer.attach (swtu);

bouncer .interval(5);

pinMode (swtd, INPUT);

bouncer.attach (swtd);

bouncer .interval(5);

EEPROM.read(1); //make eeprom memory address

}

//Write loop that will control the

void loop()

{

tempC = analogRead(tempPin); // read the analog value from the lm35 sensor.

tempC = (5.0 * tempC * 100.0)/1024.0; // convert the analog input to temperature in centigrade.

lcd.setCursor(8,0);

lcd.print(tempC);

lcd.print("'C");

Serial.print((byte)tempC); // send the data to the computer.

settemp = EEPROM.read(1); // read the settemp at memory 1

delay (250);

if (digitalRead (swtu)==1)

{

(settemp ++);

EEPROM.write(1, settemp);

}

else{

}

if (digitalRead(swtd)==1)

{

(settemp --);

EEPROM.write(1, settemp);

}

else {

}

if (tempC > settemp)

{

digitalWrite(ledPin, HIGH);

digitalWrite(fan1, HIGH);

}

else

{

digitalWrite(ledPin, LOW);

digitalWrite(fan1, LOW);

}

lcd.setCursor(0,1);

lcd.print("Set Temp To: ");

lcd.print(settemp);

Serial.print((byte)settemp);

// EEPROM.write(1, settemp);

delay(250);

}

In the code, you have

if (temp > settemp) // if the temperature exceeds your chosen settemp
{
digitalWrite (led, 1); // turn on the led
}
else // if that doesn't happen, then turn the led off
{
digitalWrite (led,0);
}

I'm guessing that turning on the LED also activates the MOSFET and turns on the A/C, correct?

My main question is this: For someone who has both a heater and an A/C, could you have it do something like this:

if (temp > settemp + 2) // if the temperature exceeds your chosen settemp
{
digitalWrite (led, 1); // turn on the led for the A/C circuit
}

elseif (temp < settemp - 2) //If the temperature exceeds your settemp

{

digitalWrite (led, 1); // turn on the LED for the heater circuit

}
else // if that doesn't happen, then turn the led off
{
digitalWrite (led,0);

// digitalWrite (ledX,0); //ledX would be the second led for the heater circuit
}

My goal with this is to replace the "heat/cool" switch on a regular thermostat, and have it be a pure climate control system (where it either turns the heat or A/C on to keep the temp at what you want). Also, I added the + 2 and - 2, because most furnaces and A/C's won't start until the temp is 2 degrees above/below your set temp. It might have to be tweaked out to 3 or 4, depending on whether your furnace and/or A/C stops before the actual temp gets more than 2 degrees from your set temp. Otherwise, your heater and a/c will constantly be turning off and on to keep your temp set.

Have a great day.:)
Patrick.

Dylon124 (author)  PatrickDickey527611 year ago

Sorry for the late response. You would need a second output or "led" which yes, is connected to a MOSFET then to a relay. I'm still new to arduino coding, so I really can't give you valuable code. The constant switching on and off is a problem that I have experienced, but you can make the code realize or have a hysteresis or a number/ temperature that will take into account the temperature lag and other stuff. Here is a helpful link because I can't explain stuff right.

I hope it helps

Dylon J

Dylon124 (author)  PatrickDickey527611 year ago

Sorry for the late response. You would need a second output or "led" which yes, is connected to a MOSFET then to a relay. I'm still new to arduino coding, so I really can't give you valuable code. The constant switching on and off is a problem that I have experienced, but you can make the code realize or have a hysteresis or a number/ temperature that will take into account the temperature lag and other stuff. Here is a helpful link because I can't explain stuff right.

I hope it helps

Dylon J

Dylon124 (author)  PatrickDickey527611 year ago

Sorry for the late response. You would need a second output or "led" which yes, is connected to a MOSFET then to a relay. I'm still new to arduino coding, so I really can't give you valuable code. The constant switching on and off is a problem that I have experienced, but you can make the code realize or have a hysteresis or a number/ temperature that will take into account the temperature lag and other stuff. Here is a helpful link because I can't explain stuff right.

I hope it helps

Dylon J

whiteneon1 year ago
The code is a good beginning but needs revision on the EEPROM.write command being used through every loop. EEPROM has a limited number of write cycles before it wears out. A better idea would be to only write to it periodically or only when the value to be written changes.
Dylon124 (author)  whiteneon1 year ago
I know what you mean. But I used a cheap atmega8 that can be rewriten about 10,000 times before having errors. Plus, I really new to coding up the arduino.
The easiest way to reduce the number of write cycles would be to move the 'EEPROM.write' command to a new line just below each of the
'(settemp ++);' and '(settemp --);' lines. This way the EEPROM is only being written to each time a button is being pressed.
Dylon124 (author)  gadgetiom1 year ago
thx I'll try and change my code
Dylon124 (author) 2 years ago
Add your relay pin control to pin 10-8 or else you will flick to relay on and of rapidly it the start of the code.