import RPi.GPIO as GPIO
import time
SOUND_SENSOR_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(SOUND_SENSOR_PIN, GPIO.IN)
print("Sound Sensor Test (KY-037 - Digital Output)")
try:
while True:
if GPIO.input(SOUND_SENSOR_PIN) == GPIO.LOW:
print("Sound Detected!")
else:
print("sound not detected")
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()
print("\nProgram stopped.")