霍爾傳感器應用非常廣泛,本文以A3144開關型霍爾傳感器為例,介紹霍爾效應傳感器以及A3144與Arduino UNO的連接,通過紅色LED閃爍檢測其附近是否有磁場存在。項目BOM如下:
A3144霍爾傳感器 x1
Arduino UNO開發板 x1
紅色LED x1
220歐姆電阻 x1
面包板 x1
跳線 若干
A3144霍爾傳感器
霍爾傳感器(Hall Effect Sensor)是根據霍爾效應制作的一種磁場傳感器,每一側都可以檢測到一個特定的極點,具有無觸點,在開關狀態時無火花,不產生干擾,使用壽命長,靈敏度高等特點。由于它適用于晶體管邏輯,因此可以輕松地與微控制器接口,應用非常廣泛。
霍爾效應傳感器有兩種主要類型,一種提供模擬輸出,另一種提供數字輸出。A3144霍爾傳感器是Aleg MicroSystems生產的寬溫數字輸出傳感器,由電壓調整電路、反相電源保護電路、霍爾元件、溫度補償電路、微信號放大器、施密特觸發器和OC門輸出級構成,通過使用上拉電路可以將其輸出接人CMOS邏輯電路。該芯片具有尺寸小、穩定性好、靈敏度高等特點:
- 汽車級或工業應用極的穩定性和溫度特性
- 4.5V至24V工作電壓,僅需穩壓電源
- 集電極開路25mA輸出,與數字邏輯兼容
- 電池反接保護
- 可以檢測市面上絕大多數的小型永磁體
- 體積小
- 耐物理壓力
- 工作溫度范圍可達-40℃~150℃。
連接A3144與Arduino
A3144有+5VCC、GND、Signal三個引腳,如果檢測到磁體輸出將變低電平,否則輸出將保持高電平。
?
A3144與Arduino UNO開發板的連接非常簡單,只要將其信號引腳與Arduino任意數字引腳連接,就可以讀取傳感器的狀態了。
本項目的代碼如下:
const int hallPin = 2 ; // initializing a pin for the sensor output
const int ledPin = 13 ; // initializing a pin for the led. Arduino has built in led attached to pin 13
// variables will change
int hallState = 0 ; // initializing a variable for storing the status of the hall sensor.
void setup ( ) {
pinMode ( ledPin , OUTPUT ) ; // This will initialize the LED pin as an output pin :
pinMode ( hallPin , INPUT ) ; // This will initialize the hall effect sensor pin as an input pin to the Arduino :
Serial.begin( 9600 ) ;
Serial.println ("HALL SESNOR WITH ARDUINO") ;
Serial.println ("Testing the analog hall sensor module:");
}
void loop ( ) {
hallState = digitalRead ( hallPin ) ; // reading from the sensor and storing the state of the hall effect sensor :
if ( hallState == LOW ) { // Checking whether the state of the module is high or low
Serial.println ("The state of the analog hall module is high");
digitalWrite ( ledPin , HIGH ) ; // turn on the LED if he state of the module is high
}
else {
digitalWrite ( ledPin , LOW ) ; // otherwise turn off the LED :
Serial.println ("The state of the analog hall module is low ") ;
}
?
將這些代碼上傳到Arduino IDE后,就可以讀取傳感器的狀態數據了。磁體靠近A3144霍爾傳感器,LED將點亮,離開后將熄滅。也可將LED換成蜂鳴器,磁體靠近A3144霍爾傳感器,蜂鳴器將鳴響,離開后將靜默。
審核編輯:湯梓紅
-
接口
+關注
關注
33文章
8691瀏覽量
151911 -
霍爾傳感器
+關注
關注
27文章
728瀏覽量
63377 -
Arduino
+關注
關注
188文章
6477瀏覽量
187816
發布評論請先 登錄
相關推薦
評論