Pro Mini: Threshold switch with hysteresis, 12 V load

by VladM

9 parts

A sketch with hysteresis switches a 12 V lamp through a MOSFET. A triangle from 0 to 10V (0.1 Hz) feeds A0 through two 10 kΩ resistors, so A0 sweeps from 0 to 5V and back every 10 s. When A0 reads above 600 (2.93V), the sketch sets D8 high and the MOSFET lights the lamp; it stays lit until A0 reads below 400 (1.95V). On the scope, the lamp comes on at about 2.94 V on the way up and goes out at about 1.95 V on the way down: on for 5.11 s and off for 4.89 s of each 10 s. Lit, the lamp draws 97 mA and the MOSFET's drain sits at 0.34 V. D8 drives the gate through 100 Ω, and the board's L LED shows the same state. The two thresholds are the hysteresis: with one threshold, an input sitting near it would switch the lamp on and off with every bit of noise.