最新消息:

Rain Detection Module 树莓派雨滴检测

Raspberry Pi 少儿编程 2340浏览 0评论
上次有朋友想要一款当室外下雨时,能够自动开打雨伞的的工具。

1Introduction

Rain Detection Module 树莓派雨滴检测

在下雨时,雨水检测模块将感应到雨滴并向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

Rain Detection Module 树莓派雨滴检测

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(0×48)
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

您必须 登录 才能发表评论!