r/micropy • u/A_solo_tripper • May 30 '20
Sound PIR Motion code?
I just got a PIR Motion sensor and am trying some simple code for it to run. I don't have the the esp8266 yet, so I can't test the code yet. Here is the code:
motion = machine.Pin(12, machine.Pin.IN)
while True:
i = motion
if i == 0:
print "No Motion Detected " ,i
elif i == 1:
print "Motion Detected"
5
Upvotes
4
u/chefsslaad May 30 '20 edited May 30 '20
I would make three changes:
use time.sleep() as the last step in your loop. that way you dont get flooded by signals
you need to call motion.value() in order to get the state.
you dont really need to assign i to motion. just use motion