这次介绍一下霍尔传感器,
可用于开关接触,例如IPAD的保护套,盖上,IPAD就自动关闭屏幕
可用于磁悬浮,例如之前很火的悬浮盆栽就需要用到线性霍尔传感器
还有...
先看看长怎么样先吧
实验效果
BOM表
Arduino Uno * 1
线性霍尔传感器(推荐使用KY-024 ,但也可以使用S49E) *1
跳线若干
接线方式
Arduino Uno KY-024 如果用的是S49E
5V <---> + <---> +
GND <---> G <---> -
A0 <---> A0 <---> out
开源代码
例程中,使用中间值是500,但可能每个线性霍尔传感器会有所不同,请自行测试
磁铁靠近时,请观察数值变化,有分南北极的,方向不对的话,越靠近,数值越大
程序打包下载:https://u16460183.ctfile.com/fs/16460183-296053650
//Code Write by Moz for YouTube changel LogMaker360, 20-10-2015
//Code belongs to this video: https://www.youtube.com/watch?v=xMTKs240lBU
int readpin = A0;
int incoming = 0;
void setup ()
{
pinMode (readpin, INPUT) ;
//pinMode(DO, INPUT);
//pinMode (LED, OUTPUT);
Serial.begin(9600);
}
void loop ()
{
incoming = analogRead(readpin) ;
if(incoming > 500){
Serial.print("nothing detected ");
}
if(incoming < 500){
Serial.print("detecting something.");
}
Serial.println(incoming);
delay(400);
}