Lcd thermostat arduino project. I need help!

My name is Dylon J. and I making an arduino lcd thermostat. It’s a basic 16x2 hd44780 hitachi driven lcd. I got it to display 70 or the current tempertaure in Fahrenheit. Also I got it to diplay set to and the temperature it supposed to cool my room doen to. The output when the temp goes goes the set temp it to pin 13 labelled as led as a test. But in the finally product will be a SSR (Solid State Rely). I wanted to control the set temp by 2 tactile switches to pins 7 and 6. swtch one is to go up one degree, and the other is down one degree. But a couple problems. Even if the settemp is at 25 degree C or 77 F, I go to warm it up but the led was light up when I first uploaded the sketch. I new to this arduino ide, and writing code. But can some one help?!?!?!
Here is the code:

/*
lm35 sketch
prints the temperature to LCD
*/
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int inPin = 0;
int led = 13;
int swtch1 = 7;
int swtch2 = 6;
float settemp;
void setup()
{
lcd.begin(16, 2);
pinMode (led,OUTPUT);
pinMode (swtch1, INPUT);
pinMode (swtch2, INPUT);
}
void loop()
{
int value = analogRead(inPin);
lcd.setCursor(0, 1);
float millivolts = (value / 1024.0) * 5000;
float celsius = millivolts / 10;
lcd.clear();
lcd.setCursor(0,0);
lcd.print((celsius * 9)/ 5 + 32);
lcd.print(" Fahrenheit");

float settemp = 25;
if
(value > settemp)
{digitalWrite (led,1);}
else
{
digitalWrite (led,0);
}
if
(swtch1,1)
{settemp + 1;}
else
{}
if
(swtch2,1)
{settemp - 1;}
lcd.setCursor (0,1);
lcd.print("set to ");
lcd.print (settemp);
delay(1000);

}

Remember this is the first time I even tried to write code, after some research. I’m still so clueless about somethings. Thanks for your help! If I get any:)

lcd_thermostat_project_2.ino (936 Bytes)

    if 
    (value > settemp)

Should probably be:

    if (celsius > settemp)

This part of the code looks like nonsense:

   if  
 (swtch1,1)
    {settemp + 1;}
    else 
    {}
    if 
    (swtch2,1)
    {settemp - 1;}

You have some very unconventional code layout generally. I suggest putting the whole of the if expression on a single line, put each { and } on separate lines with matching pairs indented by the same amount and lines between them indented one extra level.

Hi Dylon,

(swtch1,1)
{settemp + 1;}

Isn’t doing what you think. Look up how to read a switch in the Arduino examples. You’re probably closer than you think.

Also, press T to format your code to make it readable.

Pat.

Portal:
My name is Dylon J. and I making an arduino lcd thermostat. It’s a basic 16x2 hd44780 hitachi driven lcd. I got it to display 70 or the current tempertaure in Fahrenheit. Also I got it to diplay set to and the temperature it supposed to cool my room doen to. The output when the temp goes goes the set temp it to pin 13 labelled as led as a test. But in the finally product will be a SSR (Solid State Rely). I wanted to control the set temp by 2 tactile switches to pins 7 and 6. swtch one is to go up one degree, and the other is down one degree. But a couple problems. Even if the settemp is at 25 degree C or 77 F, I go to warm it up but the led was light up when I first uploaded the sketch. I new to this arduino ide, and writing code. But can some one help?!?!?!
Here is the code:

/*
lm35 sketch
prints the temperature to LCD
*/
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int inPin = 0;
int led = 13;
int swtch1 = 7;
int swtch2 = 6;
float settemp;
void setup()
{
lcd.begin(16, 2);
pinMode (led,OUTPUT);
pinMode (swtch1, INPUT);
pinMode (swtch2, INPUT);
}
void loop()
{
int value = analogRead(inPin);
lcd.setCursor(0, 1);
float millivolts = (value / 1024.0) * 5000;
float celsius = millivolts / 10;
lcd.clear();
lcd.setCursor(0,0);
lcd.print((celsius * 9)/ 5 + 32);
lcd.print(" Fahrenheit");

float settemp = 25;
if
(value > settemp)
{digitalWrite (led,1);}
else
{
digitalWrite (led,0);
}
if
(swtch1,1)
{settemp + 1;}
else
{}
if
(swtch2,1)
{settemp - 1;}
lcd.setCursor (0,1);
lcd.print("set to ");
lcd.print (settemp);
delay(1000);

}

