Untitled
unknown
plain_text
2 years ago
747 B
5
Indexable
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # Define GPIO pin PPD42_PIN = 17 GPIO.setup(PPD42_PIN, GPIO.IN) THRESHOLD = 100 # Adjust this threshold based on testing def get_dust_data(): dust_data = 0 # Read the digital output from the PPD42 for _ in range(30): # Read for 30 seconds dust_data += GPIO.input(PPD42_PIN) time.sleep(1) return dust_data try: while True: dust_measurement = get_dust_data() if dust_measurement > THRESHOLD: print("High dust concentration detected (possible cigarette smoke)") time.sleep(10) # Wait for 10 seconds before the next measurement except KeyboardInterrupt: GPIO.cleanup()
Editor is loading...
Leave a Comment