自讀書時候認識磁石有南/北極...外,往後是什少再接觸其理論的,現連關於磁場方面的什麼單位也說不出了
玩過吓Arduino亦發現了有值幾豪紙的Hall-effect sensor模塊, 其對磁場有測量作用,故閑來摸了吓
選用了隻SS49E帶線性輸出的霍爾元件:
看了說明書,斗了個多小時編程如下:
/*******************************************************
49E Hall-Effect:
1.4 ~3.0mV/GS, Linear Hall-effect sensors
South : output 0.9~2.5V (-1200 ~ 0 Gauss)
North : output 2.5~4.2V (0 ~ +1200 Gauss)
Vcc 2.3~10V (6 mA at 5 Vdc)
********************************************************/
//Vcc conected to 3.3V (stabilize)
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //select the pins used on the LCD panel, pin 10 for black light control
#define Hall_Effect A1 //connect to Hall Effect sensor output pin
int Hall_Effect_normal = 0; //Hall Effect sensor quiescent output voltage
void setup() {
lcd.begin(16, 2); //Initialise the LCD
lcd.clear();
Hall_Effect_normal = analogRead(Hall_Effect); //reading the Hall Effect sensor normal output
lcd.print("ADC: ");
lcd.setCursor(0,1);
lcd.print(Hall_Effect_normal);
delay(300);
lcd.clear();
}
void loop() {
int Hall_out = analogRead(Hall_Effect); //reading the output of Hall Effect sensor
float Hall_volt = float(Hall_out) / 1023 * 5; //change to Voltage
lcd.setCursor(0,0);
lcd.print(Hall_volt);
lcd.print(" V (ADC ");
lcd.print(Hall_out);
lcd.print(") ");
lcd.setCursor(0,1);
lcd.print(" ");
if ( Hall_out > (Hall_Effect_normal +1) ){ //North: Hall_out is 1.61~2.6V (2.38~4.2V for 5V Vcc) ; "+1" is for ADC tolerance
lcd.setCursor(0,1);
lcd.print("North ");
lcd.print(map(Hall_out, Hall_Effect_normal, 530, 0, 1200)); //map to Gauss; "530" is max. of ADC reading
lcd.print(" GS ");}
if ( Hall_out < (Hall_Effect_normal -1) ){ //South: Hall_out 0.75~1.61V (0.9~2.38V for 5V Vcc)
lcd.setCursor(0,1);
lcd.print("South ");
lcd.print(map(Hall_out, 157, Hall_Effect_normal, -1200, 0)); //map to Gauss; "157" is min. of ADC reading
lcd.print(" GS ");}
delay(100);
}
測試了磁石放不同距離的結果:
感覺磁力強度與距離成非線性變化都很大, 此Sensor亦易滿度飽和,此製作並沒有較準及調試, 故只作玩具級參考吓!
幾豪紙用來淨試測磁石的南/北極以不錯了 |