Hi trying to get leds to come on at certain temperatures (27c down to 24c then from 24c down to 20c then 20c & below)
I have got the coding this far but seems long way to do this? can I use the IF ELSE statement instead if so please please show me how. Thanks Malcolm
int tempPin = A1;
int led01 = 8;
int led02 = 9;
int led03 = 10;
int tempMax = 28;
int tempMid = 27;
int tempMin = 24;
int temp;
void setup() {
Serial.begin(9600);
pinMode (led01, OUTPUT);
pinMode (led02, OUTPUT);
pinMode (led03, OUTPUT);
pinMode (tempPin, INPUT);
}
void loop() {
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Serial.print("TEMPRATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
delay(1000);
if (temp > tempMax)
{
digitalWrite(led01, HIGH);
digitalWrite(led02, LOW);
digitalWrite(led02, LOW);
}
if (temp < tempMid)
{
digitalWrite(led01, LOW);
digitalWrite(led02, HIGH);
digitalWrite(led02, LOW);
}
if (temp < tempMin)
{
digitalWrite(led01, LOW);
digitalWrite(led02, LOW);
digitalWrite(led02, LOW);
}
}
Regarding the if/else, please do some homework first. There are a gazillion posts on the internet about if/else notation and nested if/else for C. A quick google will solve your issue.