Using ADC (Analog to Digital) Ports, Commands and Controls.

Step 7. ADC Example with Sound Sensors.

This step will guide you though setting up and using a Sound Sensors and make it turn an LED on and off. It will also show the "ADC Meter" control in use.

1.) Connect the sound sensor to an analog port on the EZ-B (This example will use "A0"). Now connect up a single 3 volt LED to the "Signal" and "Ground" pins on a digital port (D0 in this example), ensuring that the "Anode" (+) goes to the signal pin, and "Cathode" (-) goes to the ground pin. Then power up the EZ-B.

User-inserted image

2.) Open EZ-Builder, then from the menu ribbon, click "Project", "Add controls", "ADC", then "ADC Meter" to add this to your project.

User-inserted image

3.) On the "ADC Meter" control, click on the gear icon to open the configuration menu, and select the port the sensor is connected to, then click "Save".

User-inserted image

4.) Now connect the EZ-B to Ez-Builder, and make some noise... literally. The louder the sound is detected, the higher the visual display will go in the control window. You may need to adjust the potentiometer on the sound sensor to adjust the sensitivity.

5.) Make a note of the readings when quiet, and when sound is heard. You will want to use an "ADC Read" control for this.

Now to make the sound detector turn on an LED when sound is heard.

6.) From the menu ribbon, press "Project", "Add controls", "Scripting", then "EZ-Script" to add this to your project.

User-inserted image

7.) Open the script configuration menu, and write or copy/paste the following script...

:loop
#Read's the value on EZ-B port A0
$sound=getADC(adc0) 

#Will turn LED on when sensor reading is above 5.
#Change the values if necessary.
if($sound>5)
set(d0,On)

#Will turn LED off when sensor reading is below 4.
elseif($sound<4)
set(d0,Off)
endif
goto(loop)

Below, is a short video demo of the script in action...

Yoy may have noticed in the video, that the visual output on the "ADC Graph" didn't go very high. The link below, is a more extensive script using two sound sensors that also uses a multiplier to increase sensor readings. Basically by multiplying the sound values, you are magnifying the sound sensor values and you filter out random background noises that the sensor may pick up. A fellow community, @mtiberia, member did exactly this using two sensors, and his thread explains and demonstrates this very well. He also has a great video demo, and also shares his script. Click on the link below to have a look.

EZ-B can figure out what side sound is coming from.


ARC Pro

Upgrade to ARC Pro

Elevate your robot's capabilities to the next level with Synthiam ARC Pro, unlocking a world of possibilities in robot programming.

PRO
USA
#1  

can this detect the audio for a jaw movement on a robot?

PRO
Canada
#2  

If you have a analog audio level sensor (has a microphone) hooked up to the ADC you can detect the strength of audio levels.

You may be able to run the audio from the speaker breakout on the EZ-B v4 or IoTiny to an analog pin, I've never tried it but in theory it would work. It's a 3.3V audio amplifier. Although, it might mess up your audio if you still want audio going to the speaker. Worth a try I suppose.