10 bit AtoD returning integers from 0 to 1023.

Read Analog Input

There is no need to set the pin up as an analog input, just start reading it:

  int MyAnalogValue = analogRead(A3);    //Read 10-bit (0 to 1023) analog input value (causes stall for approx 100uS)

Setting The Analog Reference Voltage

Use the analogReference() function;

DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 (not available on the Arduino Mega)
INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference. 

Using Analog Pins as GPIO

The analog pins also have all the functionality of general purpose input/output (GPIO) pins (the same as digital pins 0 – 13).

Use the aliases A0 (for analog input 0), A1, etc. E.g this would set analog pin 0 to an output, and to set it HIGH:

pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);

Special Arduinos

Arduino Due, Zero and MKR Family

Use analogReadResolution() to set the resolution you want to use.

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.