IOT Virtual Lab
Interfacing Potentiometer with Arduino
ARDUINO CODE
int potPin = A0; // Potentiometer is connected on Analog Pin A0 int ledPin = 9; // LED is connected on Pin No. 9 int potValue; // Variable to store potentiometer value int ledValue; // Variable to store LED brightness value void setup() { pinMode(ledPin, OUTPUT); // LED pin mode is OUTPUT Serial.begin(9600); // Initialize serial communication } void loop() { potValue = analogRead(potPin); // Read potentiometer value (0-1023) ledValue = map(potValue, 0, 1023, 0, 255); // Map to LED brightness (0-255) analogWrite(ledPin, ledValue); // Control LED brightness Serial.println(potValue); // Print potentiometer value to serial monitor delay(100); // Small delay for stability }
Start Simulation
Click the potentiometer!