Skip to content

Commit aff5afa

Browse files
Rafael Koch PeresRafael Koch Peres
Rafael Koch Peres
authored and
Rafael Koch Peres
committed
Added tutorial for vibration sensor.
1 parent efe97be commit aff5afa

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

sensor-vibration/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Sensor KY-002: Vibration sensor
2+
3+
![ky002](images/ky002.jpg)
4+
5+
The pins for the extension board, where (`sensor: board`) - following the [example code](vibration.py):
6+
* -: G
7+
* (middle pin): V
8+
* S: D15

sensor-vibration/images/ky002.jpg

1.03 MB
Loading

sensor-vibration/vibration.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
read state from vibration sensor using callback functions
3+
4+
"""
5+
import RPi.GPIO as GPIO
6+
import time
7+
8+
vibPin = 15 # S connected to D15
9+
10+
GPIO.setwarnings(False)
11+
GPIO.setmode(GPIO.BCM)
12+
GPIO.setup(vibPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
13+
14+
lastState = GPIO.input(vibPin)
15+
16+
def eventVibration(e):
17+
print("Vibrated!")
18+
19+
GPIO.add_event_detect(vibPin, GPIO.RISING, bouncetime = 200, callback = eventVibration)
20+
21+
while(True):
22+
time.sleep(0.1)
23+
#print(GPIO.input(vibPin))

0 commit comments

Comments
 (0)