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?
-
1Why do you need any delay?Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2015年01月09日 17:39:43 +00:00Commented Jan 9, 2015 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– Gerben2015年01月09日 19:13:17 +00:00Commented Jan 9, 2015 at 19:13
-
What are you trying to do with the data? This will help us give you an answer about sample ratesbenathon– benathon2015年05月11日 12:33:19 +00:00Commented May 11, 2015 at 12:33
1 Answer 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– ukg2015年01月09日 18:10:00 +00:00Commented Jan 9, 2015 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– Majenko2015年01月09日 18:23:55 +00:00Commented Jan 9, 2015 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– meiamsome2015年04月09日 21:48:03 +00:00Commented Apr 9, 2015 at 21:48