2 · Inputs & sensors
Threshold with hysteresis
Advanced20 min
Goal
Stop the output from flickering when the reading hovers around the threshold.
Why it matters
Two thresholds (high and low) stabilise any real control loop: thermostat, night light, alarm.
Steps
- 01Define LOW_THRESHOLD and HIGH_THRESHOLD (e.g. 380 and 420).
- 02Switch on only below LOW_THRESHOLD, off only above HIGH_THRESHOLD.
- 03Remember the current state between loop iterations.
This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.
Next tutorials
- Read a push button
Light the LED only while the button is pressed.
- Toggle button (debounced)
One press turns on, the next turns off — with no contact bounce.
- Read a potentiometer
Print the analog value of A0 on the serial monitor.
- Convert to volts (map & float)
Turn the ADC's 0–1023 into a 0.00–5.00 V reading.