thermostat project

Im having difficulties programming the code so that the two pushbuttons I have connected on the breadboard increment and decrements the setpoint temperature witch is my variable called x. Please help.

//Include Wire I2C Library
#include <Wire.h>
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(6, 7, 8, 9, 10, 11);
const int buttonPin1 = 2; // the number of the pushbutton pin
const int buttonPin2 = 3; // the number of the pushbutton pin
float tempF; // create variable to store the temperature in.
int tempPin = 0; // Attach vout to analog pin 0.
int led = 13; // attach led to pin 13.
int fan1 = 12; // attach base of transistor to digital pin 9.
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0; // variable for reading the pushbutton status
void setup() // Will execute once at the start of the code.
{
//Create a Wire Object
Wire.begin();

// set up the LCD's number of columns and rows:
lcd.begin(16, 2);

Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode (led, OUTPUT); // sets the led pin 13 up as an output.
pinMode (fan1, OUTPUT); // sets the fan1 pin 9 up as an output.
pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT); // initialize the pushbutton pin as an input:
}

void loop() // code here will continue to replay until powered off.
{
int x=75;
tempF = analogRead(tempPin); // read the analog value from the lm35 sensor.
tempF = (5.0 * tempF * 100.0)/1024.0; // convert the analog input to temperature in centigrade.
Serial.print((byte)tempF); // send the data to the computer.
lcd.setCursor(0,0);
lcd.print("ST:");
lcd.print(x);
lcd.setCursor(0,3);
lcd.print(tempF);

lcd.print(" F");
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == LOW) {
++x;
}
else if(buttonState2 == LOW) {

--x ;
}
if (tempF > x) // creates bool expression for analyzation. if it evaluates to true,
{ // the body of the if statement will execute.
digitalWrite (led, HIGH); // turns on led.
digitalWrite (fan1, HIGH); // turns on fan1.
}
else // if the if equation evaluates to false the else statement will execute.
{
digitalWrite (led, LOW); // turns off led.
digitalWrite (fan1, LOW); // turns off fan1.
}
delay(1000); // wait 3 seconds before redoing the loop.
}

Place your sketch between [ code ][ /code ] tags.

You should look at de-bouncing your switches otherwise things will not increment or decrement as you think they will.

//Include Wire I2C Library
#include  <Wire.h>
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(6, 7, 8, 9, 10, 11);
const int buttonPin1 = 2;     // the number of the pushbutton pin
const int buttonPin2 = 3;     // the number of the pushbutton pin
float tempF;                            // create variable to store the temperature in.
int tempPin = 0;                        // Attach vout to analog pin 0.
int led = 13;                           // attach led to pin 13.
int fan1 = 12;                           // attach base of transistor to digital pin 9.
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;         // variable for reading the pushbutton status
void setup()                            // Will execute once at the start of the code.
{
  //Create a Wire Object
  Wire.begin();
  
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);  
  
  Serial.begin(9600);                   // opens serial port, sets data rate to 9600 bps
  pinMode (led, OUTPUT);                // sets the led pin 13 up as an output.
  pinMode (fan1, OUTPUT);               // sets the fan1 pin 9 up as an output.
  pinMode(buttonPin1, INPUT);           // initialize the pushbutton pin as an input:
  pinMode(buttonPin2, INPUT);           // initialize the pushbutton pin as an input:
}

void loop()                             // code here will continue to replay until powered off.
{
  int x=75;
  tempF = analogRead(tempPin);          // read the analog value from the lm35 sensor.
  tempF = (5.0 * tempF * 100.0)/1024.0; // convert the analog input to temperature in centigrade.
  Serial.print((byte)tempF);   // send the data to the computer.
 lcd.setCursor(0,0);
  lcd.print("ST:");
  lcd.print(x);
  lcd.setCursor(0,3);
  lcd.print(tempF);
 
  lcd.print(" F");
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState1 == LOW) {     
    ++x;     
  } 
   else if(buttonState2 == LOW) {     
       
    --x ; 
  }
    if (tempF > x)                     // creates bool expression for analyzation. if it evaluates to true,
    {                                   // the body of the if statement will execute.
      digitalWrite (led, HIGH);         // turns on led.
      digitalWrite (fan1, HIGH);        // turns on fan1.
    }
    else                                // if the if equation evaluates to false the else statement will execute.
    {
      digitalWrite (led, LOW);          // turns off led.
      digitalWrite (fan1, LOW);         // turns off fan1.
    }
  delay(1000);                          // wait 3 seconds before redoing the loop.
}

