Mini Reed Switch Module (KY-021) [S045]
https://www.youtube.com/watch?v=hyJ3NYld018
*GitHub : https://github.com/rdiot/rdiot-s045.git
* Specs
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.
* Contents
- Connect
S ----- D2
Middle ----- 5V
- ----- GND
- Key Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // LCD2004
int pin = 2;
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.print("start LCD2004");
pinMode(pin,INPUT);
delay(1000);
lcd.clear();
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("S045:Mini ReadSwtich");
int val = digitalRead(pin);
lcd.setCursor(0,1);
lcd.print("val=" + (String)val + " ");
if(val==LOW)
{
lcd.setCursor(0,2);
lcd.print("detected");
}
else
{
lcd.setCursor(0,2);
lcd.print(" ");
}
}
'2) Sensor > Reed' 카테고리의 다른 글
Reed Swtich Module (KY-025) [S044] (0) | 2016.09.09 |
---|