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

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

#25  

@CochranRobotics

I adjusted the values a few times and it still goes to one side and not the other. Here is the script I am using:



Servo(D18,90)
$Direction=0
$L=0
$R=0

:loop

repeat($x,0,2,1)


$Left=GetADC(adc0)*100   
$Left_T=$Left+$L
$L=$Left_T

$Right=GetADC(adc1)*100
$Right_T=$Right+$R
$R=$Right_T

Sleep(1000)

endrepeat

$Direction=$Left_T-$Right_T

if($Direction>-100)
Servo(D18,180)
Sleep(1800)
$Direction=0
$Left_T=0
$L=0

Elseif($Direction<-100) 
Servo(D18,1)
Sleep(1800)
$Direction=0
$Right_T=0
$R=0

endif

$Left_T=0
$Right_T=0
$L=0
$R=0

Goto(loop)


I even tried the 2 put together you posted and it still did the same thing. I know I am missing something here just not seeing it...

#26  

Hi Cameron, I posted that script. Have you ran the script in the RUN window to see if you are getting the <-100 and/or >-100 values for each sensor, if so, are you? If not, perhaps there is something wrong with a sensor. Try switching the sensors around and see what happens

#27  

@bhouston

Yeah im sorry i meant to add you to the thread as well. I have ran the script multiple times and it does show 1 having a bigger value in the variable list. But at another time they are both over 100. I'll try again and even switch them like you said.

Thank you

#28  

Run it in this window and you can see exactly what the script and the sensors are doing as you run the script.

User-inserted image

#29  

I see that you have - if($Direction>-100) - I think it should be >100.

#30  

What is the "*100" in the following part of the script:


$Left=GetADC(adc0)*100   
$Left_T=$Left+$L
$L=$Left_T

$Right=GetADC(adc1)*100
$Right_T=$Right+$R
$R=$Right_T

Are you trying to comment out the 100 for your reference? Unless I was not aware of this being OK, I don't think you can use a * to comment out something. I've always used this character: #

#31  

it was to make the value obviously high.

I think he has a sensor that os messing up or reporting much lower than the other but that is just a guess.

#32  

it was to make the value obviously high.

So this * forces the ACD reading to a wanted value? I'm not understanding this. Sorry. Can't find this in the EZ Script manual. confused