// Project 2: ESP32 Analog Inputs (ADC) // Read a potentiometer on GPIO 4 and print the value (0-4095) plus the // approximate voltage it represents. const int potPin = 4; // potentiometer wiper -> GPIO 4 (ADC2_CH0) int potValue = 0; // stores the raw ADC reading (0..4095) void setup() { Serial.begin(115200); delay(500); // give the Serial Monitor a moment to connect Serial.println(); Serial.println("=============================================="); Serial.println(" Project 2: ESP32 Analog Inputs (ADC)"); Serial.println("=============================================="); Serial.print ("Potentiometer -> GPIO "); Serial.println(potPin); Serial.println("12-bit ADC: 0 = 0 V ... 4095 = 3.3 V"); Serial.println("Turn the knob and watch the value change."); Serial.println("----------------------------------------------"); } void loop() { // Read the analog value: 0 (0 V) .. 4095 (3.3 V) potValue = analogRead(potPin); // Convert the raw reading to an approximate voltage for readability float voltage = potValue * 3.3 / 4095.0; Serial.printf("Pot: %4d / 4095 (~%.2f V)\n", potValue, voltage); delay(500); }