A hall effect sensor switch outputs a clean digital logic signal (HIGH or LOW) that toggles when an applied magnetic field crosses specific flux density thresholds. Unlike linear Hall sensors that require analog-to-digital conversion and software scaling, a digital hall switch handles the threshold comparison internally. The output is typically an open-drain or push-pull voltage stage, meaning you read it directly with a microcontroller GPIO pin using a simple digitalRead() or hardware interrupt. There is no raw-to-unit analog scaling required in your firmware; the physical unit (magnetic flux density in milliTesla) is mapped directly to a boolean state by the IC's internal comparator.

The Sensing Principle and Internal Hysteresis

When a current-carrying semiconductor is exposed to a perpendicular magnetic field, the Lorentz force deflects charge carriers, generating a transverse voltage known as the Hall voltage. In a switch IC, this microvolt-level signal is immediately amplified by an on-chip differential amplifier. The physics of the Hall Effect dictates that the voltage is proportional to the magnetic field strength, but in a switch variant, we do not measure this voltage directly.

Instead, the amplified signal feeds into a Schmitt trigger comparator, which provides built-in hysteresis. This means the magnetic field strength required to turn the switch ON ($B_{op}$) is intentionally higher than the field strength required to turn it OFF ($B_{rp}$). This hysteresis gap prevents output chatter when a magnet hovers near the threshold boundary, yielding a rock-solid digital edge even in the presence of mechanical vibration.

IC Selection and Electrical Specifications

Choosing the right IC depends on your magnet geometry, power budget, and switching speed. Unipolar switches respond to one magnetic pole (usually South), while omnipolar and latch types respond to both or require alternating poles. The classic A3144 is a staple for hobbyist tachometers, but modern ultra-low-power ICs like the TI DRV5032 are vastly superior for battery-operated ESP32 deep-sleep nodes. Below is a data-dense comparison of common hall effect switches on the market.

Table 1: Digital Hall Switch IC Specifications
Part Number Type $B_{op}$ (mT) $B_{rp}$ (mT) Supply Range (V) Output Stage
Allegro A3144 Unipolar 24.0 (Typ) 10.0 (Typ) 4.5 - 24.0 Open-Drain
TI DRV5032 Omnipolar 3.9 (Typ) 2.2 (Typ) 1.6 - 5.5 Push-Pull
Melexis MLX92211 Latch 30.0 (Typ) -30.0 (Typ) 2.7 - 24.0 Open-Drain
Silicon Labs Si7201 Unipolar 2.8 (Typ) 2.1 (Typ) 1.7 - 5.5 Push-Pull

Note: $B_{op}$ is the operate point (turn ON), and $B_{rp}$ is the release point (turn OFF). Latch types require a negative field (North pole) to release.

Wiring, Pinouts, and Signal Math

Most classic hall switches use an open-drain output. This means the IC can pull the signal line to ground (LOW), but it cannot drive it HIGH. You must provide an external pull-up resistor to your microcontroller's logic voltage. Modern ICs like the TI DRV5032 often feature push-pull outputs, eliminating the need for external resistors and saving board space.

Table 2: ESP32 to A3144 Hall Switch Wiring
A3144 Pin Function ESP32 Connection Notes
1 (VCC) Supply 3V3 or 5V A3144 needs min 4.5V; use 5V pin or a level-shifted DRV5032 for 3V3.
2 (GND) Ground GND Keep ground return path short to avoid EMI.
3 (OUT) Signal GPIO 4 Requires 10kΩ pull-up to 3V3. Avoid ESP32 strapping pins (0, 2, 12).

Output Signal Math: Raw Reading to Physical Unit

Because this is a digital switch, the raw-to-unit math is a boolean threshold mapping rather than a linear equation. The physical unit is magnetic flux density ($B$) measured in milliTesla (mT). The mapping to your microcontroller's raw digital read ($State$) is defined as:

  • ON State: $State = 0$ (Logic LOW) when $B \ge B_{op}$
  • OFF State: $State = 1$ (Logic HIGH) when $B \le B_{rp}$
  • Hysteresis Gap: $\Delta B = B_{op} - B_{rp}$

