0

I have five accelrometer sensors (MMA 7361) connected to the analog channels of Arduino Duemilanove. I am using the following code to read the data. (I am reading from only one axis from each sensor.)

#include <avr/io.h>
#include <avr/wdt.h>

int sensorValue = 0; // value read from the pot

void setup() 
{
    Serial.begin(9600); // initialize serial communications at 9600 bps:
}

void loop() 
{
    // read the analog values:

    int i=1;

    Serial.print("ACS#");

    for(i=0;i<5;i++)
    {

        sensorValue = analogRead(i);
        Serial.print(sensorValue);
        Serial.print("#");

        delay(10);
    }

    Serial.println("");

}

I am using a delay of 10 after reading each sensor. What should the value of the delay I should be using after reading one sensor to get the correct values from the sensors?

migrated from electronics.stackexchange.com Jan 9 '15 at 17:44

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 1
    Why do you need any delay? – Ignacio Vazquez-Abrams Jan 9 '15 at 17:39
  • No delay is needed. Note however that the serial communication might not be able to keep up. If that happens your Serial.print calls will block/delay until the TX-buffer is no longer full. No big deal, but might be useful to know. – Gerben Jan 9 '15 at 19:13
  • What are you trying to do with the data? This will help us give you an answer about sample rates – portforwardpodcast May 11 '15 at 12:33
1

A delay is not needed.

What can be more beneficial, though, is making a dummy reading between each real reading. This gives the ADC more of a chance to settle on the right reading without the Sample and Hold capacitor being influenced by the previous reading.

The simplest way is just to duplicate your analogRead line so it's done twice.

  • what is the time required for the ADC to settle on the right reading? – ukg Jan 9 '15 at 18:10
  • You'll find that kind of information in the datasheet. Cross-reference that with the analogRead() code to see what the current settings are. – Majenko Jan 9 '15 at 18:23
  • @ukg You don't need to wait for the ADC to settle for any of the readings, each pin uses a different ADC, and they are continuously tracking the input. – meiamsome Apr 9 '15 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.