Hi
i have made a little temp think
i use :
Arduino UNO
LCD Keypad Shield
4 relay module
and a 351T1LM35 as tempsensor
at first i did not use the keypad and all was good
the i found some code to use the keypad and now the temp is all wrong
here is my code
first the code that works
#include <LiquidCrystal.h>
int reading = 0;
int sensorPin = A1;
int relay = 3;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
lcd.begin(16, 2);
pinMode(relay,OUTPUT);
pinMode(relay2,OUTPUT);
}
void loop() {
reading = analogRead(sensorPin);
int celsius = reading/2;
lcd.setCursor(0, 0);
lcd.print("Temperature:");
lcd.print(celsius, DEC);
lcd.print((char)223);
lcd.print("C");
if (celsius >29)
{
digitalWrite(3,HIGH);
lcd.setCursor(0,1);
lcd.print(" IM COOLING OFF");
}
else if (celsius <26)
{
digitalWrite(3,LOW);
lcd.setCursor(0,1);
lcd.print(" IM COOL");
}
else
{
lcd.setCursor(0,1);
lcd.print(" ZZzzz");
}
delay(1000);
lcd.clear();
}
and now the code with keypad code in, and the wrong temp
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int lcd_key = 0;
int adc_key_in = 0;
int inputPin2 = 2;
int inputPin11 = 11;
int inputPin12 = 12;
int reading = 0;
int sensorPin = A1;
int relay = 3;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int read_LCD_buttons(){
adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 750) return btnSELECT;
return btnNONE;
}
void setup(){
lcd.begin(16, 2);
pinMode(2, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(relay,OUTPUT);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
}
void loop(){
lcd.setCursor(0,1);
lcd_key = read_LCD_buttons();
switch (lcd_key){
case btnRIGHT:{
if (digitalRead(inputPin2) == LOW) {
lcd.setCursor(0,0);
lcd.print("USB Off ");
digitalWrite(2, HIGH);
delay(200);
}
else if (digitalRead(inputPin2) == HIGH) {
lcd.setCursor(0,0);
lcd.print("USB On ");
digitalWrite(2, LOW);
delay(200);
}
else {
delay(1);
}
break;
}
case btnLEFT:{
if (digitalRead(inputPin12) == LOW) {
lcd.setCursor(8,0);
lcd.print("12v Off ");
digitalWrite(12, HIGH);
delay(200);
}
else if (digitalRead(inputPin12) == HIGH) {
lcd.setCursor(8,0);
lcd.print("12v On ");
digitalWrite(12, LOW);
delay(200);
}
else {
delay(1);
}
break;
}
case btnUP:{
if (digitalRead(inputPin11) == LOW) {
lcd.setCursor(0,1);
lcd.print("USB Off ");
digitalWrite(11, HIGH);
delay(200);
}
else if (digitalRead(inputPin11) == HIGH) {
lcd.setCursor(0,1);
lcd.print("USB On ");
digitalWrite(11, LOW);
delay(200);
}
else {
delay(1);
}
break;
}
case btnDOWN:{
break;
}
case btnSELECT:{
lcd.setCursor(0,0);
lcd.print("USB Off ");
lcd.setCursor(8,0);
lcd.print("12v Off ");
lcd.setCursor(0,1);
lcd.print("USB Off ");
digitalWrite(2, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
break;
}
case btnNONE:{
reading = analogRead(sensorPin);
int celsius = reading/2;
lcd.setCursor(8, 1);
lcd.print(celsius, DEC);
lcd.print((char)223);
lcd.print("c");
delay(500);
if (celsius >29)
{
digitalWrite(3,HIGH);
lcd.setCursor(13,1);
lcd.print("On ");
}
else if (celsius <26)
{
digitalWrite(3,LOW);
lcd.setCursor(13,1);
lcd.print("Off");
}
else
{
delay(1);
}
break;
}
}
}
hope that you can help me… my hair starting to get gray