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

Step 5. Step 4. Controlling servos with sensors and ADC ports.

One possible use for ADC ports, is to utilize them to control servos connected to digital ports respectively, using pressure or light sensors. In the following example, a servo and Photosensitive sensor will be used. The servo will move depending on how much light the sensor is detecting. This will also show an "ADC Value" control in action. It is not necessary to use this control for this example, it is there for demonstration purposes.

So, here is an example of how to do it...

1.) Open your copy of EZ-Builder, and click "Project".

User-inserted image

2.) Click on "Add Controls", then "Scripting" and select "EZ-Script".

User-inserted image

User-inserted image

3.) Now click on the "Gear" icon to open the script editor.

User-inserted image

4.) Copy/paste or wright in the following script...

Servo(d0, getadc(adc0))

6.) Now click "Save".

7.) Next, Connect the sensor to an analog port on your EZ-B, then a servo to a digital port.

User-inserted image

8.) Power on your EZ-B, and connect it to EZ-Builder. Now press "Start" on the script control, and the servo will now move when the sensor detects different brightness of light which change the analog readings. As an optional extra, you can add an ADC control like the "ADC Value" control seen in the video below, to see the sensor readings change as they happen. Check out the short video demo of this in action...

One thing to note, because most servo positions only go up to 180, and ADC values go up to 255, you may need to add a multiplier to the GetADC() script command for each of the positions for better accuracy. The resister values on the Photosensitive sensor determine the accuracy and voltage being returned. An explanation of a multiplier can be found in the step 7.


Upgrade to ARC Pro

Unlock the true power of automation and robotics by becoming a proud subscriber of Synthiam ARC Pro.


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


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.