Hi there! In this tutorial, you will learn how to use a Hall Effect sensor, how it works, and understand how it can be implemented in future projects and the best way to implement it. What type of sensor is this? What can I do with this sensor? Why should I use it instead of others? These questions will be answered soon, just for you. Stay tuned!!
Parts Required
Hall Effect Sensor
So, a Hall Effect Sensor is a type of sensor that is able to detect the magnetic field and its intensity, to take magnetic field measurements.
It is widely used, for example for detecting the presence of magnetized objects, the position of camshafts in combustion engines, fluid velocities, and induction factors, among others. All of those measurements are performed remotely without the need for physical contact at the same time they are immune to dust and noise. How is that possible and what’s behind it?
There are various types of Hall Sensors, however, ours is an omnipolar sensor, then which means it works with any pole of the magnetic field. To work, a current is applied to the thin strip of metal. In the presence of a magnetic field perpendicular to the direction of the current, the charge carriers are deflected, producing a difference in voltage between the two sides of the strip. This voltage difference (the Hall voltage) is proportional to the strength of the magnetic field. Figure 2, can show a simple Hall diagram. You can integrate this into a home alarm, to detect if someone opened the door.
Hall effect sensors respond to static magnetic fields. This is a key difference from inductive sensors, which respond only to changes in fields.
For this one was chosen “49E 920BD Hall sensor” coupled to a board with some capabilities. This board is pretty simple and offers an easy way to work with it. Includes an integrated circuit responsible to compare the on-time values of the magnetic field with a programable threshold. This threshold can be adjusted within the onboard blue potentiometer, so like other boards when the magnetic field is above a certain value a digital output is activated. Also, an analog output is present, directly connected to an output terminal of the sensor.
Circuit
Follow Figure 3 to obtain the wiring necessary for this setup. Since this is an easy work sensor just connect the board DO to NodeMCU D7 and the analog A0 to NodeMCU A0. The NodeMCU will power the Sensor board with 3.3V.
Code
The code below will read the Hall voltage directly from the sensor, process it, and print it on the serial monitor to have a notion of the value that we want to apply for our threshold. The digital input is going to be read to know the state of the threshold. Just copy the code below to Arduino IDE and upload it to your ESP, Have fun!!!
//Read the Analog input
//Read the digital input
//Print the Hall measurements in serial monitor
//It only show values between 0 1024 because they are the adc min/max
//For high magnetic presence the values will be higher and higher
int Hall_pin= A0;
int Thresold_Pin = 13; //D7 GPIO13
int BuiltIn_LED = 16; //D0 GPIO 16
void setup() {
pinMode(Thresold_Pin, INPUT);
pinMode(BuiltIn_LED, INPUT);
Serial.begin(9600);
}
void loop() {
//Function analogRead + digitalRead will be used to read the pin state//
int analogVal = analogRead(Hall_pin);
int digitalVal = digitalRead(Thresold_Pin);
if (Thresold_Pin)
digitalWrite BuiltIn_LED = HIGH;
else
digitalWrite BuiltIn_LED = LOW;
Serial.print(analogVal);
Serial.print("\t");
Serial.println(digitalVal);
Serial.print("\t");
delay(100);
}
References
[1] https://electronoobs.com/eng_arduino_tut82.php
[2 ]https://en.wikipedia.org/wiki/Hall_effect_sensor
[3] https://p.globalsources.com/IMAGES/PDT/SPEC/440/K1139513440.pdf
[4] https://diyi0t.com/hall-sensor-tutorial-for-arduino-and-esp8266/