KY-002 Erschütterungs-Schalter Modul
Aus Linkerkit.de
Version vom 17. Februar 2016, 13:50 Uhr von Sensorkit wiki admin (Diskussion | Beiträge)
Inhaltsverzeichnis
Bild
Technische Daten / Kurzbeschreibung
Chipsatz: DS18B20 | Kommunikationsprotokoll: 1-Wire
9- 12Bit genaue Temperaturmessung im Meßbereich von –55°C bis +125°C
Pin-Belegung
Codebeispiel Arduino
int Led = 13 ;// define LED Interface int Shock = 10; // define the vibration sensor interface int val; // define numeric variables val void setup () { pinMode (Led, OUTPUT) ; // define LED as output interface pinMode (Shock, INPUT) ; // output interface defines vibration sensor } void loop () { val = digitalRead (Shock) ; // read digital interface is assigned a value of 3 val if (val == HIGH) // When the shock sensor detects a signal, LED flashes { digitalWrite (Led, LOW); } else { digitalWrite (Led, HIGH); } }
Codebeispiel Raspberry Pi
Programmierbeispiel in der Programmiersprache Python
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO_PIR = 24 GPIO.setup(GPIO_PIR, GPIO.IN, pull_up_down = GPIO.PUD_UP) print "KY-002 Module Test (CTRL-C = exit)" def printFunction(channel): print("Signaal gedetecteerd") GPIO.add_event_detect(GPIO_PIR, GPIO.RISING, callback=printFunction) try: while True : Current_State = GPIO.input(GPIO_PIR) except KeyboardInterrupt: GPIO.cleanup()