Notifications
Clear all
0
07/06/2025 5:47 am
Topic starter
I have a potentiometer and want to use it to control a component like an LED or motor eventually, but for now, I just want to read its values in the Serial Monitor using Arduino. How should I wire it, and what code should I use?
1 Answer
0
28/06/2025 7:40 am
There are many tutorials available online on interfacing a potentiometer with Arduino, explaining this in depth.
Still, I will cover this quickly:
A typical potentiometer has 3 pins:
- One side pin goes to GND
- The other side pin goes to 5V
- The middle pin (wiper) connects to an analog input pin, like A0 on your Arduino
This setup allows the potentiometer to act as a voltage divider, and the middle pin will give you a variable voltage between 0V and 5V as you turn the knob.
Upload this program:
const int potPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int potValue = analogRead(potPin); // Read value (0–1023)
Serial.println(potValue); // Output the value to Serial Monitor
delay(100); // Small delay for readability
}
Once the code is uploaded, open the Serial Monitor. As you turn the knob, you’ll see values between 0 and 1023:
- Close to 0 when turned all the way to one side(towards GND)
- Close to 1023 when turned to the opposite side(towards 5V)
- Around 512 when centered