Introduction
This experiment demonstrates how to measure voltage using Arduino's analog-to-digital converter (ADC).

Components Needed
- Arduino (e.g., Uno, Nano)
- Variable resistor (potentiometer)
- Jumper wires
Circuit Setup
- Connect the potentiometer's wiper to the analog input pin A0 on the Arduino.
- Connect the other two pins of the potentiometer to 5V and GND.
This will allow you to vary the voltage at the analog input pin.

Code for Measuring Voltage
Upload the following code to your Arduino to measure the voltage:
const int sensorPin = A0;
int sensorValue = 0;
float voltage = 0.0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin);
voltage = sensorValue * (5.0 / 1023.0); // Convert ADC value to voltage
Serial.println(voltage);
delay(100);
}
Explanation
The Arduino reads the voltage from the potentiometer and converts the analog signal into a digital value using the ADC. The voltage is then calculated and displayed on the Serial Monitor.
Troubleshooting
- If no voltage is read, ensure the potentiometer is properly connected and functioning.
- If the voltage values seem incorrect, check the wiring and calibration of your analog-to-digital conversion.