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 08 '26
This probably isn't going to work as you expect. You should probably re read my comment above about analogRead and what it normally returns.
Why won't this work as you expect?
Because a digitalRead is (normally) only ever going to return a HIGH or LOW. HIGH = 1 and LOW = 0.
So, the above statement won't for for several reasons:
>=not== >which is sort of like spelling "wrong" as "dsfji" - nobody will understand what that made up word means.There may be other issues, but there are already so many issues, I will stop there.
I would suggest that you set this aside for a bit and learn the basics. If you have a starter kit, learn the basics of buttons, leds and variable resistances/voltage dividers (which I think is what it is that you might be trying to use) as well as my previous comment.
If you don't have a starter kit, have a look at the buttons, led and potentiometer example (analog) example programs and circuits here: https://docs.arduino.cc/built-in-examples/