Tutorial 4 – Using a Potentiometer with Arduino
Tutorial 4 – Using a Potentiometer with Arduino
Welcome back to our Arduino tutorial series at CraftedTech Engineering! In the last tutorial, we worked with analog pins and understood how to read values using analogRead()
. Now, it’s time to put that into practice with a common analog component — the potentiometer.
This tutorial will guide you in connecting and reading values from a potentiometer using your Arduino. Perfect for learning how to receive analog input from the physical world.
🔌 What You’ll Need
-
1 Arduino Board (e.g., Arduino UNO)
-
1 Potentiometer (10k ohm recommended)
-
Breadboard
-
Jumper wires
-
USB cable for Arduino
You can order the required components here:
💡 What Is a Potentiometer?
A potentiometer is a variable resistor. It has three pins: one connects to power (5V), one to ground (GND), and the center (wiper) gives you an analog value depending on how you rotate the knob. You can use this to control brightness, speed, volume, or anything where gradual input is needed.
🗃️ Step-by-Step Instructions
Step 1: Wire the Potentiometer
-
Connect one outer pin to 5V on the Arduino
-
Connect the other outer pin to GND
-
Connect the middle pin (wiper) to A0
Step 2: Open the Arduino IDE Launch the IDE and connect your Arduino to your computer using the USB cable.
Step 3: Write and Upload the Code
int sensorPin = A0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue); // Output value to Serial Monitor
delay(500);
}
🔍 Explanation:
-
sensorPin
is set to A0 where the wiper of the potentiometer is connected. -
analogRead()
reads a value between 0 and 1023 depending on the knob position. -
Serial.println()
prints the value to the Serial Monitor for real-time feedback.
🧠 Try This: Control an LED Use the analog value to control LED brightness using analogWrite()
and a PWM pin (like pin 9).
🛠️ Troubleshooting Tips
-
If values seem stuck, check your wiring (especially the middle pin)
-
Be sure you're using the correct analog pin
-
Try turning the knob slowly and observing the value in the Serial Monitor
📅 What You Learned in This Tutorial
✔️ How a potentiometer works ✔️ How to wire a potentiometer to Arduino ✔️ How to use analogRead()
to receive analog input ✔️ How to view sensor data in the Serial Monitor
📌 Next Up: Tutorial 5 – Fading an LED with PWM and a Potentiometer
We’ll use the potentiometer from this tutorial to control LED brightness smoothly using Pulse Width Modulation.
📣 Don’t forget to follow CraftedTech Engineering for more step-by-step tutorials and practical Arduino projects!
🔗 Website: craftedtechengineering.com 📘 Facebook: @CraftedTechEngineering 📺 YouTube: @CraftedTechEngineering
We Craft Your Future Innovations.