Buried inside the original ESP32 chip is a Hall effect sensor -- a magnetic field detector that needs zero external wiring to use. It's one of the more obscure built-in peripherals on the chip, mostly because it's limited, noisy, and quietly missing on several newer ESP32 variants. It's still a genuinely fun one-line feature to know about, and occasionally useful for a quick demo.
What hallRead() Actually Measures
void setup() {
Serial.begin(115200);
}
void loop() {
int value = hallRead();
Serial.println(value);
delay(200);
}
With no magnet nearby, this prints a small, somewhat noisy baseline value. Bring a magnet close to the top of the chip and the number swings noticeably -- the direction of the swing depends on which pole faces the chip.
The important caveat: this is not a calibrated reading in Gauss or any standard magnetic unit -- it's a relative, unitless number derived from a special internal ADC reading, useful mainly for detecting a change relative to a baseline, not for measuring actual field strength.
A Real Limitation Worth Knowing First
The Hall sensor is present on the original ESP32 (and ESP32-WROOM/WROVER modules built on that chip) -- it is not present on ESP32-S2, ESP32-S3, or ESP32-C3. Code calling hallRead() on those variants may compile, but the peripheral simply isn't there, so it won't behave the same way (often returning 0 or an unreliable value). Verifying the exact chip variant before relying on this feature for anything beyond a quick original-ESP32 demo avoids a confusing dead end later.
A Simple Practical Use: A Magnetic Presence Detector
int baseline = 0;
const int THRESHOLD = 15;
void setup() {
Serial.begin(115200);
// Average a few readings with no magnet present to establish a baseline
long sum = 0;
for (int i = 0; i < 20; i++) {
sum += hallRead();
delay(50);
}
baseline = sum / 20;
Serial.println("Baseline: " + String(baseline));
}
void loop() {
int reading = hallRead();
if (abs(reading - baseline) > THRESHOLD) {
Serial.println("Magnet detected!");
}
delay(100);
}
Calibrating a baseline first, then watching for a deviation past a threshold, is the practical way to use this sensor for anything -- a magnetic lid/door sensor demo is the most common use, though the noise level makes it better suited to a demo than a production design.
Why an External Hall Sensor Module Is Usually the Better Choice
Cheap external Hall sensor modules (based on chips like the A3144 or 49E) cost very little, give a clean digital HIGH/LOW trigger with no calibration needed, and can be placed exactly where a magnet will pass, rather than being fixed to wherever the ESP32 chip itself happens to sit on the board. For anything beyond a quick built-in-feature demo, an external module on any regular GPIO pin with a simple digitalRead() is the more reliable, more flexible choice.
Common Mistakes
Expecting a calibrated reading. hallRead() returns a relative, unitless value -- not Gauss or millitesla -- so comparing raw numbers across different boards or environments isn't meaningful without your own calibration.
Assuming every ESP32 board has this feature. S2, S3, and C3 variants don't include the internal Hall sensor at all -- check the specific chip before building around this.
Using GPIO36/GPIO39 for something else at the same time. These pins are internally tied to the same ADC channels the Hall sensor reads through, so using them as ordinary analog inputs elsewhere in a sketch can conflict with hallRead().
Relying on the internal sensor for a serious project. The noise floor and lack of calibration make it a fun one-liner for a demo, not a dependable sensor for anything that needs consistent, repeatable triggering -- an external module is the better tool for that.
Where to Go Next
For a broader look at what else the ESP32 can do out of the box -- WiFi, Bluetooth, deep sleep, and more -- see the ESP32 Complete Beginner's Guide.