Why is analogRead() returning zero all the time?
hi all,
i'm doing stupid here i've been @ hour , brain hurts. if can, please shed little sanity! problem is, analogread() returning 0 on both pins i'm using, if *deliberately* remove sensor attached pin , supply voltage.
the code designed work maxbotix ez1 sonars (in case you're wondering!).
thanks!
i'm doing stupid here i've been @ hour , brain hurts. if can, please shed little sanity! problem is, analogread() returning 0 on both pins i'm using, if *deliberately* remove sensor attached pin , supply voltage.
the code designed work maxbotix ez1 sonars (in case you're wondering!).
thanks!
code: [select]
int sonarwarmupdelay = 250; // ms delay after powerup before first reading available
int sonardelaybetweenpings = 25; // ms wait between readings
int sonarreadings = 5; // number of readings obtain (and average) pad results
// configure power output
#define totalsonars 2 // total number of sonar sensors being polled
int pwr[] = { 6, 7 }; // power pins
int son[] = { 1, 0 }; // corresponding data pins pwr[] array (eg. "sonar operated on pwr pin 7 read on analog pin 0)
// store current sensor readings
int vals[totalsonars];
void setup() {
// configure serial
serial.begin(9600);
// turn off sonars start
for (int i; < totalsonars; i++) {
pinmode(pwr[i], output);
pinmode(son[i], input);
digitalwrite(pwr[i], low);
}
}
void loop() {
for (int i; < totalsonars; i++) {
vals[i] = getsonarreading(pwr[i], son[i]);
}
}
int getsonarreading(int pwr, int sensor) {
// powerup sonar
int val = 0;
digitalwrite(pwr, high);
delay(sonarwarmupdelay); // wait specified time before obtaining reading
for (int i; i<=sonarreadings; i++) {
val += analogread(sensor);
delay(sonardelaybetweenpings);
}
digitalwrite(pwr, low);
val = val / sonarreadings;
return val;
}
asking obvious - using analogue input pin?
the analogue pins separate digital ones, , don't need
pinmode(son, input);
the analogue pins separate digital ones, , don't need
pinmode(son, input);
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Why is analogRead() returning zero all the time?
arduino
Comments
Post a Comment