The comparator · 04 of 11

H and L

The slide switch swaps the comparator's two inputs. At H, DIG is HIGH while the input is Higher than the knob; at L, while it is Lower. Same threshold, same comparison, the answer turned over. It is the one setting on the board that a sketch can also make, by testing for LOW instead of HIGH.

Six pins, two positions

H and L
Slider
Input1.40 V
Minus input
knob
Plus input
input
DIG HIGH when input is
above
Slider at H: pin 2 meets pin 1 and pin 5 meets pin 4, so the knob is on the minus input and the sensor on the plus. DIG is HIGH while the input is Higher than the knob. At 1.40 V against 1.00 V it is HIGH.

The switch is two switches in one body, moved by one slider. Its six pins sit in two rows of three. The middle pin of the top row goes to the comparator's minus input, the middle of the bottom row to its plus input. The end pins carry the knob and the input, crossed over: top row knob, input; bottom row input, knob.

A slide switch of this kind joins each middle pin to the end the slider is pushed toward. The maker's drawing does not say so in words, but that is how these are usually built, and it is the reading under which the printed letters make sense:

SliderMinus inputPlus inputDIG is HIGH while the input is
H, leftknobinputhigher than the knob
L, rightinputknoblower than the knob

What the letters mean

H and L do not mean HIGH and LOW; DIG is both, at different times. They say when DIG is HIGH: while the input is Higher than the knob, or Lower. So the letter is the question you want answered yes.

Swapping the inputs does not move the threshold. The knob sets the same voltage either way, and DIG changes at the same point; only the side that reads HIGH turns over.

Check it with the LED

You do not need a sketch to see which way it is set. The red LED lights while DIG is LOW. At H, it lights while the input is below the knob. At L, while it is above. Turn the input block one way and watch.

The same fix is always available in code: digitalRead(DIG_PIN) == LOW instead of HIGH. The switch exists so the block's own LED, and anything wired to DIG without a microcontroller, can be made to agree with you.

When it does not work

DIG is always the opposite of what I expected.

The switch is at the other letter. Slide it, or keep it and test for the other value in the sketch; either fix is fine. The LED will follow the change too, since it shows LOW.

DIG stopped changing after I moved the switch.

A slide switch can stop halfway, touching neither side. Then one comparator input is connected to nothing and DIG does what it likes. Push the slider firmly to one end until it clicks.

Which letter should I use?

Whichever makes HIGH mean the thing you care about. For an alarm that fires when a sound is loud, H: HIGH when louder. For a lamp that comes on in the dark, L: HIGH when darker. The book's light switch uses L.

Where this goes next

Why DIG needs its pull-up, and why the LED shows the opposite of DIG.

The open collector and the light

Edit this page — content/books/analog-to-digital-signal/h-and-l.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Analog to Digital Signal

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum