Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Asked — Edited

Target Bot - Getservo() Question

I'm trying to build a robotic Target Practice Bot with one Servo. The servo raises the target up, and then releases the servo. At this point I can shoot the target with a nerf dart pushing the target back just a little.

Then I want it to run a script based on the if(GetServo()) function. However, it always returns the last servo Position programmed, NOT the actual position of the Servo. I'm using only components from the EZ-Robot kit.

Is there any way to get the actual value of the servo, as opposed to the last value sent to it?


Upgrade to ARC Pro

Get access to the latest features and updates with ARC Pro edition. You'll have everything that's needed to unleash your robot's potential!

It is impossible obtain the position of a servo by the servo itself. The servo position is specified by your controller (EZ-B, R/C, Etc). The controller broadcasts a special signal that the servo understands and moves into the respective position.

Learn how a servo works here: http://www.ez-robot.com/Tutorials/Hardware.aspx?id=4

I think you're idea is neat, but you will not be able to determine the servo position that way. You can attach a Potentiometer (Also referred in short as POT) to the servo shaft. If you use a Peripheral Extension Cable (from our store) and connect to one of the ADC ports, you can determine the position of the POT.

To wire a POT, simply connect the +5 from the peripheral cable to the left pin of the pot. Connect the GND to the right pin of the pot. And connect the white/signal to the center pin of the pot.

Add the ADC control and voila... you can see the pot move. Use the GetADC() function in EZ-Script to obtain the value.

So do something like this...


# Set the movement resolution. This is the range the POT can move to know if it's been shot
$resolution = 2


# Move servo to position
servo(d0, 50)

# Sleep for a bit to make sure we're in position

# Release the servo

# sleep for a bit in case the servo moves after releasing

# get the adc value of the pot before being shot
$pot = GetADC(adc0)

$rangeHigh = $pot + $resolution
$rangeLow = $pot - $resolution

print("Waiting to be shot")


$newPot = GetADC(adc0)

if ($newPot > $rangeHigh)

if ($newPot < $rangeLow)



# We have been shot!
print("OUCH! You hit me")

# Move the servo down to pretend the nerf gun has a lot of juice
servo(d0, 20)

# Pause for a second

# Start the game over
That's awesome DJ sures! Thank you. One other thought, before I start hunting down a potentiometer. Can I make a trigger?

I'm thinking two cables running into a digitial port(or other port) and when they are a connected a script returns True, and when they are not connected they'll return False?

Thanks again.
You can use a trigger for sure. You can get creative and put a few triggers on the paddle so you know where it's been hit.
How do I wire the trigger? I've been playing around with the Read ADC control. It reads 5 volts when the red and black wire aren't connected, and the whole device shorts when they do connect *eek*. I tried inserting various resistors and LED's in between the cables, but haven't had any luck. I've no practical experience in circuitry.

Basically, how would I wire something as simple as this whisker trigger into the EZB?

I'm guessing the coding is pretty easy too, but I'd appreciate any advice.

Thanks again DJ Sures!
Got it! Thanks.

Here's the test code for anyone trying to figure out a switch.

If(GetDigital(d8) = 1)

When the power(red) and GND(white) wires are connected it'll return "yes".
You mean Power (RED) and Signal (white) are connected, it will return yes:)

Check this page: http://www.ez-robot.com/Tutorials/Hardware.aspx?id=1

There is a diagram that I just added explaining the ports.

Also keep in mind that on a digital port, YES (true) is any voltage above 0 (gnd). If you connect a switch between +5 and Signal, it will occasionally respond with YES (true) when you move your hand near the switch. This is because your hand has static electricity and it will be conducted.

The way to get around this is to use a 75k (or any value really) resistor between Signal and GND. That way the Signal sees GND all the time. When the +5 is connected to Signal via the switch, it will now see +5 on the Signal and return True.

The resistor acts as a little cushion between the GND and Voltage. Resistors are like the water taps in your home. They can let more or less power pass through them (resistance).
So here's the Target Bot.
D7 is the main servo.
D8 is the switch, which uses the GND and Signal cables (no resistors required).


If(GetDigital(d8) = 0)

say("Nice Shot")