I am making a thermometer with a lm35 and some leds. My problem is with the sketch " I think it is good" but I dont know why it doesn´t work.
This is my program:
int led[7] = { 3, 4, 5, 6, 7}; // Assign the pins for the leds
float grad;
int i,a;
void setup()
{
for (i = 0; i < 7; i++)
pinMode(led[i], OUTPUT);
Serial.begin(9600);
}
void loop()
{
grad = (5.0 * analogRead(0)*100.0)/1023.0; //convert to °C
Serial.println(grad);
delay(500);
if (grad==28){
a=1;}
else if (grad==29){
a=2;}
else if (grad==30){
a=3;}
else if(grad==31){
a=4;}
else if (grad==32){
a=5;}
else if (grad==33){
a=6;}
if (a == 0)
{
for(i = 0; i < 7; i++)
{
digitalWrite(led[i], LOW);
}
}
else
{
for (i = 0; i < a; i++)
{
digitalWrite(led[i], HIGH);
}
for(i = i; i < 7; i++)
{
digitalWrite(led[i], LOW);
}
}
}
When I open the serial monitor the arduino give me in the first value the temperature of the room but next it give me other values I don't know why. When I use the variable grad as a float value it give me the real temperature (for this reason I think that the lm35 is ok) of the room but for this sketch i need the temperature as a integer. Anyone know what could be the problem.