Learn electronics, coding, and projects — step by step.

Arduino Basics: Analog Input (Potentiometers, Sensors)

Table of Contents

Analog inputs allow your Arduino to read variable voltages from sensors or devices, typically ranging from 0 to 5V. These inputs are useful for devices like potentiometers, light sensors, and temperature sensors, which produce a continuous range of values rather than just HIGH or LOW.

Reading Analog Inputs

Use the analogRead() function to get the value from an analog pin:

  • Syntax: value = analogRead(pin);
  • The returned value ranges from 0 (0V) to 1023 (5V on Arduino Uno).

Example of reading a potentiometer:

int potPin = A0;     // Analog pin connected to potentiometer
int potValue = 0;

void setup() {
  Serial.begin(9600);   // Initialize Serial Monitor
}

void loop() {
  potValue = analogRead(potPin);      // Read potentiometer value
  Serial.print("Potentiometer: ");
  Serial.println(potValue);           // Print value (0–1023)
  delay(200);                          // Short delay for readability
}

Introduction to Analog Sensors

Analog sensors provide a voltage output proportional to the physical quantity they measure. Some common examples:

  • Light sensors (photoresistors, LDRs): Output voltage changes with light intensity.
  • Temperature sensors (LM35, TMP36): Output voltage varies with temperature.
  • Potentiometers: Variable resistors that change voltage based on knob position.
  • Flex sensors or pressure sensors: Output voltage changes with bending or pressure.

Converting Analog Values to Real Units

Sometimes you want the analog reading in real-world units (like volts, °C, or lux). Use a simple formula:

float voltage = analogRead(A0) * (5.0 / 1023.0); // Convert to volts

For a temperature sensor (LM35):

float temperatureC = analogRead(tempPin) * (5.0 / 1023.0) * 100; // Convert to °C

Tips for Analog Input

  • Use A0–A5 on Arduino Uno for analog inputs.
  • Keep wiring short to reduce noise and interference.
  • Use a capacitor for smoothing if sensor readings fluctuate rapidly.
  • Always check the sensor datasheet for proper voltage range and output scaling.

By mastering analog inputs, you can make your Arduino projects respond to environmental changes like light, temperature, or position, enabling more interactive and responsive applications.

×



Related Articles: (by Series)