jingweimo的个人博客分享 http://blog.sciencenet.cn/u/jingweimo

博文

[转载]Hall Effect Sensor with Arduino

已有 2519 次阅读 2019-3-5 11:21 |系统分类:科研笔记|文章来源:转载

How to Use a Hall Effect Sensor With Arduino 

 

 

Have you ever wanted to make a project that involved contactless sensing, for example, to detect a door closing, count the number of revolutions of a wheel, or 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. This sensor can be used to do a lot of different things. For instance, if we need to detect a door closing; 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 is placed near the hall effect sensor and 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 measured, and with a bit more math, we can detect the bike's movement speed!

How Does It Work?

The Hall effect sensor works on the principle of the Hall effect, which states that 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 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 is shown in the picture below.

Arduino Hall effect sensor working 

There are many types of Hall effect sensors, and certain types are better for certain applications. For applications where the speed of detection is not crucial, ordinary Hall effect sensors like 44E can be used. However, for applications that involve high-speed detection, like in the case of speedometers, high-frequency Hall effect sensors like US5881 or US1881 should be used. There are two main types of Hall effect sensors: latching and non-latching.

The US1881 is a latching Hall effect sensor. The sensor gives out an output HIGH (5V) voltage whenever the north pole of a magnet is brought close to it. 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 sensors that latch on to a particular state are called latched Hall effect sensors.

The US5881 is a non-latching Hall effect sensor. 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 the US5881 for my projects.

Hall effect sensors have three pins: VCC(5V), GND, and Vout(Signal). The pinout of a Hall effect sensor is as shown below:

Arduino Hall effect sensor pinout 

Making the 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 on the Arduino. The Vout or signal pin of the Hall effect sensor is connected to the 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 with the printed number is facing toward you in the diagram):

Uploading the Code and Testing the Arduino Hall Effect Sensor

After you finish hooking up the Hall effect sensor to your Arduino, you need to upload the code to the board and test it. The Arduino Hall effect sensor code can be used to detect a magnet and count the number of times it detects it. This is a very simple Arduino code that 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 that is connected to Vout detects this rising (HIGH) voltage through the function: magnet_detect. The serial monitor prints "detect" whenever a magnet is brought close to the sensor.

Arduino Hall effect sensor serial monitor


/*
Arduino Hall Effect Sensor Project
by Arvind Sanjeev
Please check out 
http://diyhacking.com for the tutorial of this project.
DIY Hacking
*/


 volatile byte half_revolutions;
 unsigned int rpm;
 unsigned long timeold;
 void setup()
 {
   Serial.begin(115200);
   attachInterrupt(0, magnet_detect, RISING);//Initialize the intterrupt pin (Arduino digital pin 2)
   half_revolutions = 0;
   rpm = 0;
   timeold = 0;
 }
 void loop() //Measure RPM
 {
   if (half_revolutions >= 20) {
     rpm = 30*1000/(millis() - timeold)*half_revolutions;
     timeold = millis();
     half_revolutions = 0;
     //Serial.println(rpm,DEC);
   }
 }
 void magnet_detect() //This function is called whenever a magnet/interrupt is detected by the arduino
 {
   half_revolutions++;
   Serial.println("detect");
 }

Hooking Up the Arduino Hall Effect Sensor to Your Project

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 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 and sirens.

Furthermore, you can also use this sensor to make a speedometer for your bike. A small magnet needs to be attached to your wheel and the Hall effect sensor can be attached to the frame of your bike. The number of rotations made by the wheel and the time taken 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 kmh or mph.


Source:

https://maker.pro/arduino/tutorial/how-to-use-a-hall-effect-sensor-with-arduino

https://www.electronicshub.org/hall-effect-sensor-with-arduino/

https://www.hackster.io/amal-ns/hall-effect-sensor-with-arduino-390916

http://www.electronics-lab.com/project/using-hall-effect-sensor-arduino/



https://wap.sciencenet.cn/blog-578676-1165772.html

上一篇:[转载]Machine Learning vs Statistical Learning
下一篇:[转载]Qt Has a Solution for All Your Timing Needs
收藏 IP: 68.83.204.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-14 20:22

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部