Introduction: 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!

Step 1: Prototyping the Test Circuit

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
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!

Step 2: The Code

So the code:

// written by Dylon Jamna (ME!)
// include the library code
#include <EEPROM.h>
#include <LiquidCrystal.h>// include the library code
int tempPin = A0;  // make variables// thermistor is at A0
int led =13; // led is at pin
float temp;  // make a variable called temp
float settemp; // make a variable called temp
int swtu = 7;  // switch up is at pin 7
int swtd = 6;   // switch down is at pin 6
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // lcd is at 12,11,5,4,3,2

void setup() {
pinMode (led,1);  // make led or pin13 an output
Serial.begin (9600); // set the serial monitor tx and rx speed
lcd.begin(16, 2); // set up all the "blocks" on the display
lcd.setCursor(0,0); // set the cursor to colum 0 row 0
lcd.print("hello, world!"); // display hello world for 1 second
lcd.clear(); // clear the lcd
}

void loop() {

int tvalue = analogRead(tempPin);  // make tvalue what ever we read on the tempPin
float temp = (tvalue / 6.388888888889); // the math / conversion to temp
lcd.setCursor (0,0); // set the cursor to 0,0
lcd.print (temp);  // Print the current temp in f
lcd.print ('F');
Serial.println (temp);  // print the temp it the serial monitor

delay (250); // wait for the lcd to refresh every 250 milliseconds

if             // if we se the switch up pin reading on 1 or 5 volts
{
settemp ++  // add one to the settemp, the settemp is the ideal temperature for you

;
}

else{// other wise do nothing

}

if
(digitalRead (swtd) == 1)// if we detect a 1 on the other switch pin
{
(settemp --);// subtract one fromm the settemp

}
else {
// else, do nothing
}

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);
}

lcd.setCursor (0,1); // set the cursor to 0,1
lcd.print ("Set To "); // Print set to and your ideal temperature in f
lcd.print (settemp);
lcd.print ('F');
Serial.println(settemp);  // Print the settemp in the serial montior

EEPROM.write (1,settemp); /* write the most recent settemp in eeprom data stoage
so that if the power is disconnected, you settemp is saved!*/

delay (250); // wait 250 milliseconds

} // we're done

Step 3: The Build

Now to actually make this project useful we need to make it more permanent.  We do this by soldering it to the perfboard. Now there are many ways to solder on perfboard. The way I prefer to solder it is by soldering on thick buses for power and ground made of solder. Then I strip, tin, and solder ribbon cable wire to every necessary connection. But you can tin track on the board, or wire above the board and solder below which is very popular. Also to switch our a/c on or off we need to modify the led. Now there are a few seps to follow.
Step 1 - remove the led
Step 2- attach the gate of your N channel MOSFET Check your datasheet for the pin out!!!!
Step 3 - Attach the ground to your source pin on the MOSFET
Step 4 - Attach the Drain pin to your MOSFET
Step 5 - Attach your relay's coil to 12v depending on the relay, and the other to you drain pin on the MOSFET
Step 6 - Add the the protection diode, connect the striped silver end (cathode) to your 12v, and you other end (anode) to your Drain                 pin on the MOSFET.

use the other diagram for the power input.

Step 4: The Final Product

Now I know this isn't the best looking project enclosure as you saw in the intro, but here's how I did it. I use 1/4 plywood type of scrap kind of wood, and you can check the Home depot for it and look carefully. I cut it up to size and nailed it together with an air compressor nailing gun. It actually didn't split,( Take your time or it will split!)  No glue is necessary. I drill hole for the wire like the thermister and 3 wires for the separate relay power control box, and drilled one big one were the lcd was supposed to go. This was so I could stick a jigsaw blade in there and cut out a rectangle. The 2 tactile switches had tall shafts which poked through the plywood just barely. You could glue or epoxy on plastic rods from a pen tube or something.

Also I embedded an atmega8 not an atmega328 just because my sketch was only 6k bytes. The atmega8 only holds 8k bytes so I was safe. I pretty much made a stand alone arduino on perboard. I used a voltage divider for the lcd which was 1k and 220 ohm resistor. 1k goes to 5 volts and pin 3 on the LCD, and the 220 ohm resistor goes to ground and the pin 3 on the LCD.

To prop up the board to the front panel. The 3 pin header connector was from the connection the the relay power box.

I used an iec connector, I soldered a main female connector to this one so I can plug it in the box. I used hot glue this time for the box and it worked surprisingly well.

Remember to comment or contact me if you have any problem. Any go to arduino.cc and arduino forums or more troubleshooting and help.

Participated in the
Arduino Contest