Getting sensor to settle for a second before it gives the reading

Hey just trying to figure out how i can get my the serial monitor to delay for a second after a weight is placed on a load cell, i have a 10 second gap on between readings but as soon as i place a weight on the sensor i get a reading on the serial monitor. Anyone know how i can stop this? Thanks, Tom.

Keep reading the value until it stops changing for 1 second or more then display the result.

Cheers Riva, what code is best for doing that?

TomDev:
Cheers Riva, what code is best for doing that?

How does the current data get into the arduino and what code are you using to read it as it's dependent of this?
Pseudo code would be something like
loop(){
Do
Read weight
Compare to last weight
If same then has 1 second passed?
Exit Do loop if yes
Loop
Display weight
}

Cheers Riva, I'm not really up to scratch with programming, I'm trying to write the code for that but i cant seem to get it working. I don't have the code i am using on this computer but i have some similar code i found. How would i write it into this piece of code?

float aReading = 120.0;
float aLoad = 60.0; // lbs.
float bReading = 344.0;
float bLoad = 172.0; // lbs.

long time = 0;
int interval = 1000; // Take a reading every 500 ms

void setup() {
Serial.begin(9600);
}

void loop() {
float newReading = analogRead(0);

// Calculate load based on A and B readings above
float load = ((bLoad - aLoad)/(bReading - aReading)) * (newReading - aReading) + aLoad;

// millis returns the number of milliseconds since the board started the current program
if(millis() > time + interval) {
Serial.print("Reading: ");
Serial.print(newReading,1); // 1 decimal place
Serial.print(" Load: ");
Serial.println(load,1); // 1 decimal place, println adds a carriage return
time = millis();
}
}

The problem with the concept of expecting the same reading for a second, is that most sensors have some noise
and successive readings will not be the same.

This sensor doesn't have much noise but i'm using it for weighing items and when i first place the weight on i get a reading as the weight is starting to settle so i just want to eliminate that initial result. Anyone have any ideas?

Sorry for delay, busy day at work.
Maybe something like this though it’s totally untested.

const float aReading = 120.0;
const float aLoad = 60.0; // lbs.
const float bReading = 344.0;
const float bLoad = 172.0; // lbs.

unsigned long interval = 1000UL;
unsigned long newTime = 0;
unsigned long oldTime = 0;
float oldReading = 0;
float newReading = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  delay(100);         // Read about 10 times a second
  newTime = millis();
  newReading = analogRead(A0);
  // Maybe round off newReading here to account for analogue noise
  if (newReading == oldReading) {
    if ((newTime - oldTime) > interval) {
      // Calculate load based on A and B readings above
      float load = ((bLoad - aLoad)/(bReading - aReading)) * (newReading - aReading) + aLoad;
      // millis returns the number of milliseconds since the board started the current program
      Serial.print("Reading: ");
      Serial.print(newReading,1); // 1 decimal place
      Serial.print("  Load: ");
      Serial.println(load,1);  // 1 decimal place, println adds a carriage return
      }
  }
  else {
    oldTime = newTime;
    oldReading = newReading;
  }
}

Cheers for that Riva, this code looks like exactly what im looking for. I just ran it now but im having a problem displaying results on the serial monitor, nothing seems to be showing up. Feel like ive lost ten years of my life to this piece of coding.

Im thinking even if the same reading comes out 4 times in a row then take that reading but i just dont know to code it.

TomDev:
Cheers for that Riva, this code looks like exactly what im looking for. I just ran it now but im having a problem displaying results on the serial monitor, nothing seems to be showing up. Feel like ive lost ten years of my life to this piece of coding.

As michinyon says in an earlier post there will probably be some noise (the analogue readings will flutter even when the weight is constant) so you may never get a steady reading for 1 second or more.
If you put a weight on the scale let it settle then run this code

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(A0));
  delay(100);         // Read about 10 times a second
}

how much does the value change by? This will give an indication of the noise level you have to compensate for. Might be worth trying a range of weights to see if noise is same with light/heavy loads.
When you know the noise level you can put extra code at this line

  // Maybe round off newReading here to account for analogue noise

to round off the result to eliminate noise.
Another method might be to average readings to reduce noise.

Yeah I have a variety of weights that I'm using and and if I place a 60 gram weight on I get readings like this 60 60 60 60 61 60 60 59 60 60 60 61.

TomDev:
Yeah I have a variety of weights that I’m using and and if I place a 60 gram weight on I get readings like this 60 60 60 60 61 60 60 59 60 60 60 61.

So the raw adc value is also the weight in grams with no conversion needed? Look at this document and note that rounding is not a part of how to do it, despite what seems like common sense. What you want to do is over-sample and decimate the result. I would take 64 or 128 samples and right shift the noise off. You can actually increase your resolution to more than 10 bits with this method. Please look at the document.

http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CDoQFjAC&url=http%3A%2F%2Fwww.atmel.com%2Fimages%2Fdoc8003.pdf&ei=lkxDUeX9B6Ke2QXx9oDIBw&usg=AFQjCNF_A3E9IfV7OzWqyano1-aHRKseFA&bvm=bv.43828540,d.b2I&cad=rja

EDIT: Here is some code that does what I was talking about, it will give you fairly smooth numbers.

//  Temperature measuring stuff
#define TEMP_IN_F .1074  // multiply by this to convert to fahrenheit
int LM34Pin = A3;    // Analog pin 3
int x;
unsigned int temp = 0;
unsigned long temptot = 0;

  //  Sample the LM34 a bunch of times then compute a nice smooth average temperature
  temptot = 0;                     //  clear the accumulator
  //  Read the ADC 64 times and compute a total
  for(x = 0; x < 64; x++) {    
    temptot += analogRead(LM34Pin);
  }
  //  divide by 64 to decimate, could divide by 16 and keep a legitimate 12 bit result
  temp = temptot >> 6;

Another untested variation that averages readings over half interval time and then prints result if 2 consecutive readings match.

const float aReading = 120.0;
const float aLoad = 60.0; // lbs.
const float bReading = 344.0;
const float bLoad = 172.0; // lbs.

const unsigned long interval = 1000UL;                    // 1 Second interval
float newReading = 0;
float oldReading = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  unsigned long newTime = millis();                       // Get current time going into loop
  newReading = analogRead(A0);                            // Preload newReading ready to averaging
  while ((newTime + (interval / 2)) < millis()){          // Average readings over half of interval time
    newReading = (newReading + analogRead(A0)) / 2;       // Add new reading and average
  }
  if (newReading == oldReading) {                         // 2 consecutive readings?
    // Calculate load based on A and B readings above
    float load = ((bLoad - aLoad)/(bReading - aReading)) * (newReading - aReading) + aLoad;
    Serial.print("Reading: ");
    Serial.print(newReading,1); // 1 decimal place
    Serial.print("  Load: ");
    Serial.println(load,1);  // 1 decimal place, println adds a carriage return
  }
  oldReading = newReading;
}