BASIC4MCU | 아두이노 | 아두이노 | tkkrlab - Arduino 37 sensors - KY-021 Mini magnetic reed modules
페이지 정보
작성자 키트 작성일2017-09-13 14:29 조회3,429회 댓글0건본문
Arduino KY-021 Mini magnetic reed modules
MINI reed switch module
A reed module is a magnetic sensor that is normally open and get closed when exposed to a magnetic field.
In our example turn off the buildin LED on pin 13 if the sensor is closed. For this you need to keep a magnet near the sensor.
The module includes a 10 K Ohm resistor, so no additional parts needed.
Schematic
- Arduino GND --> Module pin -
- Arduino +5V --> Module PLUS (middle pin)
- Arduino Digital pin 3 --> Module S
Example Code
1234567891011121314151617181920212223 // Example code for sensor KY021// More info on http://tkkrlab.nl/wiki/Arduino_KY-021_Mini_magnetic_reed_modules//int Led = 13 ;// define LED Interfaceint buttonpin = 3; // define the Reed sensor interfacesint val ;// define numeric variables valvoid setup (){pinMode (Led, OUTPUT) ;// define LED as output interfacepinMode (buttonpin, INPUT) ;// output interface as defined Reed sensor}void loop (){val = digitalRead (buttonpin) ;// digital interface will be assigned a value of 3 to read valif (val == HIGH) // When the Reed sensor detects a signal, LED flashes{digitalWrite (Led, HIGH);}else{digitalWrite (Led, LOW);}}cs https://tkkrlab.nl/wiki/Arduino_KY-021_Mini_magnetic_reed_modules
댓글 0
조회수 3,429등록된 댓글이 없습니다.