I am trying to do a temperature sensor that if a certain temp triggers a set of 5 led's and if its not that temp or higher it should trigger the other 5 led's I have tried a bunch of different ways I can think of and the led's are not lighting up how I am wanting. I am hoping someone can point me to where I am making my mistake in my code please. Thanks for any insight on this
int i;
int temperaturePin = 4; // pin that the sensor for front cab is attached to
int ledPin[] = {
4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
float getVoltage(int temperaturePin)
{
return(analogRead(temperaturePin) * .004882814); // converting from a 0 to 1024 digital range to 0 to 5 volts (each 1 reading equals - 5 milivolts
}
void setup() {
// initialize serial communications:
Serial.begin(57600);
}
void loop() {
for(int i = 4; i <= 13; i++){
pinMode(ledPin[i], OUTPUT);
}
float temperature = getVoltage(temperaturePin);
temperature = (((temperature - .5) * 100)*1.8) + 32;
if(temperature <= 79){
digitalWrite(ledPin[9], HIGH);
digitalWrite(ledPin[10], HIGH);
digitalWrite(ledPin[11], HIGH);
digitalWrite(ledPin[12], HIGH);
digitalWrite(ledPin[13], HIGH);
delay(2000);
}
else
{
digitalWrite(ledPin[4], HIGH);
digitalWrite(ledPin[5], HIGH);
digitalWrite(ledPin[6], HIGH);
digitalWrite(ledPin[7], HIGH);
digitalWrite(ledPin[8], HIGH);
delay(2000);
}
// print the analog value:
Serial.print("The temperature is ");
Serial.println(temperature);
delay(2000);
}