Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Reading an output analog pin with an input analog pin

I am having a hard time understanding why I can't read one analog pin's output with another analog pin. The docs state to put a delay in between, which I've done (I've tried up to one second with the same results). I've got this minimized code:

void setup() {
 Serial.begin(9600);
 pinMode(A0, INPUT);
 pinMode(A5, OUTPUT);
}
void loop() {
 for (int i=0; i<1024; i++){
 analogWrite(A5, i);
 delay(100);
 Serial.println(analogRead(A0));
 }
 Serial.println("done");
 delay(10000);
}

When it starts, it displays 6-9 for a few dozen iterations, then suddenly jumps to ~1018 and remains throughout the rest of the run.

A5 is connected directly to A0 via a 4" jumper cable. Nothing is connected to AREF. If I connect AREF to 5v, the output does not change but by a single digit. If I connect it to ground, it immediately outputs 1023.

I'm hoping this is a "do'h" moment here. Can someone please let me know what I'm not doing correctly?

Update: This is a legit Arduino Uno R3 board. When I connect A0 directly to 5v+, I get 1023 as expected as the output.

Answer*

Draft saved
Draft discarded
Cancel
4
  • Thanks for this, but I believe the answer that states that I was incorrectly assuming that the A'N' pins were analogWrite() capable is correct. I definitely know I had current flow without need of a resistor, capacitor or other intermediaries. I made bold mis-assumptions as to what pins can do what. Commented Jul 22, 2017 at 3:11
  • This answer completely misses the issue. No, you do not need the pin to source current in order to have a well defined voltage. And your 1 µF capacitor can damage the output pin due to the inrush current. Commented Jul 22, 2017 at 12:00
  • @EdgarBonet Srry, it should be .1uf. So do you mean to use analogueRead() and read a PWM value insted of a real analogue voltage between 0v and 5v. Commented Jul 22, 2017 at 12:09
  • You wrote: "do you mean to use analogueRead() and read a PWM value [...]". No, I mean what I wrote, nothing more. Commented Jul 22, 2017 at 13:15

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /