1

I measure 2 analog pins: A4 and A5. The A5 pin is connected to another Arduino's digital out (through a 10k resistor) which has a simple program: 5ms on and 100ms off. The A4 pin is not connected anywhere.

The analog pins are inited with pinMode(APIN, INPUT), reading is simply performed with the analogRead(APIN) function (there is no delay between the readings). I have tried with delays between the measurements but the results are the same.

The results: enter image description here

The A5 pin (which is connected) measures the correct value. However, the unconnected A4 pin is clearly interferred by the input of A5. It works like this with another pins, delays between the readings, double use of analogRead()... I even swapped the Arduinos (Arduino Nano and Uno) and the results are the same.

Is it because of that these Arduinos are clones? Or are these Arduinos damaged?

  • 1
    Did you try connecting A4 to VCC or GND? Floating signal can give this behavior. – Mikael Patel Jul 18 at 20:11
  • Thank you, it seems to work. Can I connect a pin directly to VCC or should I use resistor? – Maci0503 Jul 18 at 20:42
2

If you want to measure a pin (i.e. defined as input pin, either digital or analog), you have to use a pull up or pull down resistor (either internal or external depending on what the MCU GPIOs have).

This resistor makes sure in case there is nothing attached, that the (mostly high ohm) resistor will make sure the nonconnected pin will either give a LOW or HIGH as input (or in case of analog, the minimum or maximum value).

When the pin is connected, the pull down/up resistor will change the result so marginally that it can be ignored.

0

I believe what you are seeing is the effect of the sample and hold process used by the Arduino analog to digital converter (ADC).

The way the sample and hold circuit in the ADC works is

  1. Connect the pin to an internal, fixed size capacitor
  2. Disconnect the pin
  3. Compare the capacitor voltage against a fixed value

All the analog pins in the Arduino share the very same capacitor, so if such capacitor has no opportunity to discharge another reading will be influenced by the previous one.

Ref.

  1. https://en.wikipedia.org/wiki/Sample_and_hold
  2. http://ww1.microchip.com/downloads/en/appnotes/atmel-8456-8-and-32-bit-avr-microcontrollers-avr127-understanding-adc-parameters_application-note.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.