Tue. Jul 28th, 2026
#include <Arduino.h>

// Define Header Pin Numbers (GPIO)
const int POT_PIN_A = 40;  // ADC1 (Safe to use with Wi-Fi)
const int POT_PIN_B = 42;  // ADC1 (Safe to use with Wi-Fi)
const int POT_PIN_C = 14;  // ADC2 (Disabled if Wi-Fi is actively running)
const int POT_PIN_D = 17;  // ADC2 (Disabled if Wi-Fi is actively running)

void setup() {
    Serial.begin(115200);

    // 1. Configure the ADC resolution.
    // ESP32-S3 supports up to 12-bit depth, which outputs digital values from 0 to 4095.
    analogReadResolution(12);

    // 2. Configure Attenuation (Required for 0 - 3.3V measurement range)
    // By default, ESP32 ADCs only read up to ~1V. 11dB expands this to the full 3.3V scale.
    analogSetPinAttenuation(POT_PIN_A, ADC_ATTEN_DB_11);
    analogSetPinAttenuation(POT_PIN_B, ADC_ATTEN_DB_11);
    analogSetPinAttenuation(POT_PIN_C, ADC_ATTEN_DB_11);
    analogSetPinAttenuation(POT_PIN_D, ADC_ATTEN_DB_11);
}

void loop() {
    // 3. Perform the conversion using the exact same function for all pins
    int rawValueA = analogRead(POT_PIN_A);
    int rawValueB = analogRead(POT_PIN_B);
    int rawValueC = analogRead(POT_PIN_C);
    int rawValueD = analogRead(POT_PIN_D);

    // 4. Calculate actual voltage (Assuming VCC max reading drops to ~3.3V via your 10k/20k trick)
    float voltageA = (rawValueA * 3.3) / 4095.0;
    float voltageB = (rawValueB * 3.3) / 4095.0;

    // Print values out to the serial plotter/monitor
    Serial.printf("G40: %d (%.2fV) | G42: %d (%.2fV) | G14: %d | G17: %d\n", 
                  rawValueA, voltageA, rawValueB, voltageB, rawValueC, rawValueD);

    delay(200); // Sample 5 times a second
}

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *