int potPin = A3; // Potentiometer connected to A3
int ledPin = 13; // LED connected to pin 13
int val = 0; // Variable to store sensor value
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize Serial Monitor
}
void loop() {
val = analogRead(potPin); // Read value from potentiometer (0–1023)
Serial.print(\"Potentiometer Value: \");
Serial.println(val);
digitalWrite(ledPin, HIGH); // Turn LED ON
delay(val); // Wait for time based on potentiometer value
digitalWrite(ledPin, LOW); // Turn LED OFF
delay(val); // Wait again for same duration
}
Instruction Details
Wiring: Connect potentiometer outer pins to 5V and GND, middle (wiper) to Analog Pin A0.
Library: Not required (built-in).
Upload Code: Tools → Board → Arduino Uno. Tools → Port → select your COM port. Click Upload button.
View Output: Open Serial Monitor (Tools → Serial Monitor) at 9600 baud. Values 0–1023 display. Rotate knob to see values change. Use for LED brightness, servo control, etc.
How to Use
Connect the required components as per the Pin Configuration above
Open Arduino IDE and create a new sketch
Copy and paste the code above
Select your Arduino board and COM port from Tools menu
Click the Upload button to upload the code to your Arduino
Open Serial Monitor (if applicable) to see the output