thermometer serialprintln advise

Hi, can anyone give me some advise on the following sketch that i downloaded please, what i am wanting to achieve is instead of the sketch constantly serial println the temperature i only want it to serial println the first temp reading and then serial println any changes in the temp reading, any help would be great. thanks

int pin = 0; // analog pin
int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;
void setup()
{
Serial.begin(9600); // start serial communication
}
void loop()
{
for(i = 0;i<=7;i++){ // gets 8 samples of temperature
samples = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
tempc = tempc + samples*;*
delay(1000);
}
tempc = tempc/8.0; // better precision
if(tempc > maxi) {maxi = tempc;} // set max temperature
if(tempc < mini) {mini = tempc;} // set min temperature
Serial.print(tempc,DEC);
Serial.println(" Celsius ");
tempc = 0;
}

Does your code really look like that? I doubt it.

and then serial println any changes in the temp reading

How do you determine that the temperature reading this time is the same as, or not the same as, the temperature reading last time, without storing the reading last time?

i only want it to serial println the first temp reading and then serial println any changes in the temp reading

At the top add another variable 'tempc_prev'. At the begining of loop() add:
tempc_prev = tempc; //we are saving last value

Now check for difference before printing temperature:

if (tempc != tempc_prev) {
Serial.print..............
..........................etc
}

If 0 is a possible answer than simply setup tempc_prev to -999 or some impossible number. This ensures the 1st value prints.

Hi, thanks for the responses, i am almost new to arduino but finding it pretty cool. In reply to the help/advise, the code i inputted was one from a you tube tutorial for the lm35 sensor and seems to work pretty well, It runs and prints the temp to the serial monitor. Like a noob i didnt explain that i have a speakjet voice shield with tts fitted to the arduino also, so it actually speaks the temp too. For some reason once i fitted the sheild i didnt have to tell the arduino that the shield was fitted it just started talking the readings which was a bonus.
Joe i`ve had a go at inserting your ideas, what happens is that it still speaks the temperature every second (which is what i believe the loop sample is set at if that makes sense?) What i am trying to acheive is a talking thermometer that once switched on, reads the current temperature, speaks it and only speaks out if the temperature changes, i.e

arduino starts up,reads the sensors temps, speaks the current temp say 20 degrees c, doesnt speak anything til it either sees a temp increase or decrease then speaks that temp, and so on.

Quite possibly this code will have to completely change, not sure, still reading through the tutorial and refernce libraries.
any ideas or am i talking jiberrish? :~

please use code tags when posting code. It is the # button above the smileys..

What i am trying to acheive is a talking thermometer that once switched on, reads the current temperature, speaks it and only speaks out if the temperature changes, i.e

Are you shure you want that? if the temp stays the same for a longer period, this might be inconvenient....

Hi Rob,
didnt know about the code tags, found them now thanks.
yeah, i know it does sound strange but all i am trying to achieve is the thermometer to just speak out when theres a change in ambient temp. i am not expecting the finished code to be 100% exact with the reading, i am more interested in the temp changes, although i need to create a code that is more or less spot on with the temperature.
am currently reading about statement changes and not sure if the code would have to have that involved in it somewhere.
p.s
to all reading, i am a complete novice so please bare that in mind.

Joe i`ve had a go at inserting your ideas, what happens is that it still speaks the temperature every second (which is what i believe the loop sample is set at if that makes sense?) What i am trying to acheive is a talking thermometer that once switched on, reads the current temperature, speaks it and only speaks out if the temperature changes,

There may a bit of jitter in the A/D values. I would output the new value only if it differs by a meaningful delta. You also need a time limit (since last output) so that output occurs every x seconds or minutes even if there is no change.

You should repost your code with any new changes.

hi joe,
been realy busy at work and also trying to sort the program out for the thermometer, here is my latest work in progress code, it woks sort of fine at present but it doesnt show any change in temp, just reads the temp after the delay, its changed quite alot from the original code its all trial and error and also learning how it all works too .
[co

int tempc;
int tempPin = 0;
int lasttempc;
void setup ()
{
Serial.begin(9600);
Serial.println (" hello sensor is actevated ");
}

void loop()
{
tempc = analogRead(tempPin);
tempc = (5.0tempc100.0)/1024;
Serial.print(tempc,DEC);
Serial.println(" degrees ");
lasttempc = analogRead(tempPin);
lasttempc = (5.0lasttempc100.0)/1024;
if (lasttempc != tempc) {
delay (640000);}
else {
Serial.print(lasttempc,DEC);
Serial.println(" degrees ");
}
}