#define LM35 A2
#define RED 4
#define GREEN 2
float lm_value;
float tempc;
int brightness = 0;
void setup() {
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
}
void loop() {
lm_value = analogRead(LM35);
tempc = (lm_value * 500) / 1023;
Serial.println(tempc);//Temperature in Celcius
//Condition
if (tempc > 25) {
brightness = 0;
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
}
else {
brightness += 10;
if(brightness < 255) {
analogWrite(GREEN, brightness);
}
digitalWrite(RED, LOW);
}
delay(1000);
}
That is just one problem I am having right now, but my temp sensor is decresing and incresing with random values. Could it be that my sensor is broken?