Worked Example: If you are using an A3144 ($B_{op} \approx 24$ mT, $B_{rp} \approx 10$ mT), the ESP32 reads 0 when the neodymium magnet is close enough to push the local field past 24 mT. The ESP32 will continue to read 0 even if the field drops to 15 mT. It will only read 1 when you pull the magnet away until the field drops below the 10 mT release threshold.

Interference, Calibration, and ESP32 Implementation

Common Interference Sources

Hall switches are immune to dust, oil, and light, but they are highly susceptible to magnetic and electrical interference. Stray magnetic fields from nearby BLDC motors, transformers, or high-current DC traces can falsely trigger the switch. Ferrous metals (like steel mounting screws or a steel chassis) will distort the magnetic flux lines of your magnet, effectively shifting your $B_{op}$ threshold and altering your physical air gap. EMI on long, unshielded signal wires can induce voltage spikes that mimic a digital edge; if your wire run exceeds 12 inches, add a 100nF ceramic capacitor between the signal pin and ground to form a low-pass RC filter.

Calibration: Physical vs. Software

Software calibration and scaling are entirely unnecessary for digital hall switches. You do not need to map ADC values or calculate offsets. Calibration is purely a physical process: you adjust the air gap between the magnet and the sensor face until the switching point aligns with your mechanical trigger point. Use a stronger N42 or N52 grade neodymium magnet if your mechanical constraints require a larger air gap.

ESP32 Interrupt-Driven Tachometer Code

The most common application for a hall switch is RPM measurement. Polling the pin in a loop() is unreliable at high speeds. Instead, use a hardware interrupt. The code below measures the time between pulses to calculate RPM, utilizing ESP32-safe interrupt macros.

#include <Arduino.h>

// GPIO 4 is safe for inputs (avoid strapping pins like 0, 2, 12)
const int HALL_PIN = 4; 
const float MAGNETS_PER_REV = 1.0; // Adjust if using multiple magnets

volatile unsigned long lastPulseTime = 0;
volatile unsigned long pulseInterval = 0;
volatile bool newPulse = false;

// IRAM_ATTR ensures the ISR runs from fast internal RAM
void IRAM_ATTR hallISR() {
  unsigned long currentTime = micros();
  pulseInterval = currentTime - lastPulseTime;
  lastPulseTime = currentTime;
  newPulse = true;
}

void setup() {
  Serial.begin(115200);
  
  // Configure pin with internal pull-up (if using a push-pull sensor, INPUT is fine)
  // For open-drain A3144, an external 10k resistor is still recommended for fast edges
  pinMode(HALL_PIN, INPUT_PULLUP); 
  
  // Attach interrupt on FALLING edge (switch pulls to ground when magnet is near)
  attachInterrupt(digitalPinToInterrupt(HALL_PIN), hallISR, FALLING);
  
  Serial.println("Hall Effect Tachometer Initialized.");
}

void loop() {
  if (newPulse) {
    // Disable interrupts briefly to read multi-byte volatile variables safely
    noInterrupts(); 
    unsigned long interval = pulseInterval;
    newPulse = false;
    interrupts();
    
    if (interval > 0) {
      // Calculate RPM: (60 seconds * 1,000,000 microseconds) / (interval * magnets)
      float rpm = 60000000.0 / (interval * MAGNETS_PER_REV);
      Serial.printf("RPM: %.2f | Interval: %lu us\n", rpm, interval);
    }
  }
  
  // Handle stalled motor (no pulse for > 1 second)
  if (!newPulse && (micros() - lastPulseTime > 1000000) && lastPulseTime != 0) {
    Serial.println("RPM: 0.00 | Stalled");
    lastPulseTime = 0; // Prevent repeated printing
  }
  
  delay(10); // Small yield to prevent watchdog resets
}

When deploying this on a 3.3V ESP32, remember that the A3144 requires a minimum of 4.5V on VCC. Power the A3144 from the ESP32's VIN or 5V pin, but ensure you use a voltage divider or a dedicated level shifter on the output pin if the open-drain pull-up is tied to 5V. Alternatively, bypass this headache entirely by swapping to a 3.3V-native push-pull IC like the DRV5032.