The ESP32 features a built-in Hall effect sensor, which allows it to measure magnetic fields without any external components. Previously, reading the Hall sensor was straightforward using the hallRead() function. However, in recent ESP32 board definitions, hallRead() has been deprecated, leaving many developers wondering how to still access the Hall sensor values.
In this article, we will explore how you can still use the deprecated ESP32 hallRead() function in the Arduino IDE!
The Hall Sensor of the ESP32
The ESP32 came with a built-in Hall effect sensor to measure the presence of a magnetic field. It works by measuring a difference in potential caused by the Lorentz force. I will cover more of the physics behind that effect later in this post.
If you buy a brand-new ESP32 it might not have that built-in sensor anymore, as Espressif decided to end the support for the Hall sensor. However, most ESP32 boards still have that sensor and can still make use of it with a small workaround that I will cover in this post.
Why was ESP32 hallRead() Deprecated?
Espressif, the makers of the ESP32, have discontinued the Hall effect sensor in version 3.0.0 of the ESP32 Arduino core. While they didn’t give any explanation for their decision, we can think of some possible reasons.
The most popular theory is that the ESP32 built-in Hall sensor was never working properly. The values it read were far from accurate. Basically, it was just useful for detecting whether there is a magnetic field present, and not how strong it is, how it is oriented, etc.
How to Still Use ESP32 hallRead()
Even though the hallRead() function is deprecated, there’s a small workaround in the Arduino IDE that still allows us to make use of the Hall effect sensor of the ESP32.
Check out how to install the ESP32 in the Arduino IDE here.
We simply need to downgrade the ESP32 boards manager to version 2.0.17 or lower, as hallRead() was discontinued in version 3.0.0.
To do so, click on Tools > Board > Boards Manager…, search for the esp32 boards manager by Espressif Systems, and install version 2.0.17.
ESP32 hallRead() Hall Sensor Sketch
Using the hallRead() function, reading the hall sensor value is very easy using the following example sketch:
void setup() {
Serial.begin(115200);
}
void loop() {
int hallValue = hallRead();
Serial.println(hallValue);
delay(1000);
}
This sketch will print the Hall sensor value to the serial monitor every second.
How Does a Hall Sensor Work?
A Hall effect sensor detects magnetic fields using the Hall effect principle.
When an electrical current flows through a conductor and a perpendicular magnetic field is applied, a potential difference (Hall voltage) is generated across the conductor. This voltage is proportional to the strength of the magnetic field.
The difference in electrical potential (voltage) is caused by the Lorentz force pushing the negatively charged electrons to one side of the conductor.
Wrapping Up
Espressif deprecated the built-in Hall effect sensor of the ESP32 because, apparently, it was never working properly. However, there is still a way to use it by downgrading your ESP32 board definition in the Arduino IDE.
Nonetheless, if you want a more future-proof and more precise solution, switching to an external Hall sensor is recommended.
Also, check out how to get real-time push notifications with sensor readings to your phone using Telegram!
Do you have any questions? Share them in the comments below!
Thanks for reading!
Links marked with an asterisk (*) are affiliate links which means we may receive a commission for purchases made through these links at no extra cost to you. Read more on our Affiliate Disclosure Page.