// ESP32 + Potentiometer + LED
// Middle pin of potentiometer -> GPIO34
// LED (positive) -> GPIO2, LED (negative) -> GND
int potPin = 34; // Analog input pin
int ledPin = 2; // LED output pin
int potValue = 0;
int scaledValue = 0;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
Serial.println("Potentiometer with LED Control Started...");
}
void loop() {
potValue = analogRead(potPin); // Read analog input (0–4095)
scaledValue = map(potValue, 0, 4095, 0, 255); // Convert to 0–255 range
Serial.print("Pot Value (0–255): ");
Serial.println(scaledValue);
// If potentiometer value > 100, turn ON LED
if (scaledValue > 100) {
digitalWrite(ledPin, HIGH); // LED ON
} else {
digitalWrite(ledPin, LOW); // LED OFF
}
delay(500); // Wait half a second
}