I'm reading Analog Inputs A0,A1 & A2 and print the readings to the Serial Monitor.
I initially wanted to interface an accelerometer but I wasn't sure if the readings correspond correctly, so I detached the accelerometer.
Then I saw that I was getting values with nothing attached to the pins!!!! Also the values are different for all 3 pins!!!
I attached a potentiometer for troubleshooting. The potentiometer was read correctly, but I saw that the values my potentiometer pin affects the values of the two other neighbour analog pins eventhough they are not in any way connected!!!!
Is my arduino board damaged or is there something about reading analog input that I don't know about???
You certainly don't want a pullup or pulldown on an analog input from an accelerometer.
Analog accelerometers have large output resistances to allow adding a capacitor for low-pass
filtering, so adding a pullup or pulldown would form a voltage divider and change the reading.
analogRead on a floating pin will return random noise, but don't worry about it, connect the
accelerometer outputs to the pins and then the values are meaningful.
I have given up on the accelerometer. So far, my readings are arbitrary and not influenced when I tilt or move? I have not soldered the connections, I use a row of pin headers plugged into the holes on a breadboard. IS that the problem?
What about my observation that values on neighbouring analog pins are changed as well eventhough my potentiometer is on a diffrent pin? Is that normal?
GrizzlyBear:
What about my observation that values on neighbouring analog pins are changed as well eventhough my potentiometer is on a diffrent pin? Is that normal?
No.
We can't see your circuit or code from here so... it's impossible to help.
In your potentiometer test, try connecting a 10k resistor or similar between each of the unused analog ports and 0V. Then vary the pot and check the readings on all ports.
Hi,
Post you circuit and the code you have tested, then only can debug the problem. There is no need for any interface or Pull-Ups for analog accelerometer. You can simply connect to the analog input and read and print continuously in a while loop to test the sensor.
What about my observation that values on neighbouring analog pins are changed as well eventhough my potentiometer is on a diffrent pin? Is that normal?
Yes, normal. Unconnected analog input pins are said to be 'floating' and are just measuring circuit noise. They have no effect on analog input pins that do have something wired to them.
GrizzlyBear:
What about my observation that values on neighbouring analog pins are changed as well eventhough my potentiometer is on a diffrent pin? Is that normal?
No.
Actually that's not true. The ADC works by charging up a tiny capacitor from the input pin then measuring the charge on the capacitor.
If there's nothing at all connected to the pin then you might be seeing the residual charge from a pin that does have something connected to it.
I guess it makes sense that the pins are influenced by surrounding noise when they are floating.
As suggested, I wanted to test my pins by connecting several potentiometers. I only have two potis , but I connected them. Then I noticed the strangest thing. The first poti worked fine and values in my Serial monitor corresponded correctly. When I tried the 2nd poti the serial monitor froze and my Arduino was not recognized by the COM3 serial port. I tested this again and the error reoccurred. I noticed that this not specific to the pin but to the potentiometer!!!!! Whenever I use this one potentiometer my Arduino loses serial connection!? What's going on???
After some more poti testing my Analog Ins are doing fine. I wanna give the accelerometer another shot.
Im using ADXL335.
The setup is simple. I have VCC connected 3.3V on my Arduino, GND as usual, and the analog inputs X,Y,Z on A0,A1, A2.
The Code is the most straigh-forward approach.
int X = 0;
int Y = 0;
int Z = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
X = analogRead(A0);
Y = analogRead(A1);
Z = analogRead(A2);
Serial.print(X);
Serial.print(" ");
Serial.print(Y);
Serial.print(" ");
Serial.println(Z);
delay(500);
}
I've tried different codes I found on the net. I see no change of values, when I tilt or move.
Is my ADXL not working? Or am I doing things right.