Servo Box
Description
A servo or two and a cardboard box are all you need to create an animated scene with your Circuit Playground Express. Drawings, cut out photos, pipe cleaner figures, origami creations, and more can be attached to popsicle sticks, then set into motion. Add light and sound from the Circuit Playground Express if you want more media dimensions.
Time Required
Hours |
---|
Approximately 3 hours to complete.
Academic Tie-in Ideas
- Science: Animate the inhabitants of an ecosystem–whether it’s large or microscopic. Include text on the front of the box explaining what is going on. Instead of using Poster Boards for a science fair project, use these Servo Boxes!
- History: Bring historical characters to life in a setting you create.
- Literature: Set in motion a key scene or important theme from a work of literature.
Materials
See the Maker Tools and Techniques chapter for more details on materials.
- Cardboard box – a shoe box works well
- Popsicle sticks
- Small zip ties, pipe cleaners, or string to connect the popsicle sticks
- 1 or more servo motors (180 degree and/or continuous rotation motors)
- Glue gun and glue sticks
- Tape
- Craft knife, cardboard cutter and/or scissors
- Drill with a 9/64” bit or similar size (optional if you want to use the popsicle sticks as rocker arms)
- Colored paper, stickers, markers or other decorative items for your box
Making
Plan your project
What will go on your popsicle sticks, and what will set the stage around the rest of the box? Placement of the popsicle sticks and the figures they carry can help tell a story and create the aesthetics you envision.
Assemble your moving figures
There are three kinds of motion you can choose from here:
- Wagging back-and-forth motion – this is the simplest movement. A 180-degree servo motor will let you create a simple back-and-forth wagging motion for a figure.
- Rocking motion with two figures – this is like a seesaw using a 180-degree servo motor as a rocker arm that makes two vertical popsicle sticks travel up and down.
- Continuous rotating motion – this is good for a constantly turning wheel or sun/moon cycle. This motion will require a continuous (360-degree) servo motor.
Assembly for the Wagging back-and-forth motion
- Hot glue a servo horn to the end of a popsicle stick, taking care to not get glue in the large hole that mounts to the servo itself.
- Attach the servo horn with popsicle stick to the servo motor.
- Place the servo motor so that that the long, flat sides are parallel to the floor. Then, find the two extremes of the range of motion.Detach the popsicle stick and servo horn when they are at one extreme, then reattach so that the popsicle stick is also parallel to the floor. Getting it oriented this way will make coding the motion of the stick much easier later.
- Cover the servo motor body in masking tape.
- Cut a slot in the top of the box for the popsicle stick to travel through that is at least 2” long and ¼” wide. If the slot is too short, the popsicle stick will always stick out of the box; if the slot is the entire length of the popsicle stick (plus whatever you plan to mount on it), then the stick will disappear at 0 and 180 degrees. This slot can be anywhere you want on the box.
- Attach the servo motor on the inside of the box – turn the popsicle stick so it is in the 90-degree (middle) position, insert it from inside the box up through the slot, then hot glue the servo motor to the underside of the box’s ceiling. Take care that the motion of the horn and stick won’t be impeded by the box.
- Tape or glue your figure to the end of the popsicle stick.
Assembly for the Rocking motion with two figures
- You will need 3 popsicle sticks to create this rocker arm.
- Drill small holes of about 9/64” at both ends of one of the popsicle sticks. This will be the center rocker arm.
- Drill one small hole at the end of each of the other two popsicle sticks. These will be the two vertical arms of the rocker.
- Remember that in order to prevent the popsicle stick from splitting while drilling, apply as little pressure as possible.
- Hot glue a servo horn to the middle of the center popsicle stick rocker arm (the stick with two holes). Be sure to avoid getting glue in the center hole of the servo horn.
- Attach the center arm popsicle stick to a servo motor. Take your 180-degree servo motor and set the popsicle stick so that that the long, flat sides are parallel to the floor. Then, find the two extremes of the range of motion. Detach the popsicle stick and servo horn when they are at one extreme, then reattach so that the popsicle stick is perpendicular to the floor. Getting it oriented this way will make coding the motion of the stick much easier later because you know that 90 degrees is about parallel to the floor. Here’s a helpful video on how to do this:
- Cut holes in the top of the box. Place the servo motor with the popsicle stick on the top of the box along one of the edges of the box to measure where the vertical arm ends will come out. Then, cut two slots for the vertical popsicle sticks to travel through. The slots should be just a bit wider than your popsicle stick, and about ¼” across.
- Apply masking tape to the back of the servo, and hot glue the servo to the inside wall of the box 1 ½ to 2 ½ inches below the ceiling. Be sure to center the popsicle stick holes under the slots you cut in the box top.
- Insert the vertical arm popsicle sticks into the holes in the box top, and connect them to the rocker arm with loose zip ties, pipe cleaners or string.
- Tape or glue your figures to the ends of the two vertical popsicle sticks.
Assembly for the continuous motion servo
- Mount the figure you want to put in motion on your popsicle stick first. The reason for this is that it will be travelling through the top of the box and inside, so you need to know how long the entire thing will be. You can either have one figure at one end, or one figure at each end.
- Place the continuous motion servo on the top of the box against the side you plan to mount it on, then draw a line so you know how wide the slot you cut will need to be.
- Cut a slot for the popsicle stick to travel though. If you have one figure, this slot should be a bit longer than double the entire length of the popsicle stick with attached figure. If you have two figures, this slot should be a little longer than the entire length of your popsicle stick with attached figures. In either case, the slot should be a little wider than the widest part of the figure.
In this image, one figure is mounted on a popsicle stick. The end of the stick attaches to the servo motor, and the slot in the cardboard is more than twice as long so the figure can travel through the top of the box on each side of the servo motor.
In this image, two figures are mounted on each end of the popsicle stick. The center of the stick is affixed to the servo motor, and the slot in the cardboard is a bit longer than the total length from figure to figure.
- Hot glue a servo horn either to the center of the popsicle stick if you are using two figures, or to the end of the popsicle stick if you are only using one figure. Be sure to avoid getting glue in the large attachment hole of the servo horn.
- Hot glue the servo motor body to the inside wall of the box, taking care that the servo horn and popsicle stick will be able to travel unimpeded through the hole in the top of the box.
Stage your scene
Decorate the top and front of the box according to the theme you’ve chosen. In addition to paper, cardboard, and other materials, you can also create gusset braces out of cardboard to hold popsicle sticks upright for more options to mount decorations.
Attach the Circuit Playground Express
Once your servo is all set up, attach the servo wires to the Circuit Playground Express with alligator to male connector wires.
- Black / brown goes to GND
- Red goes to VOUT (or 3.3V if using more than one).
- Yellow / orange goes to A1 or A2 Pins. For more details on connecting servo motors, see the section on Servo Motors in Coding the Circuit Playground Express chapter.
Coding
See Coding the Circuit Playground Express chapter for more information.
The following code samples will correspond to the three different types of motion:
- Wagging back-and-forth motion
- Rocking seesaw motion with two figures
- Continuous rotating motion
These are code samples only – you will likely need to tweak angle values and/or speed of motion for your project. You can also add lights and sound to your program for additional effects.
Wagging motion code
This sample code has the figure move to 65
degrees, pause for 1.5 seconds (1500
ms), move to 120
degrees, pause again, and repeat that 10
times when button A is pressed.
input.buttonA.onEvent(ButtonEvent.Click, function () {
for (let i = 0; i < 10; i++) {
servos.A1.setAngle(65)
pause(1500)
servos.A1.setAngle(120)
pause(1500)
}
})
Rocking motion code
Similar to the wagging motion code, but this sample code doesn’t use quite as long a pause between the different angles since it’s meant to be a see-saw motion between 2 figures, and we use 75
degrees and 115
degrees as the optimal angles for our project. This code is also triggered on a loud sound (clap or snap for example). We’ve also added a rainbow animation to add to the ambiance of our scene – notice that we’re running the animation at the same time as we are moving the servo motor. The ||control:run in parallel||
block can be found in the ||control:CONTROL||
Toolbox drawer.
input.onLoudSound(function () {
control.runInParallel(function () {
light.showAnimation(light.rainbowAnimation, 10000)
})
for (let i = 0; i < 10; i++) {
servos.A1.setAngle(75)
pause(500)
servos.A1.setAngle(115)
pause(500)
}
})
Continuous rotation code
This sample code uses the ||servos:continuous servo||
block. When button A is pressed, it moves at 25
percent (%) speed in one direction. When button B is pressed, it moves 25
percent (%) speed in the other direction. And when buttons A and B are pressed together, it stops moving.
input.buttonA.onEvent(ButtonEvent.Click, function () {
servos.A1.run(25)
})
input.buttonB.onEvent(ButtonEvent.Click, function () {
servos.A1.run(-25)
})
input.buttonsAB.onEvent(ButtonEvent.Click, function () {
servos.A1.run(0)
})
Variations and Challenges
Here are some different variations or challenges you can incorporate into your project:
- Try using a condition to trigger the motion on your Servo Box. For example, if it’s night-time (dark out) then the moon comes out on your box.
- For a continuous rotation servo, try using a variable that responds to sound or light to increase the rotation speed as it gets lighter/darker or louder/quieter.
- Think outside the box: mount your servo motors on a vertical surface for display. This could be a great way to enliven a science fair poster board display. Make your data move!
- Get creative with inputs: trigger your servo motors to move with light, sound, touch, or temperature change.
- Get creative with outputs: add light and sound from the Circuit Playground Express to your project.
- Involve digital fabrication: Create objects with a 3D printer, laser cutter, or programmable paper cutter.
servo