Skip to content

Tutorial

ESP32 Hall Sensor: hallRead(), Core 3.x Removal and External Sensor Alternatives

The ESP32's built-in Hall effect sensor needs zero wiring, but its readings aren't calibrated and the feature is missing entirely on S2/S3/C3 chips. What hallRead() actually measures, and when an external module beats it.

  • 10 min read
  • Updated November 14, 2026
ESP32 Hall Sensor: hallRead(), Core 3.x Removal and External Sensor Alternatives

The original ESP32 has a Hall effect sensor built into the chip: it reacts to a magnet with no wiring at all, and one line of code reads it. It's a fun demo, but it has two big catches that most tutorials don't mention: only the original ESP32 has it, and the hallRead() function was removed in Arduino-ESP32 core 3.x.

Quick answer: hallRead() works only on the original ESP32 (WROOM-32, WROVER, DevKit V1) with Arduino-ESP32 core 2.0.x. On core 3.x you get 'hallRead' was not declared in this scope. To use it, install core 2.0.17 in Boards Manager. It returns an uncalibrated number that changes when a strong magnet is a few millimetres from the chip. For anything real (door sensors, RPM counting, position), use an external Hall sensor such as the A3144, DRV5032 or 49E on a normal GPIO: wiring is below.

Which Boards and Versions Have It

ChipInternal Hall sensorhallRead() on core 2.0.xhallRead() on core 3.x
ESP32 (original: WROOM-32, WROVER, DevKit V1, ESP32-CAM)YesWorksRemoved: compile error
ESP32-S2No——
ESP32-S3No——
ESP32-C3, C6, H2No——

Espressif removed the Hall sensor driver from ESP-IDF 5, and Arduino-ESP32 3.x is built on ESP-IDF 5, so the function is simply gone, even on the chip that has the sensor. MicroPython's esp32.hall_sensor() disappeared from recent firmware for the same reason.

To keep using it, open Tools → Board → Boards Manager → esp32 and install version 2.0.17. Other sketches still compile, unless they use 3.x-only APIs such as ledcAttach().

Reading It

sketch.ino
// Original ESP32 + Arduino-ESP32 core 2.0.x only
void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println(hallRead());
  delay(100);
}

Open the Serial Plotter to see it as a graph. With no magnet the value hovers around a baseline (often somewhere around 0–40, different on every board) with noticeable jitter. Bring a neodymium magnet within a few millimetres of the metal shield on the module and the value jumps; flip the magnet and it moves the other way. A fridge magnet barely registers.

The number has no units. It isn't Gauss or millitesla; it's an internal ADC difference, so it's useful for "magnet near or not", not for measuring field strength.

How It Works, and Its Pin Conflict

The sensor sits inside the chip and is read through ADC1 channels 0 and 3, the same circuitry behind GPIO 36 (SENSOR_VP) and GPIO 39 (SENSOR_VN). While hallRead() runs, don't use GPIO 36 or 39 for anything else, and avoid connecting circuits to those pins, which can disturb the reading. Because it goes through the ADC, it's also noisy, and Wi-Fi activity adds to the noise.

A Magnet Detector with Baseline and Hysteresis

Because the baseline differs between boards and drifts with temperature, measure it at start-up and look for a change. Two thresholds (hysteresis) stop the output flickering when the magnet sits near the edge:

sketch.ino
// Original ESP32 + core 2.0.x
int baseline;
const int ON_DELTA  = 25;   // must change this much to count as "magnet present"
const int OFF_DELTA = 12;   // and come back within this to count as "gone"
bool magnet = false;

int averagedRead(int n) {
  long sum = 0;
  for (int i = 0; i < n; i++) { sum += hallRead(); delay(5); }
  return sum / n;
}

void setup() {
  Serial.begin(115200);
  pinMode(2, OUTPUT);                  // onboard LED on most DevKit V1 boards
  baseline = averagedRead(64);         // keep magnets away during start-up
  Serial.printf("Baseline: %d\n", baseline);
}

void loop() {
  int delta = abs(averagedRead(16) - baseline);
  if (!magnet && delta > ON_DELTA)  { magnet = true;  Serial.println("Magnet detected"); }
  if (magnet  && delta < OFF_DELTA) { magnet = false; Serial.println("Magnet removed"); }
  digitalWrite(2, magnet);
  delay(50);
}

Tune ON_DELTA and OFF_DELTA by watching the values in the Serial Plotter with your magnet at the distance you care about. Expect a working range of only a few millimetres to about a centimetre.

Better: An External Hall Sensor

External Hall sensors cost very little, work on every ESP32 and every core version, give a clean signal, and can be mounted exactly where the magnet passes. Pick by what you need:

SensorOutputSupplyBest for
A3144 (KY-003 module)Digital, switches near a south pole4.5–24 VDoor sensors, RPM and wheel counting
DRV5032Digital, very low power1.65–5.5 V (runs on 3.3 V)Battery projects
49E / SS49E (linear)Analog, centred at about half the supplyabout 3–6 VMeasuring magnet distance or field strength
Reed switchA contact that closes near a magnetNoneSimple door and window sensors

Wiring an A3144 to an ESP32

The A3144 needs at least 4.5 V, so power it from the ESP32's 5V (VIN) pin. Its output is open-collector: it only pulls to GND, so with the ESP32's internal pull-up the signal never exceeds 3.3 V and needs no level shifter.

