Unaccurate analogRead() values with LM35 and ADXL335 sensors
Moderators: adafruit_support_bill, adafruit

Unaccurate analogRead() values with LM35 and ADXL335 sensors

by robogrobo on Thu Jan 28, 2010 4:22 am

Hi there

After trying almost everthing: reducing components, changing Arduino, proper external powering (min. 7V), reading the forums I need to post my problem.

Problem:
I try to read the temperature with an LM35 and get accelerometer x,y,z data with an ADXL335. As long the variable "pressed" is equal false (see sketch code), i get accurate room temperatures values. When i change the pressed variable to true (reading accelerometer data too), the values from the LM35 alter every loop (the ADXL335 rest on a flat surface). The output looks like this:

Code: Select all | TOGGLE FULL SIZE
logging lm35 and adxl335
tmp, x, y, z
21.7, 230, 340, 312
17.6, 230, 340, 312
20.0, 230, 340, 312
18.6, 230, 340, 311
22.0, 230, 340, 312
...

Do you have any idea why is this. Do i have a faulty setup on my breadboard. Some beginner circuit failure?

Setup:
- Arduino Duemilanove (powering from computer via usb)
- ADXL335 Accelerometer on a 0.5m cable, powered via Arduino 3.3V, attached to analog input 0-2
- LM35 attached to analog input 3
- the button, led, libelium microsd shield ist with this sketch not working, i used it to start logging (indicating with led) on the microsd card

Code: Select all | TOGGLE FULL SIZE
boolean pressed = false;

void setup() {
  Serial.begin(9600);
  Serial.println('logging lm35 and adxl335');
  Serial.println('tmp, x, y, z');
}

void loop() {
  //  lm35
  float volt = analogRead(3) * 3.3 / 1024;
  float tmp = (volt - 0.5) * 100;
  Serial.print(tmp);
 
  //  adxl335
  if(pressed) {
    Serial.print(',');
    Serial.print(analogRead(0));  // x
    Serial.print(',');
    Serial.print(analogRead(1));  // y
    Serial.print(',');
    Serial.print(analogRead(1));  // z
  }
 
  Serial.println();
  delay(500);
}

setup.jpg
setup.jpg (160.02 KiB) Viewed 9027 times
User avatar
robogrobo
 
Posts: 2
Joined: Thu Jan 28, 2010 3:50 am

Re: Unaccurate analogRead() values with LM35 and ADXL335 sensors

by Len17 on Thu Jan 28, 2010 12:45 pm

I had the same problem using an LM35 & a photocell. A solution is posted here:
viewtopic.php?f=25&t=11597
User avatar
Len17
 
Posts: 393
Joined: Sat Mar 14, 2009 7:20 pm

Re: Unaccurate analogRead() values with LM35 and ADXL335 sensors

by robogrobo on Thu Jan 28, 2010 5:10 pm

Perfect, it's working! Thank you very much for your advice, the link to the post was very informative.
Now I can start to log accurate data.
User avatar
robogrobo
 
Posts: 2
Joined: Thu Jan 28, 2010 3:50 am

Re: Unaccurate analogRead() values with LM35 and ADXL335 sensors

by Fransis on Tue Sep 06, 2011 8:40 am

int x, y, z;

void setup()
{
Serial.begin(9600); // sets the serial port to 9600
}

void loop()
{
x = analogRead(0); // read analog input pin 0
y = analogRead(1); // read analog input pin 1
z = analogRead(2); // read analog input pin 1
Serial.print("accelerations are x, y, z: ");
Serial.print(x, DEC); // print the acceleration in the X axis
Serial.print(" "); // prints a space between the numbers
Serial.print(y, DEC); // print the acceleration in the Y axis
Serial.print(" "); // prints a space between the numbers
Serial.println(z, DEC); // print the acceleration in the Z axis
delay(100); // wait 100ms for next reading
}
Fransis
 
Posts: 1
Joined: Tue Sep 06, 2011 8:37 am

Re: Unaccurate analogRead() values with LM35 and ADXL335 sensors

by mikeottoole on Wed Nov 07, 2012 1:36 pm

To get a more accurate reading try this...

After your read an analogue pin, *switch it to digital low (use a small resistor in series with the analogue input)...
This will discharge any remaining charge and next time round, your ready to read it again...

In a fast cycle, you may still need a small delay... without this code the delay required may slow time critical application to a point where they are unusable...

*Note
A6 and A7 are analogue so you can't change them...
You need to set the analogue pin to output before using it to discharge and back to input for analogue read...
Mike

mikeottoole
 
Posts: 1
Joined: Mon Apr 02, 2012 6:44 am
Location: Dublin, Ireland