Asked — Edited

Sound Sensors

Hey Everyone!

I am currently stuck on how to code these 2 sound sensors (1 on left, 1 on the right)(picture below) on the head of my robot. I have a servo (D18) that goes up to 180 degrees and I want the head to turn towards the loudest noise level. I have looked at some examples and I still dont have any progress.

Any help would be appreciated

Thanks,

Cameron

User-inserted image


ARC Pro

Upgrade to ARC Pro

Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming

#1  

Very straight forward... This sensor plugs into an analog port... sample code would be...


:top
$LevelLeft = GetADC(adc0)
print($LevelLeft)
sleep(100)
goto(top)

#2  

Thank you very much Richard!

#4  

Using if statements... Here's a simple (in english wording) way to look at it. Once you get the logic worked out you can use script commands to achieve what you want

if sound level on left side great than a certain level move servo left else if sound level on right side greater than a certain level move servo right end if statement

Now just convert this to ARC script... I can do it for you but you won't learn anything... Take my example from my previous code post and take a shot at adding if/else statements to move your servos... You will need another variable for the right side as follows...


:top
$LevelLeft = GetADC(adc0)
$LevelRight = GetADC(adc1)

#hint... here is where you put your if/elseif statement

sleep(100)
goto(top)

#5  

Yeah I'm someone who doesnt always just wants answers. I want to learn so I'm on the same page with that. Thank you Richard I will play around with it.

#6  

@Richard R So I think i'm missing something here...Servo seems to move but only the the left right away back and forth not picking up values...

:top $LevelLeft = GetADC(adc0) $LevelRight = GetADC(adc1)

if($LevelLeft > $LevelRight) Servo(D18,180) else if($LevelRight > $LevelLeft) Servo(D18,1)

endif

sleep(100)

goto(top)

#7  

Pretty good, but you may need a bit more...


servo(D18,90) #center the servo to start
:top
$LevelLeft = GetADC(adc0)
$LevelRight = GetADC(adc1)

#may need to use a lower or high value than 50
If($LevelLeft<50 and $LevelRight<50) #no sound so don't move servo
sleep(100)
goto(top)
endif

if($LevelLeft > $LevelRight)
Servo(D18,180)
sleep(2000) # look for 2 seconds then center again
Servo(D18,90)
else if($LevelRight > $LevelLeft)
Servo(D18,1)
sleep(2000) # look for 2 seconds then center again
Servo(D18,90)
endif

sleep(100)

goto(top)

#8  

If you dont have it yet, under Scripting in the controls, add a variable watcher. This will let you see what the $LevelLeft and $LevelRight variables are being set to.

Also, the sleep command is probably to short. This is 1/10 of a second. Try increasing the sleep command to something longer like 1000 (a second) and see if that helps you out.