Arduino Analog Input read from Pin with the help of analogRead function from Potentiometer

Arduino Analog Input or Read with analogRead Function

Arduino board have build-in Analog To Digital Converter to take analog inputs. Arduino have a function called analogRead.

Analog input features is required to interface analog sensors like, LM35 temperature sensor, LDR light sensor etc.

Arduino UNO have 10 bit analog to digital converter. It means the digital value received from analog input is from 0 to 1023.

The digital value 0 means minimum analog input and 1023 digital value means maximum analog input.

Arduino Uno Analog Pins

Arduino UNO board have six analog input pins names from A0 to A5, as shown in the figure 1 below.

Arduino Uno Board Analog Input Pins
Fig.1 – Arduino Uno Board Analog Input Pins from A0 to A5.

Syntax of AnalogRead function

int x = analogRead(A0); //read analog input from A0 pin.

analogRead() function return a integer data type. In the above code we are using variable x of integer data type to hold the digital value.

Arduino UNO Analog To Digital Converter

Arduino UNO works on the 5 volt and the same voltage is used as analog reference.

Analog reference is the maximum analog input for the conversion. If Analog ref. is set to 5 volt and the analog input is also 5 volt than Arduino reads it as 1023 corresponding digital value.

If input in near 0 volt, Arduino read it as digital (0000000000) which is 0 in decimal. And if the input is near 5 volt, Arduino read it as digital (1111111111) which is 1023 decimal.

In 10 bit resolution (0000000000) is minimum digital value, and (1111111111) is maximum digital value.

Arduino Potentiometer Wiring

To test the Arduino analog input function we can use Potentiometer to supply analog voltage to the A0 pin. Or you can use any other analog input pin of the Arduino.

The Potentiometer is a three terminal device. The center terminal is the connected to the A0 pin of Arduino. and other two pins are connected to ground and VCC ( 5 volt ).

The Fig 2 shows how to connect the Potentiometer to the Arduino UNO on pin A0. Similarly you can connect with any other analog input pins of Arduino.

Arduino Analog Input read from Pin with Potentiometer Wiring Example
Fig.2 – Arduino Analog Input Example from Potentiometer Wiring.

Analog Input Examples

In this example we take input from Potentiometer on A0 pin, and read this analog input with the help of analogRead function. And send digital reading to the serial port.

You can use serial monitor terminal application to watch the analog digital values.

Example 1 – Analog input test program code on pin A0.

    analogRead() function test program.
	Author: Nilesh Chaurasia
void setup() 
	Serial.begin(9600); // Set the baud rate to 9600
void loop() 
	int x = analogRead(A0);// s1 is String type variable.
	Serial.print("Received Digital Value => ");
	Serial.println(x);//display same in the serial monitor.
	delay(2000);//Do the same thing after 2 second delay.

In the example you have to rotate the screw of the Potentiometer to see some changes in the serial monitor.

Arduino Analog Input read with the help of analogRead function
Fig.3 – Analog Input read with analogRead function display in Serial Monitor.

Note: If the Potentiometer is near the 0 volt position the serial monitor shows 0. And if Potentiometer near the 5 volt position the serial monitor shows the 1023 digital value.

You can leave a response, or trackback from your own site.
Leave a Reply to the article

Learning & Certifications
Follow Us
Facebook Icon   Linked In Icon   Twitter Icon  
Validation and Recognition

Valid CSS! Valid HTML5!          Protected by Copyscape