int potPin = 34; // Analog input pin (GPIO34 on ESP32)
int LED_BUILTIN = 2; // PWM output pin (GPIO2 on ESP32)
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600); // Start serial communication at 9600 bps
pinMode(potPin, INPUT);
}
void loop() {
int potValue = analogRead(potPin); // Read
float voltage = potValue * (5.0/1023.0); // Convert
int ledBrightness = map (potValue, 0, 1023, 0, 255); //Map
analogWrite (LED_BUILTIN, ledBrightness); //Set
// Print the analog read value and the calculated voltage to Serial Monitor
Serial.print("Potentiometer Voltage: ");
Serial.print(voltage);
Serial.println(" V");
delay(100); // Wait for 100 milliseconds
}