/* Purpose: Temperature Regulator for a Kegerator with LCD display. Using a LM35 and Arduino to check temperature and display current temp to an LCD. Also the Arduino will turn a Solid State Relay on/off within a defined temp range -LM35 connected to 5V, Grd, Analog Pin 0 -Serial LCD connected to 5V, Grd, Digital Pin 1 (tx pin) -SS Relay connected to Grd, Digital Pin 12 -Back Light Button connected to Digital Pin 3, Grd, 5V via 10K resistor (pin pulled HIGH in open state). Many thanks to Brutus@ brutusweb.com and Mikal @ the Arduino forums for all the help and inspiration! */ #define ledPin 13 // LED connected to digital pin 13 #define lm35 0 // LM35 on Analog 0 #define blightPin 3 // Momentary switch for back light to digital pin 3 #define relayPin 7 // Relay connected to digital pin 7 unsigned long last_temperature_check_time = 0; unsigned long last_lcd_turn_on_time = 0; void sendlcd(byte command) //Quick function to send LCD commands. { Serial.print(command, BYTE); } void setup() // run once, when the sketch starts { analogReference(INTERNAL); //using internal voltage reference ~1.1v pinMode(ledPin, OUTPUT); // sets the digital pin as output pinMode(lm35, INPUT); // sets the analog pin as input pinMode(blightPin, INPUT); // sets the digital pin as input pinMode(relayPin, OUTPUT); // sets the digital pin as output digitalWrite(ledPin, HIGH); delay(1000); Serial.begin(9600); delay(1000); //Let Ports Stabilize sendlcd(27); //Reset Command For LCD sendlcd(122); delay(500); //Full Reset takes a bit sendlcd(254); //Clear and Go Home on LCD sendlcd(1); digitalWrite(ledPin, LOW); //turn off LED delay(250); } //new loop with millis... sweet void loop() // run till the end of days or the beer runs out... { unsigned long time = millis(); if (time - last_temperature_check_time > 20000) //has it been 20 seconds? { last_temperature_check_time = time; digitalWrite(ledPin,HIGH); //turn on LED for running routine status //Check Temperature routine long temp; long temp1; long temp2; long temp_x; int lm35_val=0; //delay(500); //Delay to allow stabilized analog read.. not needed? lm35_val=analogRead(lm35); //read value of center leg of LM35 temp = lm35_val; //output voltage of LM35, 10mV = 1 Degree Celcius temp1=temp/10; //creates true Celcius reading temp2=temp%10; //modulus operation to calculate remainder for higher resolution reading if (temp2 >= 5) { temp_x++; } //Send temperature to LCD routine sendlcd(254); //Clear LCD Screen sendlcd(1); Serial.println("Current Temp"); //Print "Current Temp" message Serial.print(temp1); //Print CelsuisTemperature Serial.print("."); //Print decimal place Serial.print(temp2); //Print "Tenths" place sendlcd(223); //Print degree charater Serial.print("C"); //Print "C" for Celsuis digitalWrite(ledPin,LOW); //Turn off LED //Turn Relay on/off routine if ((temp1) > 7 ) //check temp is above x degrees { digitalWrite (relayPin, HIGH); //if temp is above x degrees turn pin "ON" } else if ((temp1) < 4 ) //check temp is below x degrees { digitalWrite (relayPin, LOW); //if temp is below x degree turn pin "OFF" } } //Check Backlight Button State if (digitalRead(blightPin) == LOW) // turn on back light { last_lcd_turn_on_time = time; sendlcd(27); //ASCII ESC sendlcd(42); //ASCII * sendlcd(255); //Val (0)=off, Val(255)=full on } else if (time - last_lcd_turn_on_time > 10000) // has it been 10 seconds? { sendlcd(27); //Turn back light off sendlcd(42); sendlcd(0); } }