Hall effect sensor/How a magnet becomes LOW/04. Active low, and the light
How a magnet becomes LOW · 04 of 10

Active low, and the light

A magnet makes the chip join SIGNAL to ground, so SIGNAL reads LOW. The red LED is wired from VCC to SIGNAL, so it lights exactly then: lit means LOW means a magnet. About 3 mA from 5 V, about 1.3 mA from 3.3 V, and none of it from your board's pin.

Why LOW

Lit means LOW
VCC
The magnet
LED
about 3.00 mA
Pull-up
0.50 mA
Chip sinks
about 3.50 mA
Magnet near: the chip joins SIGNAL to GND. Now the LED has VCC on one side and 0 V on the other, and about 3.00 mA flows through it and its 1 kΩ, plus 0.50 mA through the pull-up. Your pin reads LOW, and the light says so. Lit means LOW.

The chip's output has two positions. No magnet, it connects SIGNAL to VCC. A magnet, it connects SIGNAL to ground. So the magnet is the LOW state, and a line that does its job by going LOW is called active low. The front of the board says ACTIVE LOW for that reason, and the schematic's own note says it in words: the output goes low when a magnetic field is detected.

Where the light is

The LED and its 1 kΩ resistor run from VCC to SIGNAL, not from SIGNAL to ground. With no magnet, both ends sit at VCC, there is no voltage across it, and it is dark. With a magnet, SIGNAL drops to near 0 V, the LED has the whole of VCC across it and its resistor, and it lights.

So the light means the opposite of what a first-time reader expects: lit is LOW, and LOW is the magnet. The LED and the pin agree; they just agree on LOW.

How much current

The LED is red, and a red 0805 LED drops about 2.0 V at these currents. The arithmetic below takes that figure. It is a model rather than a measurement:

LED,     from 5 V:    (5.0 V - 2.0 V) / 1 kΩ   = about 3.0 mA
LED,     from 3.3 V:  (3.3 V - 2.0 V) / 1 kΩ   = about 1.3 mA
pull-up, from 5 V:     5.0 V / 10 kΩ           =       0.5 mA

The chip's output sinks all of it while a magnet is near, about 3.5 mA from 5 V. The datasheet only states the output's low level at 0.5 mA, where it is under 0.2 V, and gives no figure at 3.5 mA. That is a gap on paper rather than a problem you are likely to see, and the check is simple: if the LED is lit and the pin reads LOW, the level is low enough.

None of that current comes from your microcontroller's pin. It flows from the block's VCC pin, through the LED, into the chip, and back out of GND. Your pin only measures the voltage.

A test that needs no code

The LED lights from the chip's output alone, so it splits a fault in two before you open the sketch:

  • Magnet near, LED lights. Power, GND and the chip are fine, and SIGNAL went LOW. If the sketch sees nothing, the fault is between SIGNAL and your code.
  • Magnet near, LED stays dark. Either the chip has no power, or the magnet is not close enough to the chip, or not face on to it.

When a magnet does nothing starts from exactly this split.

When it does not work

The LED is lit but my sketch says HIGH.

The LED is wired to SIGNAL, so if it is lit, SIGNAL is LOW at the block. The sketch is reading a different pin, the SIGNAL wire is loose, or your board and the block do not share a ground. Check the pin number first: it is the GPIO number printed beside the pin, not its place along the header.

Should I use INPUT or INPUT_PULLUP?

INPUT. The chip drives SIGNAL both ways and the board already has a 10 kΩ pull-up, so the pin needs nothing of its own. INPUT_PULLUP does no harm here, unlike on a board with a pull-down, but it adds nothing either.

Why does the block draw more current when the magnet is there?

Because that is when the LED is on. With no magnet the chip averages about 5 µA and nothing else flows. With a magnet the chip sinks the LED's current and the pull-up's, about 3.5 mA from 5 V. On a door sensor the magnet is there whenever the door is shut, so that is the current most of the time.

The LED is dimmer on my ESP32.

Normal. A red LED takes about 2.0 V before it conducts, and 3.3 V leaves about 1.3 V for its 1 kΩ resistor: roughly 1.3 mA. On a 5 V Uno the same LED gets about 3 mA.

Where this goes next

Three wires and a sketch that prints what the pin says.

The first read

Edit this page — content/books/hall-effect-sensor/active-low-and-the-light.mdx

Community

Questions about this product

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

Ask a question ↗

Hall Effect Sensor

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