Need to compare 2 values at different times from the same sensor?

Hi,

I am having trouble getting the code for comparing two water level values from the same sensor at different times. I have a DS1302 and ultrasound sensor for water level measurement.

Thankyou Ashish

What code?

Please read the "How to use this forum" post and follow the directions. Use code tags to post the code.

look into Blink Without Delay in order to set your times.

if you have a flag, you can toggle values.

sensor   = analogRead(DS1302);

you should have somethikng line this in your sketch.

//  do your timing loop with blink without delay.

blink wihgout delay goes here

//   read value

if (lastSensor = HIGH) {
    lastSensor = LOW ;
    alternateReading1 = sensor ;  //  this loads the value into alternateReading1
}
else   //  if lastSensor was NOT high
{
   lastsensor = HIGH ;
   alternateReading2 = sensor ;  //  this loads the value into alternateReading2
}

// this will load your values alternately from one to the next.

delta = alternateReading2 - alternateReading1 ;

now you have the difference

this is crude and slopply, but you should be able to see how by toggleing your inputs could be done.

What you did not tell us if WHY you want to do this. you could just as easily do it a different way

sensor   = analogRead(DS1302);
LastReading = ThisReading ;  //  this loads the LAST reading 
ThisReading = sensor ;
delta =  ThisReading - LastReading ;

Since you did not tell us WHY you want to see the differences, it is harder to give you specific help. if you are trying to see if the level is dropping, you can do many things to watch if it dropped over the last time period.

if you want to know rate, then you need to add some form of time stamp for your readings.