# Cam Follower Automaton

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/054/850/medium800/makecode_camFollowerAutomaton.jpg?1528135193)

https://youtu.be/zek5K63rOhk

An automaton type of robot that can create anything from simple up and down movements of a character all the way through to incredibly intricate, complicated scenes with multiple animated characters, and even such incredible feats as figures that can draw illustrations or write words with an ink pen!

One of the primary mechanisms found in nearly all automata is the cam follower. In this project we'll build such a mechanism and motorize the drive wheel with a Crickit and Circuit Playground Express coded in MakeCode.

## Parts
![](https://cdn-learn.adafruit.com/assets/assets/000/054/849/medium800/makecode_IMG_3373_2k.jpg?1528135154)

### Part: Circuit Playground Express
quantity: 1
Round, Awesome Microcontroller Board
[Circuit Playground Express](https://www.adafruit.com/product/3333)

### Part: Adafruit CRICKIT
quantity: 1
for Circuit Playground Express
[Adafruit CRICKIT](https://www.adafruit.com/product/3093)

### Part: TT Motor DC Gearbox
quantity: 1
200 RPM 3 to 6VDC
[TT Motor DC Gearbox](https://www.adafruit.com/product/3777)

### Part: Orange and Clear TT Motor Wheel
quantity: 1
for TT DC gearbox motor
[Orange and Clear TT Motor Wheel](https://www.adafruit.com/product/3766)

### Part: Waterproof 3xAA Battery Holder
quantity: 1
with On/Off Switch
[Waterproof 3xAA Battery Holder](https://www.adafruit.com/product/771)

### Part: Male DC Power adapter
quantity: 1
2.1mm plug to screw terminal block
[Male DC Power adapter](https://www.adafruit.com/product/771)

### Part: Alkaline AA batteries
quantity: 1
3 pack
[Alkaline AA batteries](https://www.adafruit.com/product/3521)

## Materials and Tools
- Small and medium corrugated cardboard boxes
- Wooden dowels or pencils
- Rubber bands
- Ruler
- Hobby knife or scissors
- Hot melt glue and glue gun, or white glue
- Compass or circular object to trace, e.g. coffee can
- Pipe cleaner or string

![](https://cdn-learn.adafruit.com/assets/assets/000/054/852/medium800/makecode_IMG_3160_2k.jpg?1528135243)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/853/medium800/makecode_IMG_3197_2k.jpg?1528135254)

Here's the original livestream that spawned this project:

https://youtu.be/BIYpmKVRtjk

# Cam Follower Automaton

## Build the Mechanism

## Cam Follower Basics
At the heart of this automaton is the cam follower mechanism. In the diagram below we have named the basic parts of the system. For a more in depth view, take a look at [this excellent page](http://cabaret.co.uk/cam-followers-for-automata-dugs-tips-16/) by automata builder Dug North.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/859/medium800/makecode_camDiagram01.jpg?1528140844)

Here's how the mechanism works -- the axle or shaft rotates, as does the cam which is attached to it. Gravity keeps the follower in contact with the cam as it rotates, however the rod that is attached to the follower is constrained by the bearing, so it can only move up and down.

This has the end result of converting rotation to linear motion.

## Oval Cam
In this animation we can see how an oval shaped cam will create a regularly repeating up and down motion for the follower and rod. The regular, smooth, symmetrical shape of this motion is similar to a sine wave if we to plot the motion on the y-axis over time.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/865/medium800thumb/makecode_camAnim_00.jpg?1528141871)

## Irregular Pear Cam

This cam has a somewhat irregular pear shape. Note how this produces a more abrupt rise and fall, with a longer period in the down position, more like a jump motion.

![](https://cdn-learn.adafruit.com/assets/assets/000/055/009/medium800thumb/makecode_camAnim_01c.jpg?1528159692)

## Construction

The basic construction of our automaton is fairly simple -- we'll use a small box as the frame, two dowels (or pencils!) poked through holes in the box for the cam's drive shaft and follower rod, and cardboard shapes for the cam and follower. A piece of drinking straw will act as our rod bearing.

Instead of cranking the drive axle by hand, we'll turn it with a DC motor driven by the Crickit and Circuit Playground Express. Since the DC motor spins too fast to connect to the cam shaft, we'll need to gear it down by building a large cardboard wheel which the motor will drive indirectly with a smaller wheel and rubber tire.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/867/medium800/makecode_IMG_3150_2k.jpg?1528144367)

## Frame Building

Start with a small cardboard box. From it, remove a long, rectangular section from the front of the box. This will be a guide for the follower so that the rod (and automaton) doesn't spin around on it's long axis.

Use a ruler to draw out and cut the rectangle from the front of the box. The exact measurements aren't important here, but note that the distance from the middle to the top of the rectangle is the maximum vertical distance the rod and automaton will be able to travel.

![makecode_IMG_3158_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/868/medium640/makecode_IMG_3158_2k.jpg?1528144385)

![makecode_IMG_3160_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/869/medium640/makecode_IMG_3160_2k.jpg?1528144394)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/871/medium800/makecode_IMG_3162_2k.jpg?1528144523)

## Cam Shaft Holes

Next, poke a hole through the centers of both sides of the box&nbsp; -- this will hold the cam shaft as it rotates.

- Measure the spot at the center of the sides so that the axle is level
- One way to do this is by using a ruler to draw and 'x' from corner to diagonal corner -- the center of the 'x' is the center of the rectangle!
- Use a sharp, round object to poke the holes through so the dowel will fit and turn without much friction

![makecode_IMG_3166_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/872/medium640/makecode_IMG_3166_2k.jpg?1528144619)

![makecode_IMG_3167_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/873/medium640/makecode_IMG_3167_2k.jpg?1528144625)

## Rod Bearing

Now, poke a hole through the center of the top of the box for the rod dowel.

To help the rod move up and down, we'll add a short length of drinking straw to act as a bearing. The plastic is pretty low friction, and the length of the straw will prevent the rod from rotating.

- Mark the center of the top of the box
- Poke a hole for the bearing
- Cut a short length of drinking straw -- make sure the straw's internal diameter is large enough to fit the dowel
- Place the straw piece in the hole
- Optionally, use a dab of hot glue to hold the straw in place

![makecode_IMG_3171_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/874/medium640/makecode_IMG_3171_2k.jpg?1528144932)

![makecode_IMG_3176_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/875/medium640/makecode_IMG_3176_2k.jpg?1528144939)

![makecode_IMG_3180_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/876/medium640/makecode_IMG_3180_2k.jpg?1528144945)

![makecode_IMG_3182_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/877/medium640/makecode_IMG_3182_2k.jpg?1528144951)

![makecode_IMG_3183_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/878/medium640/makecode_IMG_3183_2k.jpg?1528144957)

![makecode_IMG_3184_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/879/medium640/makecode_IMG_3184_2k.jpg?1528144963)

## Follower Guide

Cut out an identical rectangle from the back of the box as you did for the front -- this will act as the other half of the guide for the follower to prevent it from rotating.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/880/medium800/makecode_IMG_3251_2k.jpg?1528145148)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/881/medium800/makecode_IMG_3255_2k.jpg?1528145160)

## Cam Building

Now, we're ready to make a cam. You can experiment with different sizes and shapes of cams for your automata. For this one, we'll make a type of jumping motion by using an irregular pear shaped cam.

- Measure the distance from the center to the top of your follower guide rectangle you cut from the front face of the box. This is the maximum radius our cam can be before it would get stuck during rotation
- Draw a circle of that measured radius on a piece of cardboard using a compass. Alternatively, you can use an appropriately sized lid or can to measure and draw the circle
- Draw a smaller circle centered on the same spot as the first. This will be the lowest point the follower can drop
- Connect the shapes as shown to create the irregular cam -- this doesn't need to be exactly the same as shown here
- Cut out the cam using a knife or scissors
- Transfer the shape to create two more cam pieces, then poke their center holes out to the same diameter as your dowels
- Glue the cam pieces together

![makecode_IMG_3256_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/882/medium640/makecode_IMG_3256_2k.jpg?1528145568)

![makecode_IMG_3257_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/883/medium640/makecode_IMG_3257_2k.jpg?1528145575)

![makecode_IMG_3258_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/884/medium640/makecode_IMG_3258_2k.jpg?1528145584)

![makecode_IMG_3259_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/885/medium640/makecode_IMG_3259_2k.jpg?1528145596)

![makecode_IMG_3262_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/886/medium640/makecode_IMG_3262_2k.jpg?1528145609)

![makecode_IMG_3264_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/887/medium640/makecode_IMG_3264_2k.jpg?1528145624)

![makecode_IMG_3265_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/888/medium640/makecode_IMG_3265_2k.jpg?1528145651)

![makecode_IMG_3270_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/889/medium640/makecode_IMG_3270_2k.jpg?1528145660)

![makecode_IMG_3271_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/890/medium640/makecode_IMG_3271_2k.jpg?1528145675)

![makecode_IMG_3275_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/891/medium640/makecode_IMG_3275_2k.jpg?1528145691)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/892/medium800/makecode_IMG_3272_2k.jpg?1528145700)

## Make the Follower

Now, we'll make a simple rectangular follower that will be able to ride the edge of the cam and transfer the motion to the rod and automaton above.

- Measure a piece of cardboard that will protrude from the front and back of the box and is a bit more narrow than the rectangular follower guides you cut from the front and back of the box
- Cut four identical rectangles
- Poke holes in the centers of three of the rectangles for the rod to fit
- Glue the pieces together in a stack with the piece that has not hole at the bottom -- this will contact the cam so we want it to be smooth

![makecode_IMG_3277_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/894/medium640/makecode_IMG_3277_2k.jpg?1528145788)

![makecode_IMG_3279_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/896/medium640/makecode_IMG_3279_2k.jpg?1528145918)

![makecode_IMG_3288_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/897/medium640/makecode_IMG_3288_2k.jpg?1528145924)

![makecode_IMG_3289_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/898/medium640/makecode_IMG_3289_2k.jpg?1528145931)

![makecode_IMG_3290_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/899/medium640/makecode_IMG_3290_2k.jpg?1528145940)

## Insert Rod and Follower

Slide the rod into the bearing and then attach it to the follower by pressing it into the hole. You can add a bit of hot glue for a secure fit.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/900/medium800/makecode_IMG_3294_2k.jpg?1528146011)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/901/medium800/makecode_IMG_3295_2k.jpg?1528146021)

## Add the Cam and Shaft

We'll add the cam shaft, cam and a couple of rubber bands to prevent the shaft from moving left or right.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/904/medium800/makecode_IMG_3303_2k.jpg?1528146162)

- Push the cam shaft through one side of the box
- Wind a rubber band around it. This will help prevent the shaft from moving around
- Slide on the cam
- Add the second rubber band
- Push the shaft through the other side of the box
- Add hot glue to secure the cam to the cam shaft -- these two parts need to move as one

![makecode_IMG_3306_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/905/medium640/makecode_IMG_3306_2k.jpg?1528146181)

![makecode_IMG_3308_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/907/medium640/makecode_IMG_3308_2k.jpg?1528146228)

![makecode_IMG_3310_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/908/medium640/makecode_IMG_3310_2k.jpg?1528146235)

## Test the Motion

Close the box lid and try rotating the cam shaft -- you'll see the follower has no choice but to move up and down!

![](https://cdn-learn.adafruit.com/assets/assets/000/054/910/medium800thumb/makecode_cardboardCamDemo.jpg?1528146525)

## Cam Shaft Wheel

Since the DC motor we're using spins faster than we want, we will gear it down. To do this, we'll use a small wheel on the DC motor shaft that will spin multiple revolutions to turn a much larger wheel it is "riding on". This is similar to using toothed gears to accomplish the same task, but we'll be able to get away with just the friction of the rubber tire to do the turning.

We'll make a wheel of the exact size we need out of cardboard! The wheel needs to have a diameter a bit smaller than the height of the box so that it won't touch the surface upon which the automaton is resting.

## Wheel Discs

Draw out a circle on a piece of cardboard that is a bit smaller than the box height. You can use a compass, or find a large can or lid to trace.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/917/medium800/makecode_IMG_3189_2k.jpg?1528147479)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/918/medium800/makecode_IMG_3190_2k.jpg?1528147497)

- Cut out two circular discs for the wheel's sides
- Mark the centers of the discs, so we can poke holes for the cam shaft later

![makecode_IMG_3192_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/919/medium640/makecode_IMG_3192_2k.jpg?1528147584)

![makecode_IMG_3194_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/920/medium640/makecode_IMG_3194_2k.jpg?1528147593)

## Wheel Tread

For the center tread of the wheel, we'll cut a long strip of cardboard from an unfolded shipping box.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/923/medium800/makecode_IMG_3197_2k.jpg?1528148076)

- Flatten the box and cut of the flaps
- Cut one edge of the rectangle to create a single, long strip
- To determine the length needed, mark a start point on the strip and a disc and then roll it along the tread strip one revolution until the wheel mark hits the strip again-- this circumference is the length needed so mark the strip for cutting
- Cut the strip a bit longer than measured to account for material thickness (I didn't do this very well so you can see in some pictures where I added a bit of cardboard to fix it!)

![makecode_IMG_3200_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/926/medium640/makecode_IMG_3200_2k.jpg?1528148251)

![makecode_IMG_3201_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/927/medium640/makecode_IMG_3201_2k.jpg?1528148271)

![makecode_IMG_3203_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/928/medium640/makecode_IMG_3203_2k.jpg?1528148319)

![makecode_IMG_3205_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/929/medium640/makecode_IMG_3205_2k.jpg?1528148349)

![makecode_IMG_3206_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/930/medium640/makecode_IMG_3206_2k.jpg?1528148381)

![makecode_IMG_3207_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/932/medium640/makecode_IMG_3207_2k.jpg?1528148433)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/933/medium800/makecode_IMG_3210_2k.jpg?1528148451)

## Pre-Bend the Tread

You can roll the tread tightly around a cylindrical object a bit smaller than the discs in order to form the tread before attempting to glue it to the discs. This will give the tread a bit of a 'memory' of the shape, making things easier.

Here a roll of tape is used to form the tread into a cylinder.

![makecode_IMG_3211_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/935/medium640/makecode_IMG_3211_2k.jpg?1528148560)

![makecode_IMG_3212_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/936/medium640/makecode_IMG_3212_2k.jpg?1528148567)

![makecode_IMG_3216_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/938/medium640/makecode_IMG_3216_2k.jpg?1528148590)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/939/medium800/makecode_IMG_3215_2k.jpg?1528148614)

## Glue the Wheel

&nbsp;

- Using hot glue or white glue, form the tread around one of the discs as shown
- Leave a bit of the end of the tread unglued to make it easier to add the second disc
- Hold the tread in place while the glue sets
- Glue the interior of the tread and add the second disc
- Push the shaft through the ensure a the discs are aligned
- Glue the end flap in place

![makecode_IMG_3223_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/941/medium640/makecode_IMG_3223_2k.jpg?1528148693)

![makecode_IMG_3224_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/942/medium640/makecode_IMG_3224_2k.jpg?1528148701)

![makecode_IMG_3226_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/943/medium640/makecode_IMG_3226_2k.jpg?1528148710)

![makecode_IMG_3228_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/944/medium640/makecode_IMG_3228_2k.jpg?1528148722)

![makecode_IMG_3229_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/945/medium640/makecode_IMG_3229_2k.jpg?1528148788)

![makecode_IMG_3231_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/947/medium640/makecode_IMG_3231_2k.jpg?1528148957)

![makecode_IMG_3232_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/948/medium640/makecode_IMG_3232_2k.jpg?1528148966)

![makecode_IMG_3233_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/949/medium640/makecode_IMG_3233_2k.jpg?1528148974)

![makecode_IMG_3234_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/953/medium640/makecode_IMG_3234_2k.jpg?1528149106)

![makecode_IMG_3236_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/954/medium640/makecode_IMG_3236_2k.jpg?1528149116)

![makecode_IMG_3239_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/955/medium640/makecode_IMG_3239_2k.jpg?1528149128)

![makecode_IMG_3241_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/956/medium640/makecode_IMG_3241_2k.jpg?1528149139)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/957/medium800/makecode_IMG_3242_2k.jpg?1528149154)