Remember this is the first time I even tried to write code, after some research. I’m still so clueless about somethings. Thanks for your help! If I get any:)

Also when posting code up on here - please use the code tags

Craig

what I was trying to do to the settemp, was if the first switch read a high, and 1 one degree to the settemp, and the same as the second switch, but to decrease the settemp, by one degree less. Can anyone help? Thanks for your support.

Can anyone help?

Perhaps if you give this sentence another try...

Portal: what I was trying to do to the settemp, was if the first switch read a high, and 1 one degree to the settemp, and the same as the second switch, but to decrease the settemp, by one degree less.

Portal: what I was trying to do to the settemp, was if the first switch read a high, and 1 one degree to the settemp, and the same as the second switch, but to decrease the settemp, by one degree less. Can anyone help? Thanks for your support.

OK that almost makes sense. One thing to think about - you should read and write these values to eeprom so that if you lose power or reset the arduino then you will have the last remembered value to return to

Craig

Portal: what I was trying to do to the settemp, was if the first switch read a high, and 1 one degree to the settemp, and the same as the second switch, but to decrease the settemp, by one degree less. Can anyone help? Thanks for your support.

That's easy enough to do, and there are example sketches which show how to read an input, debounce it, detect input state transitions (i.e. button presses, in this context) and do something when they occur. The code fragment you included to do this is nonsense, though - throw that part away and start again using the examples for inspiration. The rest of the code looks much better and might well work if you correct the typo I pointed out.

I really new to this code writing, and I just tried to modify other's code. But the code the doesn't make sense, is what i really need. Can you help say, if the set temperature is exseeded, turn on the led. Also if 5 volts is read on 7 or 6 on the arduino, then add or subtract, one degree from the set temp. Also store to most recent set temp in eeprom. Got any helpful link on eeprom or on this project? I really appreciate your help, and hope you still can help. Thanks a lot!

Dylon J.

Portal: I really new to this code writing, and I just tried to modify other's code. But the code the doesn't make sense, is what i really need. Can you help say, if the set temperature is exseeded, turn on the led. Also if 5 volts is read on 7 or 6 on the arduino, then add or subtract, one degree from the set temp. Also store to most recent set temp in eeprom. Got any helpful link on eeprom or on this project? I really appreciate your help, and hope you still can help. Thanks a lot!

Dylon J.

I do not think you are going to get anyone to sit down and write the code for you - you need to break this down into manageable steps and then code individual routines to address each of these

1) Take Temp 2) Display Temp to LCD 3) Read EEPROM for set temp 4) Display Set temp 5) Compare Set temp to Take temp 6) Turn on a relay to control heat 7) Turn on a relay to control cold 8) Display a basic menu 9) accept buttons presses to drive the menu 10) store new values in EEPROM

Now start with each of these and as you get one written (or get stuck) come on here and ask specific questions not for your whole project to be written

Craig

All right, do guys know how could change the set temp by 2 buttons? And each time on or the other button is pressed, I would add and subtract one degree f.

I tried using the digitalRead command for each button and said (settemp + 1) for each time in read a high on the pin which the swtich is connected to. Any other way because I'm sure my way is completely wrong.

Portal: All right, do guys know how could change the set temp by 2 buttons? And each time on or the other button is pressed, I would add and subtract one degree f.

I tried using the digitalRead command for each button and said (settemp + 1) for each time in read a high on the pin which the swtich is connected to. Any other way because I'm sure my way is completely wrong.

You don't care when It's high, only when it transitional to or from HIGH. See the state change detection example.

Stuff about detecting state changes on switches:

http://www.gammon.com.au/switches

How do I store the last most recent settemp value in EEPROM?

Portal: How do I store the last most recent settemp value in EEPROM?

Look at the EEPROM write example.

I will look into the eeprom later, but I got the settemp working. So at 76 F the led will come on if the temperature exceeds 76F. How every when I try changing the settemp with buttons, the settemp will -1 or go to 75 for as long as I held it down. And the same for the addition temp button. He is my still lame code that is probably the problem. Here is my code:

#include <LiquidCrystal.h>
int tempPin = A0;
int led =13;
float temp;
float settemp;
int swtu = 7;
int swtd = 6; 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  pinMode (led,1);
  Serial.begin (9600);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("hello, world!");
  lcd.clear();
}

