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/gm310509 Jul 16 '26
No matter the board, there will be fluctuations - again that is why I suggested the range check earlier. Note that even if you tried a different ESP32, you may well find that you observed range will differ from this table. It will be similar, but probably not identical - this is just the nature of analog readings. The same will be true if you went to a different architecture such as AVR.
Also, not that you may see further variations as the seasons change due to different ambient temperatures, humidity and possibly some other factors.
All of these can be addressed by checking for a range of values defined by the expected readings and the average of the range.
It looks like your observations are not overlapping, so you should at least start with the code ranges you have identified (that table image was a bit easier to follow - assuming I did read it correctly).
Not that off should probably be defined as < the smallest value (i.e. < 500 from the code range column). Otherwise if the fluctuations gave you a 1 or 2 etc, then your off setting won't work.