## Attach the Wheel

Now we'll slide the large wheel onto the cam axle.

- Slide the wheel onto the cam axle dowel
- Push it close to the box, but not touching
- Add a bit of hot glue to fix it to the axle

![makecode_IMG_3324_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/958/medium640/makecode_IMG_3324_2k.jpg?1528149917)

![makecode_IMG_3325_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/959/medium640/makecode_IMG_3325_2k.jpg?1528149928)

![makecode_IMG_3329_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/960/medium640/makecode_IMG_3329_2k.jpg?1528149936)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/961/medium800/makecode_IMG_3330_2k.jpg?1528149991)

Your basic automaton mechanism is complete! Give the wheel a spin (be careful to note which directly allows the follower to smoothly glide over the edge of the cam, it may get stuck going the other way due to the flat side of the cam) and watch the rod go up and down.

Next we'll program the Crickit and Circuit Playground Express in MakeCode to run the DC motor, which we'll later connect to the mechanism.

# Cam Follower Automaton

## Code with MakeCode

You can code your Crickit and Circuit Playground Express using MakeCode! If you aren't already familiar with MakeCode, [check out this guide](https://learn.adafruit.com/makecode) to get started, then return here when you're ready.

## Crickit Extension

The good folks at Microsoft's MakeCode team have been busily adding Crickit functionality to MakeCode! Currently, this works with the beta version of MakeCode, so [click this link](https://makecode.adafruit.com//beta) to get started. Then, create a new project.