void loop() {

  int tvalue = analogRead(tempPin);
  float temp = (tvalue / 6.388888888889);
  lcd.setCursor (0,0);
  lcd.print (temp);
  lcd.print ('F');
  Serial.println (temp);

  delay (250);
  float settemp = 76;
  if
    (digitalRead(swtu)== 1 )
  { 
    settemp++

      ;
  }

else{

}

if 
(digitalRead (swtd) == 1)
{
  (settemp--);
}
else {

}

if (temp > settemp) 
{
  digitalWrite (led, 1);
}
else
{
  digitalWrite (led,0);
}



lcd.setCursor (0,1);
lcd.print ("Set To ");
lcd.print (settemp);
lcd.print ('F');
delay (250);



}

Portal: I will look into the eeprom later, but I got the settemp working. So at 76 F the led will come on if the temperature exceeds 76F. How every when I try changing the settemp with buttons, the settemp will -1 or go to 75 for as long as I held it down.

Because you didn't look into and/or understand the StateChangeDetection example. You don't care that the button is HIGH. You only care when it TRANSITIONS to HIGH.

  if
    (digitalRead(swtu)== 1 )
  { 
    settemp++

      ;
  }

That has got to be the ugliest bit of code I've seen to date on these forums. If you don't know how to properly format code to make it readable, you the Auto Format tool the IDE gives to you.

I got most of it working, and I’ll use eeprom later, but the control buttons for the settemp are confusing. Any time I push the button, the settemp add or subtracts from the settemp by one, until I let go. For example if I push the swtup button, it goes from 76 to 77 f until I let go. And the settemp doesn’t change even if I hold it down. Can someone tell me what’s wrong with the poorly written code? Here is my code:

#include <LiquidCrystal.h>
int tempPin = A0;
int led =13;
float temp;
float settemp;
int swtu = 7;
int swtd = 6; 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  pinMode (led,1);
  Serial.begin (9600);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("hello, world!");
  lcd.clear();
}

void loop() {

  int tvalue = analogRead(tempPin);
  float temp = (tvalue / 6.388888888889);
  lcd.setCursor (0,0);
  lcd.print (temp);
  lcd.print ('F');
  Serial.println (temp);

  delay (250);
  float settemp = 76;
  if
    (digitalRead(swtu)== 1 )
  { 
    settemp++

      ;
  }

else{

}

if 
(digitalRead (swtd) == 1)
{
  (settemp--);
}
else {

}

if (temp > settemp) 
{
  digitalWrite (led, 1);
}
else
{
  digitalWrite (led,0);
}



lcd.setCursor (0,1);
lcd.print ("Set To ");
lcd.print (settemp);
lcd.print ('F');
delay (250);



}

Portal:
I got most of it working, and I’ll use eeprom later, but the control buttons for the settemp are confusing. Any time I push the button, the settemp add or subtracts from the settemp by one, until I let go. For example if I push the swtup button, it goes from 76 to 77 f until I let go. And the settemp doesn’t change even if I hold it down. Can someone tell me what’s wrong with the poorly written code? Here is my code:

#include <LiquidCrystal.h>

int tempPin = A0;
int led =13;
float temp;
float settemp;
int swtu = 7;
int swtd = 6;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  pinMode (led,1);
  Serial.begin (9600);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print(“hello, world!”);
  lcd.clear();
}

void loop() {

int tvalue = analogRead(tempPin);
  float temp = (tvalue / 6.388888888889);
  lcd.setCursor (0,0);
  lcd.print (temp);
  lcd.print (‘F’);
  Serial.println (temp);

delay (250);
  float settemp = 76;
  if
    (digitalRead(swtu)== 1 )
  {
    settemp++

;
  }

else{

}

if
(digitalRead (swtd) == 1)
{
  (settemp–);
}
else {

}

if (temp > settemp)
{
  digitalWrite (led, 1);
}
else
{
  digitalWrite (led,0);
}

lcd.setCursor (0,1);
lcd.print ("Set To ");
lcd.print (settemp);
lcd.print (‘F’);
delay (250);

}

Did you look at the state change detection example like you were told ? Why have you got the empty else statements in there ?

Move the floating ; to the correct locations in your code so we can read it a little more easily

Do some more serial printing so you understand what is happening at each stage of the program

Craig

I tried the state change detection and looked at tutorials and everything, but I still could get the code functioning correctly. It was the same as last time. This time, PLEASE I'm hopeless and I don't understand how to get this thing working. I referring to the settemp control with 2 tactile switches. Any more links, tutorials, or any bit of code will help. I seriously can't get this thing working. As always any replies will help. Thanks.