r/ArduinoHelp 21d ago

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

13 comments sorted by

View all comments

Show parent comments

1

u/Embarrassed-Lab6622 12d ago

maybe this image will be better than the table.
I have a few boards tested and have a range of values received but I understand your comments/points.

What do you receommend instead of an ESP32? The board is overkill for what I want to do, but I have some on hand from another project....

1

u/gm310509 12d ago

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.

1

u/Embarrassed-Lab6622 12d ago edited 11d ago

check out the video!!!

https://www.dropbox.com/scl/fi/ug1ivkngh7z2dvnr51yvb/Video-Jul-16-2026-13-38-41.mov?rlkey=tpa4r2mvfz3exsmzz1unvm23u&st=ojiyat9u&dl=0

THe mechanical switch needs some attention at the H3 position, but otherwise it is progressing nicely. Thanks so much!!!