Below is my current code. I have a flora Arduino, a temperature sensor and LED. Right now how it is set up, the red LED turns on if the temperature sensor senses a temperature above 80 degrees and the blue turns on if it senses a temperature below 60 degrees. What i would like the LED to do is get gradually brighter the hotter or colder the temperature sensed is. So at say 90 degrees, the red LED would be brighter then it was at 80 degrees. How do i do this? Any help would be appreciated. Thanks!
int HOT_TEMP = 80;
int COLD_TEMP = 60;
int RED_LED = 2;
int BLUE_LED = 3;
void setup(){
Serial.begin(9600);
pinMode(RED_LED,OUTPUT);
pinMode(BLUE_LED,OUTPUT);
digitalWrite(RED_LED,HIGH);
digitalWrite(BLUE_LED,HIGH);
}
void loop(){
int sensorValue = analogRead(A11); // 0-1023
float sensorVoltage = ((float)sensorValue / 1023) * 3.3; // 0-3.3V
float sensorTemp = (sensorVoltage - 0.5) * 100; // C
float sensorTempF = 1.8 * sensorTemp + 32;
Serial.print("SensorTemp C: ");
Serial.print(sensorTemp);
Serial.print(" F: ");
Serial.print(sensorTempF);
Serial.println();
// Decide which LED to light
if (sensorTempF>HOT_TEMP){
digitalWrite(RED_LED, LOW);
} else {
digitalWrite(RED_LED, HIGH);
}
if (sensorTempF<COLD_TEMP){
digitalWrite(BLUE_LED, LOW);
} else {
digitalWrite(BLUE_LED, HIGH);
}
delay(1000); // wait one second
}
edit by mod: please include the code using the proper tags