Hi Guys,
I'm wondering if any of you wonderful people can help me.
Basically, Im trying to make a thermostat with user button to increase or decrease my threshold temperature.
I'm using an LM35 sensor. For my LCD display, I'm using Grove-LCD RGB Backlight v2.0 display which is wonderful.
The problem is when I tried to put in the button, the temperature that I can set will not stay. So when I set for 25 degrees Celcius, after about 5 secs it will either go to 24, 23,22 or it will rise up and wont stop. I honestly don't know what I'm not doing correctly.
And yes I am very new to Arduino and coding too.
I'm using an Arduino Uno by the way.
Please help, below are my codes:
Thanks.. =(
// Declare variables
#include <Wire.h>
#include <EEPROM.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 2
int buttonup= 7;
int buttondown = 6;
// 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(1000);
pinMode(ledPin, OUTPUT);
pinMode(fan1, OUTPUT);
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 (buttonup)==1)
{
(settemp ++);
EEPROM.write(1, settemp);
}
else{
}
if (digitalRead(buttondown)==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);
}