Arduino Project #2

659

7

Posted

Introduction: Arduino Project #2

This is the second project I have done with Arduino.

This particular project functions as a thermostat where you can see the current temperature (in Fahrenheit or in Celsius), you can set the desired temperature, and you can switch between °Fahrenheit and °Celsius. There is a LED light that automatically turns on when the current temperature is greater than the desired temperature. There is supposed to be a DC motor implemented instead of the light, however I did not have a working DC motor.

Step 1: THE PARTS

Below shows the required parts to build the thermostat:

1 Arduino Uno R3

1 LCD 16x2 Screen

2 Potentionmeters

1 Pushbutton

1 2 kohm Resistor

1 LED light / 1 DC motor (if you have one, this should work just fine)

Approximately 30 Wires

Step 2: THE WIRING

Attached is a picture that shows how to build this thermostat:

Step 3: THE CODE

Below is the code required to program this thermostat:

You can copy this code into an Arduino program and it should run fine:

int cel;

int far;

char let;

boolean cf;

int desC;

int desF;

int inputDes;

int temp;

int changeTime = 2;

float voltage;

#include

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

lcd.begin(16, 2);

pinMode(8, INPUT);

pinMode(9, OUTPUT);

}

void loop() {

voltage = getVoltage(0); //initializers

desC = (getVoltage(5) / 10) * 100;

desF = Far(desC) + 20;

inputDes = (analogRead(5) / 20.5);

cel = (voltage - 0.5) * 100;

far = ((cel * 9) / 5) + 32;

lcd.setCursor(0, 0); //LCD code

lcd.print("Temperature:");

lcd.setCursor(13, 0);

lcd.print(temp);

lcd.setCursor(15, 0);

lcd.print(let); //Display

lcd.setCursor(0, 1);

lcd.print("Desired:");

lcd.setCursor(9,1);

if (cf == true) {

lcd.print(desF);

lcd.setCursor(11,1);

} else {

lcd.print(desC);

lcd.setCursor(11,1);

if (desC < 10) {

lcd.print(" ");

lcd.setCursor(10,1);

}

}

lcd.print(let);

if (cf) { //Temp Toggle

let = 'F';

temp = far;

} else {

let = 'C';

temp = cel;

}

if (cel > desC) {

digitalWrite(8, HIGH);

} else {

digitalWrite(8, 0);

}

changeTime--;

if (analogRead(4) > 1000 && changeTime < 0) { //temp toggle input

cf = !cf;

changeTime = 2;

}

delay(150);

}

float Far (float a) { //farenheit conversion

float b = (a * (9 / 5)) + 32;

return b;

}

float getVoltage (float a) {

float b = (analogRead(a) * 0.004882814);

return b;

}

Step 4: THE INITIATION

If the previous steps work, then you should be done!

All that is left is to run the program and marvel at its glorious temperature detecting.

Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Spotless Contest

      Spotless Contest
    • Science of Cooking

      Science of Cooking
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments