r/ArduinoHelp • u/Embarrassed-Lab6622 • Jul 07 '26
Coding for resistor ladder input on ESP32
Hello. I am trying to write some code in Arduino that will read the input pin (D32) and based on the on the different voltage, the will different outputs and a timer. Is it as simple as:
if (SWITCH_INPUT == >3.0 && !timerActive) {
digitalWrite(HIGH_HEAT, HIGH); // Turn the seat heater on HIGH
previousMillis = millis(); // Save the starting timestamp of the timer
timerActive = true; // Flag that the timer is now active
}
Then repeat for each of the 6 positions of the input switch?
1
Upvotes
View all comments
Show parent comment
1
u/Embarrassed-Lab6622 Jul 15 '26 edited Jul 15 '26
Sir - so I finally got my switch to work properly. I used the below code and have a few questions.
The output in each position varied quite a bit more than I thought it would with a power supply (as opposed to the Buck converter which will be on the board eventually). Luckily the values didn't overlap so it will be easier to write the >= and <= parameters (safe range).
Finally to my questions:
The voltage remained constant to the thousands of a volt, so why the varied range of values?
And why would the values not be between 0 and 1023? UPDATE: I found an article that notes ESP32 are 12-bit so the values are non-linear and range fromn 0-4095.