A3144ESP32
VCC (pin 1)5V / VIN
GND (pin 2)GND
OUT (pin 3)GPIO 27 (any input pin)

KY-003 modules need one change. They add their own pull-up resistor to the module's VCC, and since the A3144 needs 5 V, that resistor would put 5 V on the ESP32 pin. Either remove the module's pull-up resistor and use the ESP32's INPUT_PULLUP, or put a divider (10 kΩ over 20 kΩ) between the module output and the GPIO. A bare A3144 with INPUT_PULLUP, as in the table, needs neither.

sketch.ino
const int HALL_PIN = 27;
volatile uint32_t pulses = 0;

void IRAM_ATTR onMagnet() { pulses++; }   // e.g. one magnet on a wheel

void setup() {
  Serial.begin(115200);
  pinMode(HALL_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(HALL_PIN), onMagnet, FALLING);
}

void loop() {
  static uint32_t last = 0;
  noInterrupts(); uint32_t count = pulses; pulses = 0; interrupts();
  Serial.printf("Magnet now: %s, pulses in the last second: %lu (%lu RPM)\n",
    digitalRead(HALL_PIN) == LOW ? "yes" : "no", (unsigned long)count, (unsigned long)count * 60);
  delay(1000);
}

Wiring a 49E linear sensor

Power it from 3.3 V and connect its output to an ADC1 pin such as GPIO 34. With no magnet it sits near half the supply (about 1.65 V); one pole pushes it up, the other down. Read it with analogReadMilliVolts(34). ADC1 pins keep working with Wi-Fi on; details in ESP32 ADC pins.

Troubleshooting

ProblemCauseFix
'hallRead' was not declared in this scopeArduino-ESP32 core 3.x, or a non-original ESP32 board selectedInstall core 2.0.17 and select an ESP32 Dev Module, or use an external sensor
Value barely changesMagnet too weak or too farUse a neodymium magnet within a few millimetres of the module
Values jump around at restADC noise, Wi-Fi activityAverage 16–64 readings; use hysteresis
Different numbers on two boardsThe sensor isn't calibratedMeasure each board's own baseline at start-up
Readings disturbedSomething connected to GPIO 36 or 39Leave those pins free while using the sensor
A3144 never triggersPowered from 3.3 V, or wrong magnet polePower from 5 V; the A3144 responds to the south pole facing its marked side
A3144 output reads HIGH alwaysNo pull-uppinMode(pin, INPUT_PULLUP)

FAQ

Does the ESP32-S3 or ESP32-C3 have a Hall sensor? No. Only the original ESP32 has the internal sensor.

Why does hallRead() give a compile error? It was removed in Arduino-ESP32 core 3.x. Use core 2.0.17, or an external sensor.

What units does hallRead() return? None. It's a relative value for detecting a change, not a measurement in Gauss or millitesla.

How close does the magnet need to be? A strong neodymium magnet within a few millimetres to about a centimetre of the module.

Can I use it as a door sensor? For a demo, yes. For a real door, an A3144, a DRV5032 or a reed switch on a GPIO is far more reliable and can sit right next to the door frame.

Related guides: ESP32 pinout · ESP32 ADC pins · ESP32 GPIO input and output · ESP32 complete beginner's guide

How to evaluate a Hall sensor in a real circuit

Treat the built-in hallRead() result as a relative signal, not a calibrated magnetic-field measurement. To compare readings fairly, keep the board in the same orientation, remove nearby magnets and steel tools, allow the board to reach a stable temperature, and record a baseline over several seconds. Then move the magnet in small steps and record the change. Repeat with the magnet flipped. If the response is inconsistent, check whether the magnet is strong enough and whether nearby metal is changing the field. A single threshold copied from another ESP32 is unlikely to work reliably because chip, board and environmental variation affect the baseline.

For an external sensor, test the electrical interface before writing application logic:

  1. Confirm the exact part number and its supply range from the manufacturer's datasheet. Breakout boards may add resistors or a regulator that the bare sensor does not have.
  2. With power removed, check the module pin labels and continuity to its components. Do not assume every three-pin board uses the same pin order.
  3. Power the sensor and measure its output with a multimeter before connecting it to an ESP32 GPIO.
  4. Confirm the output never exceeds the ESP32's 3.3 V input limit. A 5 V pull-up on a module output can damage the microcontroller.
  5. Move the magnet past the sensor and verify the output polarity and switching distance.

Choosing digital or analog output

A digital Hall switch answers a simple question: has the magnetic field crossed its operate threshold? It is usually the better choice for a door contact, wheel pulse or proximity trigger. A linear Hall sensor produces a voltage that changes with field direction and strength, making it more suitable for experiments that need a relative position signal. Neither type automatically measures distance: magnet shape, orientation, sensor sensitivity and mechanical alignment all affect the result.

For a rotating target, count pulses over a known time window and account for the number of magnets or magnetic poles. For a door, use debounce or a short stability interval so vibration near the switching point does not create repeated events. In safety-critical or unattended equipment, use a sensor and interface designed for that application rather than relying on the ESP32's undocumented internal measurement.

Continue learning

Related articles

All articles

Signal In

Built from what makers search for

The lookups piling up in SolderHub's search bar every day shape what we publish next — new component pages, board guides, and firmware notes, sent out as they go live.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.