arduino hall ky_003.docx
TRANSCRIPT
-
8/18/2019 Arduino hall KY_003.docx
1/1
Arduino KY-003 Hall magnetic sensor modulehttps://tkkrlab.nl/wiki/Arduino_KY-003_Hall_magnetic_sensor_module
Hall magnetic sensor module
The KY-003 is a magnetic switch. If no magnetic field is present, the signal line of the sensor is HIGH (3.5 !. If a magnetic
field is presented to the sensor, the signal line goes "#$, at the same time the "%& on the sensor lights 'p. The polarit of
the magnetic field is of infl'ence to the switching action. The front side of the sensor needs the opposite polarit as the )ac*
of the sensor to switch on.
In the e+ample program the led on the rd'ino (pin 3! will )e t'rned on when a magnetic field is present.
onnecting to the Arduino
in - / G&, connect to G& of the rd'ino
in (middle pin! 15 2, connect to rd'ino 15
in signal, connect to rd'ino pin 0
ower cons'mption, 3 m in rest, 4 m when switched on
!"ample code/*
KY-003 Hall magnetic switch
*/
int Led = 13 ; // define LED Interface
int SENSOR = 10 ; // define the Hall magnetic sensor interface
int val ; // define numeric variales val
void setup ()
{
pinMode (Led, OUTUT) ; // define LED as out!ut interface
pinMode (SENSOR, !NUT) ; // define the Hall magnetic sensor line as in!ut
"
void loop ()
{ val = di#italRead (SENSOR) ; // read sensor line
i$ (val == LO%) // when the Hall sensor detects a magnetic field" #rduino LED lights u!
{
di#ital%&ite (Led, '!');
"
{
di#ital%&ite (Led, LO%);
"
"