Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import grovepi
- # Connect the Grove Sound Sensor to analog port A1
- # SIG,NC,VCC,GND
- sound_sensor = 1
- # Connect the Grove LED to digital port D5
- # SIG,NC,VCC,GND
- led = 5
- grovepi.pinMode(sound_sensor,"INPUT")
- grovepi.pinMode(led,"OUTPUT")
- # The threshold to turn the led on 400.00 * 5 / 1024 = 1.95v
- threshold_value = 400
- while True:
- try:
- # Read the sound level
- sensor_value = grovepi.analogRead(sound_sensor)
- # If loud, illuminate LED, otherwise dim
- if sensor_value > threshold_value:
- grovepi.digitalWrite(led,1)
- else:
- grovepi.digitalWrite(led,0)
- print("sensor_value = %d" %sensor_value)
- time.sleep(1)
- except IOError:
- print ("Error")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement