How should analogRead work?
I am trying to use analogRead on an Arduino Micro. A0 is connected to a pentiometer with 3.3 V. A1 and A2 have cables soldered in, but are not connected to anything. When I look at the output of analogRead, it is always between 200-350, sometimes going up to 700 and then back down. When A2 is connected, regardless of which pin analogRead is reading, to the pentiometer, the read is always 0. The setup was working 3 months ago, but I haven't used it since now. I've tried switching which pin is connected to the pentiometer, but it always keeps on giving me the same numbers and doesn't respond to the pentiometer. All of the connections are working.
My code (copied and pasted from the Arduino docs):
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
// outside leads to ground and VCC
int val = 0; // variable to store the value read
void setup() {
Serial.begin(9600); // setup serial
}
void loop() {
val = analogRead(analogPin); // read the input pin
Serial.println(val); // debug value
delay(200);
}
Of course, you might want to tell us what values get printed.
Can't figure your wiring from that, but odds are you've misconnected the pot, and have A0 connected to one end or the other, not the wiper.
Well, from "how should analogRead() work", I jumped to the conclusion that the values printed were unexpected. Of course, with no indication of what values are being printed, I may be incorrect.
It goes up from 280 to 320 and back. The wires are connected properly. The issue is that there is no read coming from the Arduino and whenever A2 is connected to the pentiometer, analogRead() always gives 0, even if I do analogRead(A0) or analogRead(A1).
makes no sense. I'm glad your wires are connected properly, but the evidence belies that.
The numbers output are obscured in the original post by the erroneous use of code tags so here they are
I am trying to use analogRead on an Arduino Micro. A0 is connected to a pentiometer with 3.3 V. A1 and A2 have cables soldered in, but are not connected to anything. When I look at the output of analogRead, it is always between 200-350, sometimes going up to 700 and then back down. When A2 is connected, regardless of which pin analogRead is reading, to the pentiometer, the read is always 0. The setup was working 3 months ago, but I haven't used it since now. I've tried switching which pin is connected to the pentiometer, but it always keeps on giving me the same numbers and doesn't respond to the pentiometer. All of the connections are working.
My code (copied and pasted from the Arduino docs):
I'm sorry, my text got put into a line. The issue is that analogRead doesn't actually read the pentiometer and whenever A2 is connected to the pentiometer, analogRead always returns 0 even if I am doing analogRead(A0). The setup was working a few months ago, but I've just left it sitting there without using it.
Is it ok if I get a video really quick?
You'll have to get past new member restrictions. @UKHeliBob can advise.
To post images etc. you need trust level 1, you can get there by:
- Entering at least 5 topics
- Reading at least 30 posts
- Spend a total of 10 minutes reading posts
Users at trust level 1 can...
- Use all core Discourse functions; all new user restrictions are removed
- Send PMs
- Upload images and attachments
Thank you, I will upload a Google drive link instead then.
@roro3541 FYI @camsysca I can't tell where the wires are in the photo or the drawing. I see solder damage. Why do you not use a header plus at a minimum bread board, but better a proto board?
Being argumentative will not help you learn or come to a solution.
This makes absolutly no sense.
I'm sorry I'm not trying to be argumentative. I did mess up the soldering by burning the board and I should've used a breadboard. It was working before though.
It's really wierd. Let me try to break it down into steps.
I do analogRead(A0) with A0 connected to the pentiometer
It returns consecutive numbers between 280-320
I unplug A0 from the pentiometer and plug A2 into the pentiometer
analogRead(A0), analogRead(A1), and analogRead(A2) all return 0.
Classic symptom of a bad connection, very likely a cold solder joint.
It would help us assist you if we knew why you are not using a bread board or better, and why no male headers to be inserted in female hdrs. Do you not have the parts, not able to get them?
Is it connected to the wiper of the pot and where are the other two ends of the pot track connected to ?