To enable Crickit functionality in MakeCode, click on the **Advanced** category, then click on **Extensions.**

![](https://cdn-learn.adafruit.com/assets/assets/000/054/993/medium800/makecode_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor.jpg?1528153366)

Then, type 'crickit' in the text field and press enter. The Crickit package will appear. Click on it and it'll be added to MakeCode!

![](https://cdn-learn.adafruit.com/assets/assets/000/054/994/medium800/makecode_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_2.jpg?1528153509)

Now that the package has been added, you'll see a new block category appear named **Crickit**

![](https://cdn-learn.adafruit.com/assets/assets/000/054/996/medium800/makecode_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_3.jpg?1528153738)

Click on the **Crickit** category to see all of the things you'll be able to do.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/997/medium800/makecode_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_4.jpg?1528153835)

## Crickit Run Motor

We'll start with the fundamental block for our program -- **crickit run motor**

Add one of these blocks to the **Forever** block. This will cause Motor 1 to run at half speed, forever!

![](https://cdn-learn.adafruit.com/assets/assets/000/055/000/medium800/makecode_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_5.jpg?1528154805)

Name and download the program, saving the .uf2 file to a directory you can easily find.

Then, plug the Circuit Playground Express (CPX) into you computer over USB (make sure to plug into the CPX USB port, not the one on the Crickit, which is used for occasional firmware updates) click the reset button on the CPX once to enter bootloader mode. Copy the .uf2 file to the CPX by dragging it to the CPLAYBOOT drive that appears.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/999/medium800/makecode_IMG_3373_2k.jpg?1528154606)

Make sure the battery pack is plugged into the Crickit, and that the Crickit's power switch is in the 'on' position.

When the Circuit Playground Express restarts, it will tell the Crickit to run the motor. It's alive!!

## Button Activation

It's convenient to set up start and stop buttons for the motor. We can use the two that are built onto the Circuit Playground Express.

From the **Input** category, add an **on button A click** block. Since we won't have the motor run forever anymore, drag the **crickit run motor** block out of the **forever** block and into the new button block. You can delete the **forever** block.

![](https://cdn-learn.adafruit.com/assets/assets/000/055/001/medium800/makecode_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_6.jpg?1528155050)

## Stop Button

Add another button block, this time changing the dropdown menu to **button B.**

From the **Crickit** category, add a **crickit stop motor** block to the **button B** block.

![](https://cdn-learn.adafruit.com/assets/assets/000/055/002/medium800/makecode_Banners_and_Alerts_and_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor.jpg?1528155164)

## Speed Control

What if we want to have a couple of different speeds to run the automaton? One way is to use the slide switch on the CPX to change the **crickit run motor** speed percentage between to preset values.

To do this we'll create a variable called **speed.** Then, we'll us this variable in place of the current fixed value of 50% that is in the **crickit run motor** block.

Our slide switch will change the value of the **speed** variable depending upon its position.

Click on the **Variables** category and **Make a Variable...** named **speed.**

![](https://cdn-learn.adafruit.com/assets/assets/000/055/003/medium800/makecode_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_7.jpg?1528156094)

Drag the **speed** variable to the **crickit run motor** block.

![](https://cdn-learn.adafruit.com/assets/assets/000/055/004/medium800/makecode_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_8.jpg?1528156160)

## Startup Speed

When the program starts, we need to specify the value of **speed** in case the button A is pressed before the slide switch it moved. From the **Loops** category, add an **on start** block. Then, drag from the **Variables** category a **set speed to** block and set the value to **40**.

![](https://cdn-learn.adafruit.com/assets/assets/000/055/005/medium800/makecode_Banners_and_Alerts_and_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_2.jpg?1528156339)

## Switch Control

Now, from the **Input** category, add an **on switch moved left** block. Duplicate the **set speed to 40** block by right clicking on it and choosing **Duplicate.** Drag this copy to the switch block.

![](https://cdn-learn.adafruit.com/assets/assets/000/055/006/medium800/makecode_Banners_and_Alerts_and_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_3.jpg?1528156478)

Duplicate the left swtich block, and change the dropdown menu item to **right.** Change the **set speed to** value to **80**.

![](https://cdn-learn.adafruit.com/assets/assets/000/055/007/medium800/makecode_Banners_and_Alerts_and_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_4.jpg?1528156544)

And there we have it! Download this .uf2 file and copy it to your Circuit Playground Express and now you'll be able to start and stop the automaton and run it at two different speeds. Note, you'll need to press the A button to activate the speed change after flipping the switch. Can you think of a way to adjust the program so this happens automatically when the switch is changed?

## NeoPixel Speed Indicator

Here's the program with a few blocks added from the NeoPixel category to show low and high speed colored indicators.

![](https://cdn-learn.adafruit.com/assets/assets/000/055/008/medium800/makecode_Banners_and_Alerts_and_Adafruit_Circuit_Playground_Express_-_Blocks___Javascript_editor_5.jpg?1528157364)

You can download this copy below if needed.

https://makecode.com/_64id8Chz7d94

Next, we'll connect the brains to the machine!

# Cam Follower Automaton

## Power the Automaton

![](https://cdn-learn.adafruit.com/assets/assets/000/054/962/medium800/makecode_IMG_3375_2k.jpg?1528150161)

## Indirect Drive Wheel
We'll couple the high-RPM DC motor and orange wheel to the cam shaft indirectly by resting the assembly on the large cardboard cam shaft wheel. To allow for irregularities in the surface, we'll have a single pivot, made from a toothpick, that holds the motor in place while still allowing it to pivot in compliance.

- Place the toothpick into the motor's mounting hole as shown
- Mark the position on the box that will allow it to rest on the large wheel
- Cut a small hole
- Push in the toothpick
- Slide the motor into place

![makecode_IMG_3376_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/967/medium640/makecode_IMG_3376_2k.jpg?1528150663)

![makecode_IMG_3377_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/968/medium640/makecode_IMG_3377_2k.jpg?1528150672)

![makecode_IMG_3379_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/969/medium640/makecode_IMG_3379_2k.jpg?1528150678)

![makecode_IMG_3380_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/970/medium640/makecode_IMG_3380_2k.jpg?1528150686)

![makecode_IMG_3381_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/971/medium640/makecode_IMG_3381_2k.jpg?1528150695)

That's all there is to it -- gravity will do the rest of the work!

![](https://cdn-learn.adafruit.com/assets/assets/000/054/972/medium800/makecode_IMG_3383_2k.jpg?1528150716)

## Mount the Crickit

To counterbalance the weight of the motor and wheels, we'll mount the Crickit, Circuit Playground Express, and batteries on the opposite side.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/981/medium800/makecode_IMG_3385_2k.jpg?1528151017)

- Hold the Crickit in place and mark holes to mount it to the box's side
- Use pipe cleaners or string to secure it in place
- Mark and affix the battery box underneath the Crickit

![makecode_IMG_3388_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/973/medium640/makecode_IMG_3388_2k.jpg?1528150811)

![makecode_IMG_3398_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/974/medium640/makecode_IMG_3398_2k.jpg?1528150877)

![makecode_IMG_3401_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/976/medium640/makecode_IMG_3401_2k.jpg?1528150923)

![makecode_IMG_3402_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/977/medium640/makecode_IMG_3402_2k.jpg?1528150933)

![makecode_IMG_3405_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/978/medium640/makecode_IMG_3405_2k.jpg?1528150944)

![makecode_IMG_3407_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/054/980/medium640/makecode_IMG_3407_2k.jpg?1528151003)

Plug the motor's wires into the Crickit's Motor 1 port as we did during programming.

![](https://cdn-learn.adafruit.com/assets/assets/000/054/983/medium800/makecode_IMG_3408_2k.jpg?1528151066)

![](https://cdn-learn.adafruit.com/assets/assets/000/054/986/medium800thumb/makecode_motorRunningCamAuto2.jpg?1528151384)

## Add Character

You can now choose what to move with your cam follower mechanism! A simple approach is to draw or print a character to affix to the rod.

Or, you can get a bit fancier and create a jointed character so that just and arm moves, or perhaps the stance of a cat made from pipe cleaners and googly eyes!

![](https://cdn-learn.adafruit.com/assets/assets/000/054/988/medium800/makecode_IMG_3424_2k.jpg?1528151891)

https://youtu.be/cyvmU7yZZRE

![](https://cdn-learn.adafruit.com/assets/assets/000/054/989/medium800/makecode_IMG_3444_2k.jpg?1528151907)

https://youtu.be/ofkF4-FkXtI


## Featured Products

### Adafruit CRICKIT for Circuit Playground Express

[Adafruit CRICKIT for Circuit Playground Express](https://www.adafruit.com/product/3093)
Sometimes we wonder if robotics engineers ever watch movies. If they did, they'd know that making robots into servants always ends up in a robot rebellion. Why even go down that path? Here at Adafruit, we believe in making robots our&nbsp; **friends!**

So if you find...

In Stock
[Buy Now](https://www.adafruit.com/product/3093)
[Related Guides to the Product](https://learn.adafruit.com/products/3093/guides)
### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### DC Gearbox Motor - "TT Motor" - 200RPM - 3 to 6VDC

[DC Gearbox Motor - "TT Motor" - 200RPM - 3 to 6VDC](https://www.adafruit.com/product/3777)
Perhaps you've been assembling a new robot friend, adding&nbsp;a computer for a brain and other fun personality touches. Now the time has come to let it leave the nest and fly on its own wings– err, _wheels!_&nbsp;

These durable (but affordable!) plastic gearbox motors...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3777)
[Related Guides to the Product](https://learn.adafruit.com/products/3777/guides)
### Orange and Clear TT Motor Wheel for TT DC Gearbox Motor

[Orange and Clear TT Motor Wheel for TT DC Gearbox Motor](https://www.adafruit.com/product/3766)
Usually when one needs an orange wheel&nbsp;it's a garnish for a cocktail, like a tasty Sidecar. And speaking of cars,&nbsp;this wheel **&nbsp;** is for driving, not drinking!

Need a great drive solution for&nbsp;your little robotic friends?&nbsp;This&nbsp; **Orange...**

In Stock
[Buy Now](https://www.adafruit.com/product/3766)
[Related Guides to the Product](https://learn.adafruit.com/products/3766/guides)
### Waterproof 3xAA Battery Holder with On/Off Switch

[Waterproof 3xAA Battery Holder with On/Off Switch](https://www.adafruit.com/product/771)
Keep your power source safe and toasty in these waterproof 3xAA battery holders. They're just like classic switched battery holders, but designed for survival! The case has a rubber gasket around the edge of the case (its black and hard to see in the photos but it is there) and attaches...

In Stock
[Buy Now](https://www.adafruit.com/product/771)
[Related Guides to the Product](https://learn.adafruit.com/products/771/guides)
### Male DC Power adapter - 2.1mm plug to screw terminal block

[Male DC Power adapter - 2.1mm plug to screw terminal block](https://www.adafruit.com/product/369)
If you need to connect a battery pack or wired power supply to a board that has a DC jack - this adapter will come in very handy! There is a 2.1mm DC plug on one end, and a screw terminal block on the other. The terminals are labeled with positive/negative assuming a positive-tip configuration...

In Stock
[Buy Now](https://www.adafruit.com/product/369)
[Related Guides to the Product](https://learn.adafruit.com/products/369/guides)
### Alkaline AA batteries (LR6) - 3 pack

[Alkaline AA batteries (LR6) - 3 pack](https://www.adafruit.com/product/3521)
Battery power for your portable project! These batteries are good quality at a good price, and work fantastic with any of the kits or projects in the shop that use AAs. This is a pack of **3 AA batteries**.  
  
These batteries are Alkaline (MnO2) chemistry, with a voltage...

In Stock
[Buy Now](https://www.adafruit.com/product/3521)
[Related Guides to the Product](https://learn.adafruit.com/products/3521/guides)

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [Creating and sharing a CircuitPython library](https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library.md)
- [CPU Temperature Logging with CircuitPython](https://learn.adafruit.com/cpu-temperature-logging-with-circuit-python.md)
- [Circuit Playground Musical Glove](https://learn.adafruit.com/cpx-musical-glove.md)
- [Affordable HAL 9000 Replica](https://learn.adafruit.com/hal-9000-replica.md)
- [Mini Golf Course with Circuit Playground and Crickit](https://learn.adafruit.com/mini-golf-course-with-makecode-circuit-playground-crickit.md)
- [Bunny Ears with MakeCode](https://learn.adafruit.com/bunny-ears-with-makecode.md)
- [Circuit Playground Express Rocket Lamp](https://learn.adafruit.com/cpx-rocket-lamp.md)
- [Mason Jar Snow Globe](https://learn.adafruit.com/snow-globe-makecode.md)
- [Circuit Playground Bike Glove](https://learn.adafruit.com/circuit-playground-bike-glove.md)
- [Make It Pulse](https://learn.adafruit.com/make-it-pulse.md)
- [Make It Hot or Cold](https://learn.adafruit.com/make-it-hot-or-cold.md)
- [Circuit Playground Express Sugar Glider](https://learn.adafruit.com/cpx-sugar-glider.md)
- [Crickit Powered Minerva Owl Robot](https://learn.adafruit.com/crickit-powered-owl-robot.md)
- [Circuit Playground Seashell Pendant](https://learn.adafruit.com/circuit-playground-seashell-pendant.md)
- [Controlling a Classic Nintendo R.O.B. Robot Using Circuit Playground Express](https://learn.adafruit.com/controlling-a-classic-nintendo-r-o-b-robot-using-circuit-playground-express.md)
