For my daughter's science fair project (Computer Science and Math category), she'd like to use the RPi to go around and measure whether different loud sounds are above the threshold of pain and are damaging our ears. She's a 6th grader, but she has experience with RPi and programming in Python. Phillip Heels Nichols has answered some questions on the FB RPi page, but suggested that we come over here for more help. She wants to calibrate the Pi with a sound pressure meter (I have one of these) to figure out how many millivolts are produced
Here is what we are thinking so far. We bought an adc (mcp3008) from adafruit and are awaiting its arrival. If we connect the digital output from the adc to the GPIO pin 11 and GPIO pin 12 to a red LED, will this simple program work?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN)
GPIO.setup(12,GPIO.OUT)
GPIO.output(12,GPIO.LOW) #make sure LED is off
SPL=0 #zero the variable
While SPL<??: #Where ?? is the value in millivolts produced by a sound at 130 db
SPL=GPIO.input(11) #get value from adc connected to microphone
GPIO.output(12,GPIO.HIGH) #turn LED on if the sound level is higher than ??
If this would work, what code could be put at the end to reset the program with the press of a button connected to GPIO pins? She wants this to be portable, so she won't be able to type commands to run the program again.
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.IN) GPIO.setup(12,GPIO.OUT) GPIO.output(12,GPIO.LOW) #make sure LED is off SPL=0 #zero the variable
While SPL<??: #Where ?? is the value in millivolts produced by a sound at 130 db SPL=GPIO.input(11) #get value from adc connected to microphone GPIO.output(12,GPIO.HIGH) #turn LED on if the sound level is higher than ??
– user5769 Feb 01 '13 at 05:49