Articles Comments

{ Berbagi, Menulis, Dan Mengajar } Ilmu… » Raspberry » Wiring Pi .. Read Sensor Raspberry

Wiring Pi .. Read Sensor Raspberry

import wiringpi as wpi
from time import sleep

PIR_SENSOR = 1
LED_MODULE = 21

wpi.wiringPiSetup()
wpi.pinMode(PIR_SENSOR, wpi.INPUT)
wpi.pinMode(LED_MODULE, wpi.OUTPUT)

try:
while True:
if wpi.digitalRead(PIR_SENSOR) == wpi.HIGH:
print(“Moving Object Detected”)
sleep(0.5)
wpi.digitalWrite(LED_MODULE, wpi.HIGH)
else:
print(“No Object Detected”)
sleep(0.5)
wpi.digitalWrite(LED_MODULE, wpi.LOW)

except KeyboardInterrupt:
wpi.pinMode(LED_MODULE, wpi.OUTPUT)
wpi.digitalWrite(LED_MODULE, wpi.LOW)
print(“exit”)

Filed under: Raspberry

Leave a Reply

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>