#define POTENTIOMETER_PIN 36 // ESP32 pin GPIO36 (ADC0) connected to Potentiometer pin
#define LED_PIN 21 // ESP32 pin GPIO21 connected to LED's pin
#define ANALOG_THRESHOLD 2000
void setup() {
pinMode(LED_PIN, OUTPUT); // set ESP32 pin to output mode
Serial.begin(115200); // initialize serial communication at 115200 baud rate
}
void loop() {
int analogValue = analogRead(POTENTIOMETER_PIN); // read the input on analog pin
Serial.print("Analog Value: "); // print the analog value to the Serial Monitor
Serial.println(analogValue);
if (analogValue > ANALOG_THRESHOLD)
digitalWrite(LED_PIN, HIGH); // turn on LED
else
digitalWrite(LED_PIN, LOW); // turn off LED
delay(100); // add a small delay to make the serial output more readable
}