Hall sensors are solid-state magnetic transducers that convert the presence, proximity, or strength of a magnetic field into an electrical signal. Depending on the specific IC inside the plastic package, that output signal is either a continuous analog voltage proportional to the magnetic flux density, or a binary digital logic state (HIGH/LOW) that triggers when a specific magnetic threshold is crossed.
The Physics: How Hall Effect Sensing Works
When an electrical current flows through a semiconductor material (like gallium arsenide or indium antimonide), the charge carriers move in a straight line. If you introduce a magnetic field perpendicular to that current flow, the Lorentz force deflects the electrons toward one edge of the material. This charge accumulation creates a measurable transverse voltage across the semiconductor, known as the Hall voltage. This principle, discovered by Edwin Hall in 1879, allows us to measure magnetic fields without any moving mechanical parts or physical contact (All About Circuits).
In modern ICs, this microvolt-level Hall voltage is immediately amplified by internal operational amplifiers and temperature-compensated before it ever reaches the output pin. Because the semiconductor element is entirely encapsulated in epoxy or plastic, hall sensors can detect magnetic fields through non-ferrous barriers like aluminum housings, water, or dirt, making them vastly superior to mechanical switches in harsh environments.
Analog vs. Digital: Knowing Your Output Type
A common mistake in embedded projects is conflating analog and digital hall sensors. They look identical on the outside (often the same TO-92 or SOT-23-3 package), but their internal circuitry and microcontroller interfacing requirements are entirely different.
| Feature | Analog (e.g., SS49E, DRV5053) | Digital Switch (e.g., A3144, US5881) |
|---|---|---|
| Output Signal | Continuous voltage (e.g., 0.5V to 4.5V) | Binary (Open-drain LOW or Push-pull HIGH/LOW) |
| Microcontroller Pin | ADC (Analog-to-Digital Converter) | Standard GPIO (Digital Input) |
| Quiescent State (No Magnet) | Outputs exactly VCC / 2 | Outputs HIGH (with pull-up) or LOW (latch) |
| Best Use Case | Measuring distance, thickness, or linear position | RPM counting, limit switches, BLDC commutation |
INPUT_PULLUP) or use an external 10kΩ resistor to VCC.
Wiring and Interfacing the SS49E to an ESP32
For this guide, we will interface the Honeywell SS49E, a highly reliable linear analog hall sensor. The SS49E operates from 2.7V to 6.5V, meaning we can power it directly from the ESP32's 3.3V rail. This keeps the output voltage safely within the ESP32's 0-3.3V ADC range without needing a voltage divider.
Wiring Table
| SS49E Pin | ESP32 DevKit Pin | Notes |
|---|---|---|
| 1 (VCC) | 3V3 | Supply range: 2.7V - 6.5V. Use 3.3V for direct ADC compatibility. |
| 2 (GND) | GND | Common ground. Keep return path short to avoid noise. |
| 3 (OUT) | GPIO 34 | ADC1_CH6. GPIO 34 is input-only and lacks internal pull-ups, making it ideal for clean analog reads. |
Output Signal Math: Raw ADC to Gauss
The ESP32's 12-bit ADC returns raw values from 0 to 4095. However, the ESP32 ADC is notoriously non-linear at the extreme ends (below 0.1V and above 3.1V). To bypass raw ADC non-linearity, use the ESP-IDF calibrated function analogReadMilliVolts(), which utilizes factory-stored eFuse calibration data to return a highly accurate millivolt reading (Espressif Docs).
The Math:
1. Quiescent Voltage: At 3.3V VCC, the zero-field output is VCC / 2 = 1650 mV.
2. Sensitivity: The SS49E datasheet states a sensitivity of 1.4 mV/Gauss at 5.0V. Because the output is ratiometric, sensitivity scales linearly with supply voltage. At 3.3V, sensitivity is: 1.4 * (3.3 / 5.0) = 0.924 mV/Gauss.
3. Conversion Formula:
int raw_mV = analogReadMilliVolts(34);
float gauss = (raw_mV - 1650.0) / 0.924;
// Positive Gauss = South pole facing flat side
// Negative Gauss = North pole facing flat side
Interference, Calibration, and Real-World Gotchas
Hall sensors are incredibly useful, but they are highly susceptible to environmental noise. If your readings are jittery or drifting, you are likely falling victim to one of these three interference sources:
- Electromagnetic Interference (EMI): If you are using a hall sensor to measure current or motor RPM, the PWM switching from nearby motor drivers will induce high-frequency noise in the sensor's high-impedance analog output trace. Fix: Add a 100nF ceramic decoupling capacitor directly across the sensor's VCC and GND pins, and place a 100Ω series resistor on the signal line right before the ESP32 GPIO to form a low-pass RC filter.
- Temperature Drift: Semiconductor sensitivity shifts with temperature. While modern ICs have internal compensation, extreme ambient shifts (e.g., moving from a 20°C bench to a 60°C enclosure) will shift the quiescent zero-point. Fix: Record the zero-field ADC offset in your code's
setup()routine on boot, rather than hardcoding 1650 mV. - Ferrous Chassis Distortion: Magnetic flux lines take the path of least resistance. If you mount a hall sensor on a steel bracket, the bracket will bend the flux lines away from the sensor element, drastically reducing sensitivity and creating non-linear dead zones. Fix: Always mount hall sensors on non-magnetic materials like aluminum, brass, or ABS plastic.
Frequently Asked Questions
What are hall sensors used for in brushless motors?
In Brushless DC (BLDC) motors, hall sensors are embedded in the stator to detect the physical position of the rotor's permanent magnets. The motor controller reads these digital signals to determine the exact moment to commutate (switch) the current to the next stator coil. Without them, the controller would have to rely on "sensorless" back-EMF detection, which struggles at low RPMs and requires the motor to be spinning before it can synchronize.
What are hall sensors vs reed switches for RPM counting?
While both detect magnets, reed switches rely on physical metal contacts that close inside a glass tube. Reed switches suffer from mechanical bounce (requiring software debouncing), have a maximum switching frequency of around 500 Hz, and will eventually wear out. Hall sensors are solid-state, have zero contact bounce, can switch at frequencies well over 100 kHz, and have an infinite operational lifespan. For any RPM counting above a few hundred RPM, a digital hall sensor is the mandatory choice.
What are hall sensors doing when they output exactly half the supply voltage?
When an analog hall sensor outputs exactly VCC/2 (e.g., 1.65V on a 3.3V supply, or 2.5V on a 5V supply), it is in its quiescent state. This means it is detecting a net magnetic field of zero Gauss. The internal amplifier is biased to the midpoint of its rail so that it can swing upward when detecting a South magnetic pole, and swing downward when detecting a North magnetic pole. If you read exactly half your supply voltage, your wiring is correct, but your magnet is either too far away or oriented parallel to the sensor face rather than perpendicular.






