and a little bit simplified my code.
#!/usr/bin/env python # Info - This program is for PIR sensor. Contionusly checks for state, # set LED if movement detected and plays wav file on detection. import RPi.GPIO as GPIO import time PIR = 7 # On-board pin number 7 (GPIO04) state = False val = False GPIO.setmode(GPIO.BOARD) # Change this if using GPIO numbering GPIO.setup(PIR, GPIO.IN) # Set PIR as input try: while True: val = GPIO.input(PIR) # read input value if (val == True): # check if the input is HIGH print("Hi there!") time.sleep(1) except KeyboardInterrupt: GPIO.cleanup()
I also have wiringpi library, so when i do gpio readall I see that pin 7 gets 0 or 1 dependes on sensor data. but when i run python code, it just gets 1 all the time, and prints "Hi there" all the time. Any suggestions?