The Physics: How a Hall Effect Sensor Works
When a current-carrying semiconductor wafer is placed in a magnetic field, the Lorentz force deflects moving electrons to one side of the material. This charge accumulation creates a measurable transverse voltage difference, known as the Hall voltage, which is directly proportional to the magnetic flux density passing perpendicular to the sensor surface.
Inside a practical IC like the Allegro A1302 or Honeywell SS49E, this microvolt-level Hall voltage is immediately amplified by an internal op-amp and temperature-compensated before reaching the output pin. This integrated design means you do not need external amplification; the chip outputs a clean, ratiometric voltage or a crisp digital logic signal depending on the specific variant you buy.
Analog vs. Digital Outputs: What You Are Actually Measuring
The most common mistake makers make when buying hall modules from Amazon or AliExpress is assuming all "hall sensors" output the same signal. They do not. You must match the sensor type to your microcontroller's input capabilities and your code's expectations.
- Analog (Linear) Sensors (e.g., SS49E, A1302, DRV5053): These output a continuous voltage proportional to the magnetic field strength. At zero magnetic field (quiescent state), the output sits at exactly half the supply voltage (Vcc/2). As a north pole approaches, the voltage rises; as a south pole approaches, it falls. You must read these with an Analog-to-Digital Converter (ADC) pin.
- Digital (Switch) Sensors (e.g., A3144, US5881): These contain an internal Schmitt trigger. They output a binary HIGH or LOW signal based on a specific magnetic threshold (Bop). They also feature built-in hysteresis (Brp) to prevent output chatter when hovering near the threshold. These connect to standard digital GPIO pins and are read via
digitalRead()or hardware interrupts.
Wiring and Pinout Guide for ESP32 and Arduino
Hall effect ICs are generally low-voltage devices, but module boards often include onboard voltage regulators or pull-up resistors. Below is the hardware specification and wiring matrix for the three most common modules found in maker kits.
| Sensor Module | Type | Supply Range (Vcc) | Output Logic | ESP32 Pin | Arduino Uno Pin |
|---|---|---|---|---|---|
| SS49E / A1302 | Analog Linear | 4.5V - 6.0V | Ratiometric 0.5V - 4.5V | GPIO 34 (ADC1) | A0 |
| A3144 | Digital Switch | 4.5V - 24.0V | Open-Drain (Active Low) | GPIO 25 (Input) | D2 |
| DRV5053 | Analog Linear | 2.5V - 5.5V | Ratiometric 0.2V - 4.8V | GPIO 35 (ADC1) | A1 |
Numbered Wiring Steps (ESP32 DevKit V1 with SS49E Analog Module):
- De-energize the breadboard: Ensure the ESP32 is disconnected from USB or external power before routing jumper wires to prevent accidental shorts on the 5V rail.
- Connect Vcc: Wire the module's VCC (or +) pin to the ESP32's
VINor5Vpin. The SS49E requires a stable 5V supply for its internal ratiometric scaling to function correctly. - Connect GND: Wire the module's GND pin to any ESP32
GNDpin. A shared ground reference is mandatory for accurate ADC readings. - Connect Signal: Wire the module's OUT (or AO) pin to ESP32
GPIO 34. GPIO 34 is an input-only pin on the ESP32 connected to the ADC1 channel, which does not conflict with the onboard WiFi radio (unlike ADC2 pins). - Verify connections: Use a multimeter in continuity mode to verify there is no short between Vcc and GND before applying power.
Output Signal Math: Converting Raw ADC to Gauss and Tesla
Reading the raw ADC value is useless for physical measurements. You must scale the raw voltage into milliTesla (mT) or Gauss. The ESP32 features a 12-bit ADC (0-4095), but its raw analogRead() function is notoriously non-linear, especially near the 0V and 3.3V rails. For accurate physics measurements, use the analogReadMilliVolts() function available in modern ESP32 Arduino cores, which applies factory-stored eFuse calibration data automatically.
The Scaling Formula (for SS49E at 5V):
- Sensitivity: 1.4 mV per Gauss (check your specific datasheet, as this varies by manufacturer).
- Quiescent Voltage (Zero Gauss): Vcc / 2 = 2500 mV.
- Unit Conversion: 1 milliTesla (mT) = 10 Gauss.
Math Equation:
Magnetic_Field_mT = ((Measured_mV - 2500.0) / 1.4) / 10.0
Here is the complete, compilable ESP32 code to read the sensor and output calibrated milliTesla values over the serial monitor:
#include <Arduino.h>
const int HALL_PIN = 34;
const float QUIESCENT_MV = 2500.0; // Vcc/2 for a 5V supply
const float SENSITIVITY_MV_GAUSS = 1.4; // SS49E typical sensitivity
void setup() {
Serial.begin(115200);
analogReadResolution(12); // Ensure 12-bit resolution (0-4095)
pinMode(HALL_PIN, INPUT);
Serial.println("Hall Effect Sensor Initialized. Calibrating zero-point...");
delay(1000);
}
void loop() {
// Read calibrated voltage directly in millivolts
int measured_mV = analogReadMilliVolts(HALL_PIN);
// Calculate Gauss
float gauss = (measured_mV - QUIESCENT_MV) / SENSITIVITY_MV_GAUSS;
// Convert to milliTesla (mT)
float mT = gauss / 10.0;
Serial.printf("Raw mV: %d | Field: %.2f mT\n", measured_mV, mT);
delay(100); // 10Hz sample rate
}
Magnetic Interference and Calibration Pitfalls
Hall sensors are exquisitely sensitive to stray magnetic fields, which can ruin your calibration and cause phantom readings. When designing an enclosure or mounting the sensor on a workbench, account for these common interference sources:
- DC-DC Buck Converters: The power inductors on step-down modules (like the LM2596 or MP1584) leak significant high-frequency magnetic flux. Keep linear hall sensors at least 3 inches away from unshielded switching power supplies.
- Ferromagnetic Workbenches: If you mount your sensor near a steel chassis or a workbench with a steel top, the metal will distort the ambient magnetic field (soft-iron distortion), pulling flux lines away from the sensor and altering your quiescent zero-point.
- High-Current Traces: According to Ampere's Law, a wire carrying 10A generates a measurable magnetic field. Do not route high-current motor power traces directly beneath the hall sensor IC on your custom PCB.
Calibration Tip: Never assume your quiescent voltage is exactly 2500 mV. Internal IC offset voltages and slight Vcc drops across breadboard wires mean your true zero-point might be 2480 mV or 2515 mV. Write a setup routine that averages 50 readings at startup with no magnets present, and store that value as your dynamic QUIESCENT_MV variable.
Frequently Asked Questions
How does a hall effect sensor work with alternating current (AC) wires?
Standard linear hall sensors can detect the alternating magnetic field generated by AC current flowing through a wire. Because the AC magnetic field reverses direction at 50Hz or 60Hz, the sensor's voltage output will oscillate above and below the quiescent Vcc/2 point at the same frequency. To measure AC current accurately, you typically pass the sensor's analog output through a software RMS (Root Mean Square) calculation or an analog envelope detector circuit before feeding it to the microcontroller.
How far away can a hall effect sensor detect a neodymium magnet?
Detection range depends entirely on the magnet's grade, volume, and the sensor's sensitivity. A standard 10mm x 3mm N52 neodymium disc magnet will trigger a highly sensitive digital switch (like the US5881, rated at 30 Gauss) from about 15mm to 20mm away. However, a weaker ceramic ferrite magnet might need to be within 3mm to register. Magnetic field strength drops off at roughly the cube of the distance (1/r³), meaning doubling the distance reduces the field strength by a factor of eight.
Why is my hall effect sensor output always maxed out at 4095 on the ESP32?
If your analogRead() is stuck at 4095 (or 3.3V), you have likely wired the sensor's Vcc to 5V, but the ESP32 GPIO pin is not 5V tolerant. While the ESP32 ADC can measure up to ~3.1V reliably before saturating, feeding it 4.5V from a 5V-powered SS49E will immediately max out the ADC and can permanently damage the silicon. To fix this, either power the SS49E from the ESP32's 3.3V pin (which shifts the quiescent output to 1.65V) or use a simple voltage divider (e.g., 10kΩ and 20kΩ resistors) on the signal line to step the 0-5V range down to 0-3.3V.
Do I need pull-up resistors for digital hall effect switches?
It depends on the IC's output stage. The ubiquitous A3144 features an open-drain output, meaning it can pull the signal line to GND (active low) but cannot drive it HIGH. You must enable the ESP32's internal pull-up resistor in code (pinMode(pin, INPUT_PULLUP)) or use an external 10kΩ resistor to Vcc. Conversely, modern sensors like the TI DRV5013 feature a push-pull output and can drive both HIGH and LOW natively, requiring no external pull-up resistors. Always verify the output topology in the manufacturer datasheet.






