Menu Close

Arduino Nano – Analog Input

This tutorial of Robo India explains the basics of input and output programming in physical computing world. This tutorial teaches how to take analog input using Arduino Nano.

1. Introduction:

To read an analog signal through Arduino Nano, Analog to Digital conversion is required. Arduino Nano has 10 bit ADC which means it scales an analog signal in a range of 0-1023.

In this example an analog input is taken and it displayed on an LED and the serial monitor.In order to show the input result on LED, Mapping of input value is need. Thus mapping is done by dividing input values by 4.

S.No.ItemQuantity
1. Arduino Nano 1
2. Mini USB Cable 1
3. Breadboard 1
4. LED 1
5. Resistor 220 Ohm 1
6. 10K Preset 1
7. Male to Male Jumper Wires 7

2. Building Circuit

Schematic Diagram:

Circuit Layout:

3. Programming:

You may download this code (Arduino Sketch) from here.

const int analog_ip = A2;   //Naming analog input pin
const int LED = 3;          //Naming LED Pin
int inputVal  = 0;          //Variable to store analog input values

void setup() {
  pinMode(LED, OUTPUT);     // Defining pin as output
  Serial.begin(9600);       // Initiating Serial communication

}                                                                                                                                                                                                                           
void loop() {
  inputVal = analogRead (analog_ip); // Analog Values 0 to 1023
  Serial.println (inputVal);
  analogWrite(LED, inputVal/4);      // Mapping 0 to 255
  delay(1000);
}

4. Output

The analog input is printed on the serial monitor. LED brightness is adjusted as per the analog input value. Try rotating preset and see the effect on the LED and serial monitor.

5. Troubleshooting

Input values are not changing: Check the preset connections.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply