Esp32

ESP32 Built-In Hall Effect Sensor with Arduino IDE

ESP32 is a very diverse microcontroller board with not only having capability of WiFi and dual Bluetooth but it has some prebuilt cool features like touch sensor and hall effect sensor to collect data without any need of external hardware. Today we will be looking at ESP32 hall effect sensors inside the rectangular shape metal we can see on the ESP32 board.

ESP32 Hall Effect Sensor

ESP32 hall effect sensor can detect magnetic field. The output voltage hall sensor gives is proportional to the magnetic field strength. The output of the sensor is proportional to the change in strength of the field.

Hall effect sensors like touch pins of ESP32 can also be used as a replacement for switches and push buttons by setting a threshold value. Additionally, hall effect sensor can also be used as:

  • Detect Proximity
  • Detect door closing
  • Count wheel revolution
  • Calculate positioning

ESP32 Hall Effect Sensor Using Arduino IDE

To read value from ESP32 using Arduino IDE we will be using a simple hallRead() function. Open Arduino IDE select ESP32 board and the COM port.

Go to: File>Examples>ESP32>HallSensor

Following code will appear in the new window.

Code

The code given below can read the hall effect sensor reading using the hallRead() function.

int val = 0;   /*int variable to store input value*/
void setup() {
  Serial.begin(9600);
    }
void loop() {
  val = hallRead();   /*hall sensor reading*/
  Serial.print("sensor = ");
  Serial.println(val);   /*output printed*/
  delay(500);
}

Here in the above code we simply read the hall effect sensor value using the hallRead() function which is stored inside a variable val. To print the read value Serial.print() function is used.

Hardware

To upload and test the hall effect sensor code we need following equipment:

  • ESP32 board
  • Strong magnet
  • Micro USB cable

Connect ESP32 board with PC and upload the code given above using Arduino IDE.

Output

Once the code is uploaded, place a magnet over the ESP32 board. Hall sensor is present inside the metal rectangular box we can see on the ESP32 board just under the voltage regulator.

Following output will appear and we can see the positive reading.

Graphical user interface, text Description automatically generated

Now turn around the magnet, due to change in magnetic field, negative current will be influenced resulting in negative value of hall effect sensor.

Following the result will appear on the serial monitor here we can see that output is in negative number.

Text Description automatically generated

Conclusion

ESP32 comes with different features such as dual Bluetooth and WiFi support. However, ESP32 boards also have an internal hall effect and capacitive touch sensor available. Here in this article, we have read the hall effect input using a strong magnet. By changing magnetic fields, a change in output is observed.

About the author

Kashif

I am an Electrical Engineer. I love to write about electronics. I am passionate about writing and sharing new ideas related to emerging technologies in the field of electronics.