Arduino Hall Effect Sensor Tutorial: The Easy Way
Have you ever wanted to make a project that involved contact-less sensing. For example: to detect a door close, to count the number of revolutions of a wheel or even to make a speedometer? Then this Arduino Hall Effect sensor tutorial is for you.
This project uses a hall effect sensor to detect the presence of a magnet. Whenever a magnet moves past this sensor, it can detect it. Hence, this sort of sensor can be used to do a lot of things. For instance, if we need to detect a door close; then we simply have to attach a magnet to the door and a hall sensor to the frame of the door. Whenever the door closes, the magnet gets placed near the hall effect sensor and therefore we are able to detect that the door has been closed.
Similarly, this same principle can be used to make a speedometer for a bike or any other vehicle. If a magnet is attached to the wheel and a hall effect sensor is placed somewhere in the frame of the bike, the time taken for the wheel to complete one revolution can be achieved. Thus, using a bit more math, we can detect the speed of movement of the bike.
What are the stuff required to do this project? Hardware:
- Arduino or an arduino clone board (freeduino), or make your own custom arduino board with this tutorial.
- Hall effect sensor 44E or US5881 or US1881.
- A small magnet.
- 10K resistor.
- 9V Battery and connector.
- Connecting wires and breadboard.
How does it work?
The Hall Effect sensor works on the principle of Hall Effect. According to which, whenever a magnetic field is applied in a direction perpendicular to the flow of electric current in a conductor, a potential difference is induced. This voltage can thus be used to detect whether the sensor is in the proximity of a magnet or not. The arduino can detect this voltage change through its interrupt pin and determine whether the magnet is near the sensor or not. The basic working of the Arduino hall effect sensor can be described as shown:
There are many types of Hall Effect sensors, and depending on your project you should choose the right one. For applications in which speed of detection is not crucial, ordinary hall effect sensors like 44E can be used. However, for applications that involves high speed detection, like in the case of speedometers, high frequency hall effect sensors like US5881 or US1881 should be used. Mainly there are two types of hall effect sensors:
- Latching hall effect sensors.
- Non-latching hall effect sensors.
US1881 is a latching hall effect sensor. Here, the sensor gives out an output HIGH (5V) voltage whenever the north pole of a magnet is brought close to it. However, even when the magnet is removed the sensor still outputs a HIGH voltage and does not go LOW (0V) until the south pole of the magnet is brought close to it. These type of sensors that latches on to a particular state are called latched hall effect sensors.
US5881 is a non-latching hall effect sensor. Here, the sensor gives an output HIGH voltage whenever the north pole of a magnet is brought close to it. And, switches LOW whenever the magnet is removed. I personally prefer non-latching hall effect sensors like US5881 for my projects.
Hall effect sensors have three pins: VCC(5V), GND and Vout(Signal). The pin out of a hall effect sensor is as shown below:
Step 1: Connections for the Arduino Hall Effect Sensor
Interfacing the hall effect sensor with Arduino is really simple. The VCC of the sensor is connected to Arduino’s 5V power pin. The GND of the sensor is connected to the GND pin of Arduino. And the Vout or Signal pin of the hall effect sensor is connected to Arduino’s interrupt pin (digital pin 2). Furthermore, a 10K resistor is connected between the VCC and Vout pins of the hall effect sensor. This is done to pull the output of the hall effect sensor to 5V. The connections are done as shown below (the side having the printed number is facing towards you in the diagram):
Step 2: Uploading the code and testing the Arduino Hall Effect sensor
After you finish hooking up the hall effect sensor to arduino, you need to upload the code to the board and test it. The code which can be used to detect a magnet and count the number of times it detects it can be found here: Arduino Hall Effect Sensor code. This is a very simple arduino code which utilizes the interrupt pin 0 (digital pin 2) of the arduino.
Whenever the hall effect sensor detects a magnet, it outputs a HIGH (5V) voltage to its Vout pin. The interrupt pin of the arduino which is connected to Vout, thus detects this rising (HIGH) voltage through the function: magnet_detect. A screenshot of the serial monitor which prints “detect” whenever a magnet is brought close to the sensor.
Step 3: Hooking up the Arduino hall effect sensor to your project
Here, in order to show the applications of this project, I have installed the sensor on my door frame. I have also attached a small magnet on to my door. Thus, whenever my door closes, I can detect it. This can also be used as a burglar alarm system by hooking it up to some lights/sirens.
Furthermore, you can also use this sensor to make a speedometer for your bike. Here, a small magnet needs to be attached to your wheel and the hall effect sensor could be attached to the frame of your bike. The number of rotations made by the wheel and the time taken for doing it can be measured through the hall effect sensor. And after performing some calculations on this data, you can show the speed of your bike in Km/h or Mp/H.
Check out this video which shows the demo for the Arduino hall effect sensor project: