MIEO with a single servo arm raised, beside a laptop keyboard
Mieo ProRobot armsIntermediate35 minArena (live)

Remote Servo Arm

Raise and lower a servo arm with your keyboard

What you'll build

Robot arms in factories are often driven by a person with a controller before they're programmed to work alone. In this project you do the same, with your computer keyboard as the controller. Hold the up arrow and MIEO's arm rises a few degrees at a time; hold the down arrow and it lowers. Press H to send it home. The program also keeps the arm inside safe limits, so it can never be told to push against itself.

What you'll learn

  • Keeping a servo's angle in a variable and changing it a little at a time
  • Setting safe limits with “and”, so a part can't be pushed too far
  • Showing a live reading on screen with “say”
  • Controlling a robot arm live in Arena mode

You'll need

  • Mieo board
  • Battery
  • 3D-printed mountings
  • Screws and screwdriver
  • A servo motor, from the MIEO kit
  • Robot arm parts, from the Mieo Pro kit
  • A computer with Bluetooth
  • The Robolab app (free)

Stay safe

  • Ask an adult to help with the small screws.
  • Plug extra parts only into the connector this page names. Wiring a part to the wrong connector can damage it for good.

Build it

  1. Build the robot arm from your Mieo Pro kit as the Mieo Pro build guide shows, with the servo at the arm's shoulder.
  2. With MIEO switched off, plug the servo into connector S1, the right way round.
  3. Switch MIEO on and connect it to your computer over Bluetooth. Then run the program once before fixing the arm to the servo, so the servo is at 90: fit the arm sticking straight out.

Code it

  1. Open Robolab, choose Mieo, connect over Bluetooth and set the switch at the top right to Arena. Make a variable called angle.
  2. Start with “when green flag clicked”, “set angle to 90” and “set servo on Servo 1 to (angle) angle”, with the angle variable dropped into the gap.
  3. Add a “forever” loop. Inside it, add “if … then” with “key up arrow pressed? and angle < 170” as its condition, and “change angle by 5” and “set servo on Servo 1 to (angle) angle” inside.
  4. Add a second “if … then” for “key down arrow pressed? and angle > 10”, with “change angle by -5” and the same servo block.
  5. Still in the loop, add “say” from Looks with “join Arm angle: (angle)” in it, so the angle shows on the stage.
  6. Add a second script: “when h key pressed”, “set angle to 90” and the servo block, to send the arm home.
  7. Click the green flag, click once on the stage, and use the arrow keys.

Arena mode: the program runs on your computer and talks to MIEO live over USB or Bluetooth, so keep MIEO switched on and connected.

The finished program
The Robolab blocks for the Mieo sprite, as listed below
when green flag clicked
set [angle v] to (90)
set servo on Servo [1 v] to (angle) angle
forever
  if <<key [up arrow v] pressed?> and <(angle) < (170)>> then
    change [angle v] by (5)
    set servo on Servo [1 v] to (angle) angle
  end
  if <<key [down arrow v] pressed?> and <(angle) > (10)>> then
    change [angle v] by (-5)
    set servo on Servo [1 v] to (angle) angle
  end
  say (join (Arm angle:) (angle))
end

when [h v] key pressed
set [angle v] to (90)
set servo on Servo [1 v] to (angle) angle
Checked in Robolab 1.0.10. Open it in Robolab from the File menu.

Test it

Click the green flag and the arm moves to 90 degrees, sticking straight out, while the Mieo sprite on the stage says “Arm angle: 90”. Hold the up arrow and the arm rises smoothly, 5 degrees at a time, stopping at 170. Hold the down arrow and it lowers, stopping at 10. Press H and it swings straight back to 90.

If it doesn't work

  • The arm moves the wrong way for each key? Swap the 5 and the -5, or fit the arm the other way round on the servo.
  • The arm jerks instead of moving smoothly? Use a smaller step, such as 3 and -3.
  • The servo buzzes at one end? It's pushing against the arm's frame. Change 170 or 10 to stop it a little earlier.

Make it your own

  1. Easy: add more home positions on other keys, such as T for straight up.
  2. Medium: make the arm move faster while the space bar is held as well, with a step of 10 instead of 5.
  3. Hard: record a move: press R to remember the current angle in a list, then P to play every remembered angle back in order.

What to build next