Hi, i am trying to write a code for LM35 + RGB to change color of RGB LED at different temperature but this is not working, please see code is there is any issue with code? I am using attiny85 usb and connected LM35 in A2 (D2 pin)
int ledb = 0;
int ledg = 1;
int ledr = 2;
int lm= A2; // por algún motivo solo funciona analógico en el pin 3
void setup()
{
pinMode(ledb, OUTPUT);
pinMode(ledg, OUTPUT);
pinMode(ledr, OUTPUT);
}
void loop()
{
int temp;
temp=abs(410.0*analogRead(lm)/1023.0);
if (temp<=30) //if the temperature is low
{
digitalWrite(ledb, HIGH);
digitalWrite(ledg, LOW);
digitalWrite(ledr, LOW);
}
else if (temp>=31 && temp<=40) // if the temperature is middle
{
digitalWrite(ledb, LOW);
digitalWrite(ledg, HIGH);
digitalWrite(ledr, LOW);
}
else if (temp>=41) //If the temperature is HIGH
{
digitalWrite(ledb, LOW);
digitalWrite(ledg, LOW);
digitalWrite(ledr, HIGH);
}
delay(100);
}