LM35 and how to put out average reading

Hey guys, im trying to figure out how to take an average of 10 readings every second and to put out that average reading into serial print for a duration of 5 minutes for both heating and cooling.

Can you guys help write a code for me, I just dont know what to do. Do i put in another for loop inside the for loop of 300?

Heres the code I have so far:

void setup()
{
pinMode(2, OUTPUT); // sets the digital
Serial.begin(9600);
delay(500);
}
void loop()
{
int adin;
float tpc, tpf;
Serial.println("Heater On");
digitalWrite(2, HIGH); // turns the LED on
for(int i=1; i<=300; i++)
{
adin=analogRead(0);
tpc=adin*.4888;
tpf=tpc*1.8+32.;
Serial.println(i);
Serial.println(tpf);
delay(2000);
}
Serial.println("Heater Off");
digitalWrite(2, LOW); // turns the LED off
for(int i=1; i<=300; i++)
{
adin=analogRead(0);
tpc=adin*.4888;
tpf=tpc*1.8+32.;
Serial.println(i);
Serial.println(tpf);
delay(2000);
}
}

http://www.arduino.cc/en/Tutorial/Smoothing

That will help you.

Mowcius

void setup()
{
pinMode(2, OUTPUT); // sets the digital
Serial.begin(9600);
delay(500);
}

void loop()
{
int adin;
Serial.println(“Heater On”);
digitalWrite(2, HIGH); // turns the LED on
for(int i=1; i<=300; i++)
{
float average=0;

for(int j=1; j<=10; j++)
{
delay(100);
adin=analogRead(0);
// sum of all readings
average=average+adin;
}

// sum of all readings divided by number of readings
average=average/10;

Serial.println(i);
Serial.println(average);
}

Serial.println(“Heater Off”);
digitalWrite(2, LOW); // turns the LED off

for(int i=1; i<=300; i++)
{
float average=0;

for(int j=1; j<=10; j++)
{
delay(100);
adin=analogRead(0);
// sum of all readings
average=average+adin;
}

// sum of all readings divided by number of readings
average=average/10;

Serial.println(i);
Serial.println(average);
}
}

Was this heplfull to you?

Mowcius solution is ofcourse better but maybe harder to understand for a beginner…