The Sensing Principle: How Hall Effect Sensors Work
When an electrical current flows through a semiconductor material (like indium antimonide or gallium arsenide) and a magnetic field is applied perpendicular to that current, the Lorentz force deflects the moving electrons to one side of the material. This charge accumulation creates a measurable transverse voltage difference known as the Hall voltage. The strength of this voltage is directly proportional to the magnetic flux density passing through the sensor.
In practical microcontroller projects, the raw microvolt-level Hall voltage is too small to read directly. Modern linear Hall effect sensor ICs, such as the Texas Instruments DRV5055 or Honeywell SS49E, integrate the Hall element with an on-chip amplifier and temperature compensation circuitry. This outputs a clean, scaled analog voltage or a digital logic signal that a microcontroller can easily process to measure proximity, position, or current.
Wiring Pinouts and Output Signal Types
A common mistake on the bench is conflating analog linear sensors with digital switch sensors. They look identical (often in the same TO-92 package) but output fundamentally different signals. Analog sensors output a continuous voltage proportional to the magnetic field strength, while digital sensors use an internal Schmitt trigger to output a binary HIGH/LOW signal (often via an open-drain transistor) when a specific magnetic threshold is crossed.
| Part Number | Type | Supply Range (VCC) | Output Signal | Quiescent State | Sensitivity |
|---|---|---|---|---|---|
| TI DRV5055A1 | Linear (Analog) | 2.5V to 5.5V | Ratiometric Analog Voltage | 0.5 × VCC | 10 mV/mT (1 mV/G) |
| Honeywell SS49E | Linear (Analog) | 2.7V to 6.5V | Ratiometric Analog Voltage | 0.5 × VCC | ~1.4 mV/G (at 5V) |
| Allegro A3144 | Switch (Digital) | 4.5V to 24V | Open-Drain Digital (LOW on magnet) | Floats HIGH (needs pull-up) | N/A (Threshold: ~300G) |
Standard Linear Wiring (DRV5055 / SS49E):
- Pin 1 (VCC): Connect to ESP32 3V3 pin.
- Pin 2 (GND): Connect to ESP32 GND.
- Pin 3 (OUT): Connect to an ADC-capable GPIO (e.g., GPIO 34 on ESP32 DevKit V1).
Raw-to-Unit Math: Converting ADC Readings to Gauss
To turn a raw ADC reading into a physical magnetic flux density unit (Gauss or milli-Tesla), you must account for the sensor's quiescent voltage (the output when no magnet is present) and its sensitivity. We will use the TI DRV5055A1 powered at 3.3V as our reference.
At 3.3V VCC, the quiescent output is exactly half the supply: 1.65V (1650 mV). The DRV5055A1 has a sensitivity of 10 mV/mT. Since 1 milli-Tesla (mT) equals 10 Gauss, the sensitivity is exactly 1 mV per Gauss. A south pole will increase the voltage above 1650 mV, and a north pole will decrease it below 1650 mV.
On the ESP32, the standard analogRead() function is notoriously non-linear at the extremes of the 0-3.3V range. Instead of manual voltage division math, use the analogReadMilliVolts() function (available in Arduino ESP32 core v2.x and v3.x). This function reads the raw ADC value and applies the factory-calibrated eFuse data stored on your specific ESP32 chip to return a highly accurate millivolt reading.
// Pin definitions
const int HALL_PIN = 34; // ADC1_CH6 on ESP32 DevKit V1
const int QUIESCENT_MV = 1650; // 1.65V zero-point at 3.3V supply
const float SENSITIVITY_MV_PER_GAUSS = 1.0; // DRV5055A1 spec
void setup() {
Serial.begin(115200);
analogReadResolution(12); // Ensure 12-bit resolution (0-4095)
}
void loop() {
// Read calibrated millivolts directly from ESP32 eFuse data
int voltage_mV = analogReadMilliVolts(HALL_PIN);
// Calculate delta from zero-field quiescent point
int delta_mV = voltage_mV - QUIESCENT_MV;
// Convert to Gauss (1 mV = 1 Gauss for DRV5055A1)
float gauss = delta_mV / SENSITIVITY_MV_PER_GAUSS;
// Convert to milli-Tesla (10 Gauss = 1 mT)
float mT = gauss / 10.0;
Serial.printf("Voltage: %d mV | Field: %.2f Gauss (%.2f mT)\n", voltage_mV, gauss, mT);
delay(250);
}
Magnetic Interference and Calibration Pitfalls
If your sensor readings are noisy or offset from zero, you are likely dealing with environmental magnetic interference or thermal drift. Hall effect ICs are highly sensitive to local fields generated by mundane objects on your workbench.
Common Interference Sources:
- Ferromagnetic Metals: Steel bench frames, iron-core transformers, or even the steel casing of a nearby USB hub will distort the Earth's magnetic field and create a localized offset.
- PCB Current Traces: According to Ampere's law, any current-carrying trace on your PCB generates a concentric magnetic field. If you are measuring high currents, routing a 5A trace directly under the Hall sensor will induce massive errors.
- Temperature Drift: While modern ICs have internal compensation, extreme temperature swings (e.g., moving a sensor from a 20°C lab to a 60°C outdoor enclosure) will shift the quiescent voltage by several millivolts, translating to a phantom 5-10 Gauss reading.
Calibration Procedure:
- Isolate: Remove all neodymium magnets and ferrous tools from a 12-inch radius around the sensor.
- Sample Quiescent: In your
setup()loop, take 64 rapid ADC readings and average them to establish a dynamicQUIESCENT_MVbaseline rather than hardcoding 1650. This accounts for minor VCC ripple and ambient temperature. - Verify Polarity: Bring a marked neodymium magnet close. If the voltage drops instead of rises, flip your math logic or the physical orientation of the sensor, as the DRV5055 outputs differential voltages based on North vs. South pole orientation.
Frequently Asked Questions
Can I use a linear Hall effect sensor to measure AC current?
Yes, but not by passing the AC wire directly through the sensor. You must use a magnetic concentrator (like a split ferrite core) with an air gap, and mount the Hall sensor inside that gap. The AC current generates an alternating magnetic field in the core, which the sensor reads. For high-resolution AC current measurement, dedicated current sensor ICs like the ACS712 or isolated Hall modules like the Allegro ACS724 are preferred because they integrate the conductor and magnetic core into a single package, eliminating external interference.
Why is my ESP32 Hall effect sensor reading fluctuating wildly?
The ESP32's internal ADC is susceptible to noise, especially on pins shared with the internal WiFi/Bluetooth RF circuitry. If you are seeing ±20 Gauss jitter, first ensure you are using an ADC1 pin (GPIO 32-39) rather than an ADC2 pin, as ADC2 is disabled or highly erratic when WiFi is active. Second, add a 100nF ceramic decoupling capacitor directly across the VCC and GND pins of the Hall sensor, and a 10µF electrolytic capacitor on the breadboard power rails to filter out high-frequency switching noise from the ESP32's onboard 5V-to-3.3V LDO regulator.
What is the difference between a Hall effect sensor and a reed switch?
A reed switch is a mechanical device containing two ferromagnetic metal reeds sealed in a glass tube; a magnetic field pulls them together to close a circuit. It draws zero standby current but suffers from mechanical bounce, limited lifespan (usually ~10^6 cycles), and slow switching speeds. A Hall effect sensor is solid-state, has an infinite operational lifespan, outputs analog field strength data (not just binary on/off), and can switch in microseconds. However, Hall sensors require continuous power (drawing 2mA to 10mA quiescent current), making reed switches better for ultra-low-power battery applications like door alarms.
How close does the magnet need to be to the Hall effect sensor?
Magnetic flux density follows an inverse-cube law relative to distance from a dipole magnet. This means if you double the distance between a neodymium magnet and the sensor, the magnetic field strength drops to 1/8th, not 1/2. For a standard 10mm x 3mm N52 neodymium disc magnet, you will typically see a strong, easily readable signal (over 100 Gauss) within 5mm to 15mm. Beyond 30mm, the field strength drops below the noise floor of most hobbyist ADC setups. Always mount the sensor as close to the target magnet as physically possible without risking mechanical collision.