can you please elaborate and explain on how I could make my buttons work? Im trying to control the set temp with the buttons.

Try the modified code below:
Lines with <<< I have changed or added.

Note necessary in this case, however, for future reference, switches should be de-bounced otherwise you may get strange results.
Look up the Bounce library on the web site. i.e. Bounce.h

//Include Wire I2C Library
#include  <Wire.h>
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(6, 7, 8, 9, 10, 11);
const int buttonPin1 = 2;     // the number of the pushbutton pin
const int buttonPin2 = 3;     // the number of the pushbutton pin
float tempF;                  // create variable to store the temperature in.
int tempPin = 0;              // Attach vout to analog pin 0.
int led = 13;                 // attach led to pin 13.
int fan1 = 12;                // attach base of transistor to digital pin 9.
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;         // variable for reading the pushbutton status
int x=75;                     // <<< initialize   

void setup()                  // Will execute once at the start of the code.
{
  //Create a Wire Object
  Wire.begin();

  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);  

  Serial.begin(9600);                   // opens serial port, sets data rate to 9600 bps
  pinMode (led, OUTPUT);                // sets the led pin 13 up as an output.
  pinMode (fan1, OUTPUT);               // sets the fan1 pin 9 up as an output.
  pinMode(buttonPin1, INPUT);           // initialize the pushbutton pin as an input:
  digitalWrite(buttonPin1,HIGH);        // <<<turn on pullups
  pinMode(buttonPin2, INPUT);           // initialize the pushbutton pin as an input:
  digitalWrite(buttonPin2,HIGH);        // <<<turn on pullups
}

void loop()                             // code here will continue to replay until powered off.
{
//<<<  int x = 75;
  tempF = analogRead(tempPin);          // read the analog value from the lm35 sensor.
  tempF = (5.0 * tempF * 100.0)/1024.0; // convert the analog input to temperature in centigrade.
  Serial.println((byte)tempF);          // send the data to the computer.
  lcd.setCursor(0,0);
  lcd.print("ST:");
  lcd.print(x);
  lcd.setCursor(0,3);
  lcd.print(tempF);
  lcd.print(" F");
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState1 == LOW)
  {     
    ++x;                   
//<<<Serial.println(x);
  } 
  else if(buttonState2 == LOW)     
  {     
    --x ;                                   
 //<<<Serial.println(x); 
  }
  if (tempF > x)                     // creates bool expression for analyzation. if it evaluates to true,
  {                                        // the body of the if statement will execute.
    digitalWrite (led, HIGH);         // turns on led.
    digitalWrite (fan1, HIGH);        // turns on fan1.
  }
  else                                // if the if equation evaluates to false the else statement will execute.
  {
    digitalWrite (led, LOW);          // turns off led.
    digitalWrite (fan1, LOW);         // turns off fan1.
  }
  delay(1000);                          // wait 3 seconds before redoing the loop.
}

Thank you. I got everything working how I wanted it to. I have one more question for you. On this project im working on, its asking me to also control the dead-band on the thermostat. Whats dead-band? How can I control that?

If you want to know what dead band is look at this Deadband - Wikipedia

Lets say you are using an analog i/p (connected to a temperature sensor) to turn on and off a fan.
Your code might be if (temperature >= 200)
{
digitalWrite(2,HIGH); // if the temp is over 199 or 19.9'C turn on the fan
}
else
{
digitalWrite(2,LOW); // turn off the fan when if it is < 200 or 20.0'C
}
The problem here is when we are at exactly 20.0'C we may have the fan turning on and off constantly
as the temp. varies from 19.9 to 20.0 to 19.9 etc.
We need to incorporate a dead band to prevent the annoying on/off/on/off of the fan.
We can do this by if (temperature >= 200)
digitalWrite(2,HIGH); // if the temp is over 19.9'C turn on the fan
if (temperature < 170)
digitalWrite(2,LOW); // if the temp is under 17.0'C turn off the fan
We have a dead band of 3'C