HC-SR501
Jump to navigation
Jump to search
Judesio daviklis.
RaspberryPI
Kodas
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import urllib
sensor = 8
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)
previous_state = False
current_state = False
while True:
time.sleep(0.1)
previous_state = current_state
current_state = GPIO.input(sensor)
if current_state != previous_state:
new_state = "HIGH" if current_state else "LOW"
print("GPIO pin %s is %s" % (sensor, new_state))
httpresponse = urllib.urlopen ("http://xxx.xxx.xxx.xxx:8080/json.htm?type=command¶m=switchlight&idx=XX&switchcmd=On")
OrangePI
Sujungimas
Visi pinai aprašyti čia. Sujungimas:
VVC = PIN 2 OUTPUT = PIN 7 GND = PIN 6
Kodas
from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
mq135 = port.PA6
gpio.init()
gpio.setcfg(mq135, gpio.INPUT)
try:
while True:
state = gpio.input(mq135)
sleep(0.2)
print "Statusas: %d"%state
except KeyboardInterrupt:
print ("Goodbye.")