Skip to content
If this is your first visit, please click here to learn about shipping and delivery.
If this is your first visit, please touch here to learn about shipping and delivery.
US5881 through-hole Hall effect switch with three leads

Building a Magnetic Position Switch: Hall Sensor Polarity, Pull-Ups and Mounting

A magnet and a Hall switch can indicate when a drawer, model carriage or removable panel reaches a position without making electrical contact across the moving gap. The electronic circuit can be simple, but reliable operation depends on the magnet's orientation and the geometry of the complete assembly.

The US5881 Hall effect sensors from PMD Way are an example of a digital magnetic switch. They are different from an optical slot sensor and from an analogue magnetic-field sensor. This guide uses a low-voltage position-indicator project as its example, not a safety interlock.

Identify the kind of magnetic response

A unipolar switch responds to a specified magnetic polarity. An omnipolar switch can respond to either polarity under its documented conditions. A latch has different operate and release behaviour, commonly requiring the opposite field polarity to change state. These differences matter when the magnet simply approaches and withdraws.

Melexis identifies the US5881 as a unipolar switch with an open-drain output. Its package options also have different specified active polarities. Confirm the exact package, viewing direction and part identity before choosing which magnet face points towards it.

Allegro's Hall latch explanation is a useful comparison. Replacing a switch with a latch can change what happens after the magnet moves away, even if the components look similar.

Check the supply and output separately

The Melexis US5881 datasheet specifies a 3.5–24 V operating supply range for the documented device. A 3.3 V supply therefore falls below that stated range. Verify the actual supplied part and revision rather than treating every three-pin Hall device as a 3.3 V component.

An open-drain output pulls low when active and needs a pull-up to establish a high level when inactive. Choose the pull-up rail for the receiving logic, within the sensor's output limits, and provide the documented common ground. Do not assume the output must be pulled up to the sensor's supply voltage.

For a short, slow position-input example, a 10 kΩ pull-up to 3.3 V would draw approximately 0.33 mA when pulled near ground. This calculation is illustrative. Check the receiving input thresholds, output low voltage, leakage and cable capacitance before accepting a resistor value.

Use the package drawing for pin order. A familiar flat face is not enough to establish the connections. Include the manufacturer's recommended local supply decoupling and inspect the unpowered wiring before connecting the controller.

Prove polarity on a stationary bench fixture

Mount the sensor so it cannot rotate while being tested. Mark the face and orientation shown by its datasheet. Use a small magnet held in a non-magnetic carrier, and bring it towards the intended sensing area without striking the package.

Observe the electrical output or a correctly driven indicator. If there is no change, withdraw the magnet and reverse its orientation before assuming the sensor is faulty. Also verify supply voltage, pull-up connection and input reading independently.

Once the correct orientation works, mark the magnet carrier. This local marking is enough for repeatable assembly even if you do not have an instrument for identifying the magnet's north and south poles. Keep loose small magnets controlled, particularly in educational settings.

Measure operate and release positions

Move the magnet slowly towards the sensor and record where the output activates. Then withdraw it and record where the output releases. Repeat several times with the same approach path.

These positions need not be identical. Allegro's Hall sensor applications guide explains operate and release thresholds and magnetic hysteresis. The sensor responds to magnetic flux at its active region, so a switching threshold in the datasheet does not directly specify a universal detection distance.

Magnet dimensions, material, orientation and nearby steel all influence the field. Do not promise a particular gap based only on the magnet's advertised pull force. A magnet that strongly attracts a steel plate does not necessarily produce the desired switching margin in your geometry.

Record the installed magnetic switch as a system
Test What to record
Normal approach Activation position and spread over repeated trials.
Withdrawal Release position and whether it returns reliably.
Lateral offset Behaviour at the expected mounting tolerance.
Final hardware Effect of brackets, screws and enclosure parts.
Electrical operation Behaviour while nearby motors or other loads run.

Give the two mechanical states useful margin

Arrange the “present” position comfortably inside the reliably active region, and the “absent” position clearly beyond the reliably released region. Avoid making normal operation depend on hovering at the exact transition point.

Include tolerance in both directions. A removable panel may seat slightly differently each time, and adhesive or plastic parts can move with age. A test at the nominal gap alone does not establish that every assembled unit will behave the same way.

Secure the magnet mechanically for the application. If it can rotate in its recess, a previously correct polarity may become wrong. Protect the sensor leads from repeated bending and provide a cable route that remains clear of the moving mechanism.

Interpret the signal honestly in software

Name the raw state separately from its application meaning. “Hall output low” might mean “magnet detected”; it does not by itself prove that a lid is latched or a carriage is mechanically secure. The magnet can be present while another part of the mechanism is misaligned.

For a slowly moving model, a short stable-state confirmation interval may reject brief disturbances. Choose it from the required response and observed transitions. Do not use a long software delay to hide an inadequate magnetic margin.

Consider faults as well. A disconnected signal wire can look like an inactive open-drain output if the controller's pull-up holds it high. A basic three-wire arrangement does not automatically distinguish every wiring failure from an ordinary absent magnet.

Validate the final assembly

Repeat the movement with all normal fixings fitted and the project's other electronics running. Test startup with the magnet both present and absent. Keep the final mounting photograph and transition measurements with the project.

The Hall effect sensor collection offers different physical approaches. Choose the response type and interface first, then design the magnet and mounting around the required position window. Dependable detection comes from the complete arrangement, not from the sensor alone.

Previous article Battery Power for Arduino Projects: Voltage Range, Runtime and Regulator Heat