Reading Voltage and Working with Potentiometers for Arduino
In this tutorial, we will explore how to read voltage values using a potentiometer with an Arduino. By the end of this project, you will understand how to convert analog readings into voltage values and even calculate the resistance of a potentiometer based on the voltage output. This is useful in various applications where you need to monitor and control voltage levels.

In this project, we will use an Arduino to read the voltage from a potentiometer connected to one of its analog input pins. The potentiometer will allow us to vary the voltage, which we will then convert into a readable format and display it on the serial monitor. Additionally, we will extend the functionality to calculate the resistance value based on the voltage reading, providing a comprehensive understanding of how potentiometers work with Arduino.
For further clarification on the steps and code implementation, be sure to check out the video (in video at 00:00).
Hardware Explained
The key components in this project are the Arduino board and the potentiometer. The Arduino is a microcontroller platform that allows you to read input signals and control outputs easily. In this case, it will read the analog voltage from the potentiometer.
The potentiometer is a variable resistor that can adjust its resistance based on the position of its wiper. When connected to a voltage source, it divides the voltage across its terminals, allowing you to output a variable voltage that can be read by the Arduino’s analog input.
Datasheet Details
| Manufacturer | Various |
|---|---|
| Part number | Potentiometer |
| Resistance range | 0 – 1 MΩ |
| Power rating | 0.1 W |
| Temperature range | -40 to 85 °C |
| Type | Linear or logarithmic |
- Ensure the potentiometer is connected properly to avoid incorrect voltage readings.
- Use a multimeter to verify the resistance value of the potentiometer before connecting it to the Arduino.
- Keep the potentiometer within its rated power to prevent overheating.
- Use proper decoupling capacitors if necessary to filter out noise in readings.
- Be cautious about floating inputs; always connect unused pins to ground.
Wiring Instructions

To wire the potentiometer to the Arduino, start by connecting one end of the potentiometer to the 5V pin on the Arduino and the other end to the ground (GND) pin. The middle pin of the potentiometer, which is the wiper, should be connected to the analog input pin A0 on the Arduino. This setup allows the Arduino to read the variable voltage output from the potentiometer.

If you are using a different analog pin, make sure to update the corresponding pin number in your code. For example, if you connect the wiper to A1, you will need to change the code to read from A1 instead of A0.
Code Examples & Walkthrough
void setup() {
Serial.begin(9600); // setup serial
}
void loop() {
int sensorValue = analogRead(A0); // Read from A0
float voltage = sensorValue * (5.0 / 1023.0); // Convert to voltage
Serial.print("Voltage ="); // prints the text "Voltage ="
Serial.print(voltage);
Serial.println();
delay(300);
}
This code snippet initializes the serial communication and continuously reads the analog value from pin A0. It converts the analog reading (0 to 1023) into a voltage (0 to 5V) and prints it to the serial monitor.
float RT = 50000; // the potentiometer value
float R; // the unknown R value
void loop() {
int sensorValue = analogRead(A0); // Read from A0
float voltage = sensorValue * (5.0 / 1023.0); // Convert to voltage
R = (voltage * RT) / 5.0; // Calculate resistance
Serial.print("Voltage ="); // prints the text "Voltage ="
Serial.print(voltage);
Serial.print("v R=");
Serial.print(R);
Serial.print(" ohms");
Serial.println();
delay(300);
}
This second code snippet builds upon the first by adding calculations for the resistance value based on the voltage reading. It uses the known resistance value of the potentiometer RT and calculates the unknown resistance R using the formula derived from Ohm's law.
Demonstration / What to Expect
When you run the program, you should expect to see the voltage values printed in the serial monitor, which will change as you adjust the potentiometer. The output will also display the calculated resistance value based on the voltage reading. Be cautious to avoid reversed polarity connections, as this could lead to incorrect readings or damage to the components (in video at 02:30).
Video Timestamps
- 00:00 - Introduction to the project
- 01:15 - Explanation of the hardware components
- 02:30 - Wiring instructions
- 03:45 - Code walkthrough
- 05:00 - Live demonstration
Ressourcen & Referenzen
Noch keine Ressourcen vorhanden.
Dateien📁
Keine Dateien verfügbar.