Programming Question????

Hi,

I am new to arduino, i am trying to do a small project "monitoring digital Temperature and humidity " using DHT22 and LCD.
I am using one push button to switch the temperature between F and C and another push button to turn off the system
but I had a problem sometimes it works sometimes not i THINK THERE IS BUG in the code but I can not figure it out
here is my code :

#include <DHT.h>
#include <LiquidCrystal.h>
#include “DHT.h”
#define DHTPIN 8 // what pin we’re connected to
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Pins for the LCD display, as taken from arduino.cc
int TempButton =7; // switchable button connected to digital pin 7
int ExitButton =6; // Exit button connected to digital pin 6
float h,t,Cel;

int checkVal; // return val of readButtons
int buttonValue;

int temp_state=0; // temp in f

#define DHTTYPE DHT22 // DHT 22 (AM2302)

// Uncomment whatever type you’re using!
//#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor // start button connected to digital pin 8
DHT dht(DHTPIN, DHTTYPE);

//Red Cathode to 330ohms then to Arduino pin 9
//Green Cathode to 330ohms then to Arduino pin 10
//middle pin to ground
int RedLEDPin = 9; // LED connected to digital pin 9
int GreenLEDPin = 10; // LED connected to digital pin 10

// intialization Function

void setup() {

dht.begin();
lcd.begin(16, 2);
init_lcd(); // show the blinking welcome
defaultScreen();
pinMode(TempButton,INPUT); // Initialize both button I/O ports as input ports
pinMode(ExitButton,INPUT);
pinMode(RedLEDPin, OUTPUT); // sets the digital pin as output
pinMode(GreenLEDPin, OUTPUT); // sets the digital pin as output

}

// start menu screen
void defaultScreen()
{
calcTemp();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Humidity: “);
lcd.print(h);
lcd.print(”%”);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(t);
lcd.print((char)223);
lcd.print(“F”);
TemRange();

}

void init_lcd() // Initial Welcome Screen
{
lcd.print(" WELCOME TO “);
lcd.setCursor(0,1);
lcd.print(” Temp Monitor ");
lcd.display();
delay(5000);

lcd.clear();
lcd.setCursor(0,1);
lcd.print(“Please Wait …”);
delay(3000);
lcd.clear();
}

// Reading temperature or humidity takes about 250 milliseconds!

void calcTemp()
{

h = dht.readHumidity();
Cel = dht.readTemperature();
t = Cel* 9/5 + 32;

}

void loop() {
do{

defaultScreen();
delay(500); // to avoid debouncing
checkVal=readButtons(); // Check if any button is pressS
}

while (checkVal==0);
//check if exit button pressed

if(checkVal == 2) // Exit Button is pressed
{
//if (lcd_state ==1){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Thank you ");
lcd.setCursor(0,1);
lcd.print( " Good By ");
delay(2000);
lcd.clear();
lable:{
digitalWrite(GreenLEDPin, LOW); // sets the Green LED on
digitalWrite(RedLEDPin, LOW); // sets the Red LED off
}
goto lable;

//}
}

if ((checkVal==1)&&( temp_state==1)){
while (temp_state==1){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Humidity: “);
lcd.print(h);
lcd.print(”%”);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(Cel);
lcd.print(( char)223);
lcd.print(“C”);
TemRange();
calcTemp();
delay(500);
checkVal=readButtons(); // Check if any button is pressed
}
}
else if((checkVal==1)&&( temp_state==0)){
while(temp_state==0){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Humidity: “);
lcd.print(h);
lcd.print(”%”);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(( char)223);
lcd.print(“F”);
TemRange();
calcTemp();
delay(500);
checkVal=readButtons(); // Check if any button is pressed
}

}

}

// Function used to read the push buttons which one is pressed
int readButtons(){
if(digitalRead(TempButton) ==HIGH)
{
buttonValue =1;
temp_state= temp_state^1;
}

else if(digitalRead(ExitButton) ==HIGH)
{

buttonValue =2;

}
else
{
buttonValue = 0;
}
return(buttonValue); // retirn value depends upon button pressed
}

// function used to calculate the Temprature Range
//to turn on the lights
// if the room temprture <22 Red light on
// if the room Temprture >= 25 Green Light On
// if room Temprture between 22 and 25 no light

void TemRange(){

if (dht.readTemperature() <22)
{
digitalWrite(RedLEDPin, HIGH); // sets the Red LED on
digitalWrite(GreenLEDPin, LOW); // sets the Green LED off

}
else if (dht.readTemperature() >= 25)
{
digitalWrite(RedLEDPin, LOW); // sets the Blue LED on
digitalWrite(GreenLEDPin, HIGH); // sets the Green LED off
}
else
{
digitalWrite(GreenLEDPin, LOW); // sets the Green LED on
digitalWrite(RedLEDPin, LOW); // sets the Red LED off

}

}

I appreciate your response in advance

Thank you

Read the how to use this forum sticky post then modify that post to use the correct code tags.

THINK THERE IS BUG in the code but I can not figure it out

Why do you think that? Say what you expect the code to do and what it actually does.

How to use this forum

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the # button above the posting area.