KY 020 Joy IT
KY 020 Joy IT
KY 020 Joy IT
1 Pircture ................................................................................................................................................................ 1
2 Technical data / Short description ....................................................................................................................... 1
3 Pinout ................................................................................................................................................................... 2
4 Code example Arduino ......................................................................................................................................... 2
5 Code example Raspberry Pi ................................................................................................................................. 3
Pircture
Export: 16.06.2017 Copyright by Joy-IT - Published under CC BY-NC-SA 3.0 Page 83 of 214
KY-020 Tilt switch module
Pinout
the modules KY-011, KY-016 or KY-029 could be used as LED too for example.
void setup ()
{
pinMode (Led, OUTPUT) ; // Initialization output pin
pinMode (Sensor, INPUT) ; // Initialization sensor pin
}
void loop ()
{
val = digitalRead (Sensor) ; // The current signal at the sensor will be read
Connections Arduino:
Export: 16.06.2017 Copyright by Joy-IT - Published under CC BY-NC-SA 3.0 Page 84 of 214
KY-020 Tilt switch module
SensorTest_Arduino_withoutPullUP
GPIO.setmode(GPIO.BCM)
# The outFunction will be started after detecting of a signal (falling signal edge)
GPIO.add_event_detect(GPIO_PIN, GPIO.FALLING, callback=outFunction, bouncetime=100)
SensorTest_RPi_withoutPullUP
Export: 16.06.2017 Copyright by Joy-IT - Published under CC BY-NC-SA 3.0 Page 85 of 214