Go Down

Topic: Changing values (Read 532 times) previous topic - next topic

Drew Davis

Hello I have two sensors from spark fun which slowly change their values for no reason. The change is minimal, but I was wondering why that happens and how to prevent the change in value.

Thanks

https://www.sparkfun.com/products/9453

robtillaart

Can you tell a bit more, what values changes?
from what to what?
What values did you expect?

Can you post the code to read these sensors?

Does it get the original value if you do a restart?

It can also be minute differences that the sensor sees but the human eye not.
It can also be that the sensor warms up a little and slightly changes behavior.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Drew Davis

Sorry for the lack of info.

The analog value is what changes.
I did not expect any certain value but I wanted it to stay consistent based on what the sensor sees.

For the first 10 seconds or so the readings are all over the place then it starts to become somewhat consistent (+/- 10).

If i power it off and turn it on a few seconds later the values it was reading before I shut it off is what the lcd displays…  It does not have that time period where the values are completely unreliable.

Below is a link of it in action. Their is one sensor on each side... where the arm stops.

http://www.youtube.com/watch?v=Q-XWh6XneTA

Here is the code for just the light sensors…
Code: [Select]
#include <SerialLCD.h>
#if ARDUINO < 100
#include <NewSoftSerial.h> //this is a must
#else
#include <SoftwareSerial.h>
#endif
SerialLCD slcd(11,12);

// Serial LCD setup


int sensorPin = A1  ;
int long sensorValue = 0;

void setup() {
slcd.begin();

}

void loop() {
 
  slcd.setCursor(0, 1);
  sensorValue = analogRead(sensorPin);
  slcd.print(sensorValue, DEC);

   delay(100);
   
     slcd.clear(); 
 
}







robtillaart


You could use some averaging in your code

Code: [Select]
#include <SerialLCD.h>
#if ARDUINO < 100
#include <NewSoftSerial.h> //this is a must
#else
#include <SoftwareSerial.h>
#endif
SerialLCD slcd(11,12);

// Serial LCD setup


int sensorPin = A1  ;
int sensorValue = 0;

void setup()
{
  slcd.begin();
}

unsigned long lastTime = 0;

void loop()
{
  // average
  int sum = 0;
  for (int i=0; i<8; i++)   sum += analogRead(sensorPin);  // with an int you can max average 32 samples
  sensorValue = (sum+4)/8;  // incl rounding

  if (millis() - lastTime > 100)  // removes the delay which is blocking
  {
    lastTime = millis();
    slcd.clear();
    slcd.setCursor(0, 1);
    slcd.print(sensorValue, DEC);
  }
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Drew Davis

Your code did not really produce any different results.


Do you have another idea?


Thanks for the help,
Drew

robtillaart

Quote
Your code did not really produce any different results.

Can you post the output of the code?  (hint use serial.print instead)

How do you power the system?
Motors need to have a separate power supply.
If an arduino has too little power analog reads can become inaccurate
e.g. measure if the Arduino has its 5Volts

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up