Rpi with Rain Detection Module 樹莓派雨滴檢測
Rpi with Rain Detection Module 樹莓派雨滴檢測
上次有朋友想要一款當室外下雨時,能夠自動開打雨傘的的工具。
1
introduction
在下雨時,雨水檢測模塊將感應到雨滴並向Raspberry Pi發送信號。在雨滴模塊上有兩根金屬線彼此靠近但不會上交叉。當雨水落在電路板上時,兩根金屬線會導通,因此兩根金屬線之間會有電壓。
也就是說當有電壓產生後,利用8591AD模塊即可實現樹莓派讀取信號的功能。我們可以用8591自帶的旋鈕來調節靈敏度。
2
What you will need
Raspberry Pi
Breadboard
Jumper wires (Male to Male, 2 red and 2 black)
Rain Detection module
PCF8591
3
Python Code
#!/usr/bin/env python
import PCF8591 as ADC
import RPi.GPIO as GPIO
import time
import math
DO = 17
GPIO.setmode(GPIO.BCM)
def setup():
ADC.setup(0x48)
GPIO.setup(DO, GPIO.IN)
def Print(x):
if x == 1:
print ""
print " ***************"
print " * Not raining *"
print " ***************"
print ""
if x == 0:
print ""
print " *************"
print " * Raining!! *"
print " *************"
print ""
def loop():
status = 1
while True:
print ADC.read(0)
tmp = GPIO.input(DO);
if tmp != status:
Print(tmp)
status = tmp
time.sleep(0.2)
if __name__ == "__main__":
try:
setup()
loop()
except KeyboardInterrupt:
pass
TAG:樹莓派的奇幻之旅 |