Reciprocating Rack and Pinion

Learn how to create an automated geared mechanism with hypnotic motion. Use the Adafruit CRICKIT and Circuit Playground Express to make it dance! This is a mechanism for converting rotary motion to linear oscillating motion. The gear appears to bounce back and forth as it continuously rotates. As the wheel spins, the gear turns and oscillates between two tracks. It emits clacks and sloshes sound while in motion creating the sense of white noise. The teeth engage the lower track as it rotates. When it has travels the length of the slot, the teeth clears the end of the track and catches the teeth in the upper part of the track.

Make Robot Friend

Use Microsoft MakeCode to program the motor and use the on-board sensors from the Circuit Playground Express to make an interactive robot. This project was inspired by Ron Walters Reciprocating Rack and Pinion mechanism build.

Circuit Playground Express is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and...
In Stock
Sometimes we wonder if robotics engineers ever watch movies. If they did, they'd know that making robots into slaves always ends up in a robot rebellion. Why even go down that...
In Stock
Perhaps you've been assembling a new robot friend, adding a computer for a brain and other fun personality touches. Now the time has come to let it leave the nest and fly on...
In Stock
Here's another addition to our growing family of AA battery holders. A holder for three (3) AA batteries!...
In Stock


We'll need just a 3xAA battery pack to power our CRICKIT robot. 

1 x 3 x AA Battery Holder
Battery Pack with 2.1mm Plug


You'll need some extra hardware like machine screws, nuts and threaded inserts to assemble this project. They're linked below, but feel free to source them from your favorite supplier.

2 x M3 x 20mm Metric Machine Screws
For mounting the motor to the housing.
6 x M3x 16mm Metric Machine Screws
For bolting the tracks, base and feet together.
3 x M3 x 6mm Metric Machine Screws
For the wheel, pin and drive hub parts.
10 x M3 Metric Hex Jam Nuts
For securing parts together.
1 x M3 Threaded Insert – Brass Knurled
Heat press insert to center pin for drive hub assembly.
1 x M3 Metric Screw Tap
Coarse Thread Taper Taps
2 x Goggly Eyes
25mm (1in) diameter – Assortment Pack

Prerequisite Guides

There's resources in these guides that go beyond what's covered in this tutorial. MakeCode guide is all about setting up your Circuit Playground Express board. TheCircuit Playground Express introduction guide walks you through all of the pinouts, sensors and everything you need to know.

3D Printed Parts

The mechanism is comprised of 3D printed parts that are bolted together. Parts are layers together to form the tracks. Each part is listed with a description of what they do. Parts with mounting holes will need to be tapped with M3 threads using a screw tap. 

Parts List


Base plate contains slot for pinion and mounting holes. 


Toothed track for the wheel.  Features eye sockets.


Features slot for motor housing.


Geared wheel with seven teeth. Attaches to center pin with screw.


Symmetrical foot stand. Print two of these.


Pin is secured to the drive hub.


Drive hub is press fitted into motor shaft.


Housing for TT Motor. Slides along motor track.


The material used in this printed are 2.85mm PLA from Melt Ink 3D. The colors are the neon blue, magenta pink, aqua, orange, light green and yellow. This filament diameter is typically used for Ultimaker and Lulzbot 3D printers.

CURA Slicing

This project was sliced using Ultimaker's CURA. Use the slice settings as reference. Settings may need to be adjust for tolerances. Print parts independently for best results. Test fit parts before full assembly. Parts tested with PLA filament using Ultimaker 3.


  • 0.4mm nozzle for standard quality
  • 0.2mm layer height
  • 0.38mm line width / 2 wall line count 
  • 60mm/s printing speeds

Download STLs

You'll need an STL file to 3D print the mount for the circuit playground express. Click the button below to download the STL from your choice of repo site. 

Design Source Files

The enclosure assembly was designed in Fusion 360. This can be downloaded in different formats like STEP, SAT and more. Electronic components like the board, displays, connectors and more can be downloaded from our Fusion 360 CAD parts github repo.

CAD Assembly

We designed the mechanism in Autodesk Fusion 360. The assembly is made up of components that are parametrically driven. This CAD animation demonstrates how all the pieces fit together. The design source is free download so you can build your own, links are in the description.


The mount for the CRICKIT was designed in a previous project. It's a general, multi-purpose mount designed to house the CRICKIT PCB with M3 machine screws. Check out the learn guide for the files, assembly info and more. Download Mount for CRICKIT

What If I Don't Have A 3D Printer?

Not to worry! You can use a 3D printing service such as 3DHubs or MakeXYZ to have a local 3D printer operator 3D print and ship you parts to you. This is a great way to get your parts 3D printed by local makers. You could also try checking out your local Library or search for a Maker Space.

The Ultimaker 2+ is one of our favorite 3D printers on the market. It's a well-built open-source compact machine with an excellent UX. Every inch of the...
Out of Stock

MakeCode for CRICKIT // Circuit Playground Express

MakeCode is this programming editor that runs in the Google Chrome web browser. It’s has an intuitive interface that’s both block based and text editor.

It works with Adafruit's CRICKIT and Circuit Playground Express so you can make interactive projects with the on-board sensors and components. You can drag & drop blocks to make interactive programs using lights and sounds without having to solder or learning a new syntax.

You can upload code directly to the Circuit Playground Express with WebUSB is you use the information in the MakeCode tutorial WebUSB page.

Setup Circuit Playground Express for MakeCode

To get started, we'll need to head over to the Adafruit MakeCode website and follow the steps below.

  1. Plug in your Circuit Playground Express with a USB Cable
  2. Press the RESET button. Green light means you're ready to MakeCode
  3. Download the UF2 file and drop it onto CPLAYBOOT.

Install CRICKIT Extension for MakeCode


On the makecode site, click on New Project. In the list of blocks, select ADVANCED and then EXTENSIONS. Click on the Crickit block that shows up and install Crickit support! You will now have a new CRICKIT bin of blocks you can use! Continue on to learn how to use these blocks. Read the full guide here for more info.

Upload and Test Code

Once you have your CPX setup with the MakeCode UF2, try testing it out by uploading the code to the board. Click the link below to open up the program in makecode. Click on the pink edit icon near the top of the title to open the code. This will create a project in MakeCode and allow you to edit, modify and upload the code to the board. 

Motor Speed Controller MakeCode Program


The program uses motor blocks to control the speed of a motor. When the A or B buttons on the Circuit Playground are pressed, the motor speed changes. Each button press incrementally changes the speed of the motor. In the program, a motorSpeed variable is used to reference a value and changes on an action. The values are positive and negative numbers that are used to set the speed of the motor or brightness of the NeoPixels. 

Using Variables


We're used two variables, brightness and motorSpeed. The titles are self explanatory in which they'll be used. To create a variable, used the "Make a Variable" button under the Variable menu. Each variable block features a set and change block that can be used to adjust values.

Forever CodeBlock


In the forever code block, we have a crickit run motor and set brightness code block. These contain variables, indicated by the pink color blocks. Each is associated to their own type, motorSpeed for crickit run motor and set brightness for NeoPixels.

On Start CodeBlock


Use the set variable code blocks to set the brightness and motorSpeed on start. We can have it start fast or slow, depending on how we'd like the behavior to preform when we boot up the CRICKIT board. We can also set the color of NeoPixel.

On Change Variables


Use the on blocks to setup which buttons to activate the motor speed and neopixel brightness. Button A and B are used in this project. The change variable code block will set a given value whenever button A or B are pressed. The negative values are used to reduce the speed and brightness. Max value for brightness is 255. Max value for motor is 100.


Motor Assembly

To start, we'll work on securing the DC geared motor to the motor housing. We'll need 2x M3 x 25mm long screws and 2x hex nuts. These screws are extra long to accommodate for the size of the motor body.

Install Motor Mount

Place the motor housing over the body of the motor and try to line up the mounting holes. The motor shaft should fit through the center hole. Can figure out which side of the motor to use? Try looking for the side with the protruding nub right below the motor shaft. While holding them together, insert and fasten the long screws through the housing and body of the motor. You may use a power drill to speed things up as they're quite long screws.




Secure Motor

The screws should be long enough to protrude from the back of the motor. Place and fasten the hex nuts to the remaining threads and use pliers to tighten them in place. A third screw, (M3 x 25) can be inserted and fastened through the remaining mounting hold near the top of the motor shaft. This can be installed through the housing and tab on the motor.



Drive Hub Parts

Set the motor aside and gather the drive hub parts and screws. We'll need the drive hub and the pin. 2x M3 x 6mm screws will be used to secure the two parts together. An M3 threaded insert and screw will be used to secure the drive hub assembly to the geared wheel.

Heat Press Threaded Insert

We'll need to install an M3 threaded insert into the center hole of the pin. I used the tip of a soldering iron to do this. Tack the pin down on a flat surface and place the insert on top of the hole. Slowly insert the tip of the iron through the insert and press down until flush. Be as straight as possible. Check all angles to ensure its installed straight. Allow to cool for a moment before refitting.

Installed Threaded Insert

The thread should be permanently secured in place. Test out the threads by inserting a short M3 screw. It should be straight and easy to fasten. We'll use this setup to secure the geared wheel to the pin. This will keep the wheel from flying off the track when in motion.



Secure Hub to Pin

Start by inserting and fastening the two screws through the mounting holes on the pin. Flip it over and place the drive hub onto the screw threads. Both parts should be jointed at the flat surface. Screw heads should be recessed. While holding them together, fasten to join parts together. Use hex nuts to tighten and secure parts in place.




The threaded insert is not present in the first photo but it should be there when installing!

Install Drive Hub to Motor

With the drive hub assembled, grab the motor and line up the hole in the hub with the motor shaft. Carefully press the drive hub onto the shaft of the motor. If it's too loose, the drive hub won't stay put. If it's too tight, it'll be very hard to remove. Options are to use a filing tool to loose up, or reprint with different slice settings. Using glue or other adhesives is also an option. 




Note, the motor housing has been removed in these photos for clarity – It should still be attached in your build!

Assembled Motor Box

The flange of the drive hub should be flush with the motor housing. If not, you may need to press the drive hub more to fully seat. With the motor box fully assembled, we can work on building the track next.

The threaded insert should be installed in your assembly!

Install Eyes

Grab the rack part and two 25mm diameter goggly eyes. These can be press fitted into the eye sockets. The eyes should click and stay put. If they're too lose, use a bit of super glue to keep secure it in place.

Layers Tracks

To form the track assembly the base, motor tack and wheel track are bolted together with screws. Grab these parts and layer them to form the track assembly. Start with the motor track. Place the base over it. Make sure the mounting holes are lined up. Then, lay the wheel track over the base. Again, making sure mounting holes are lined up. 

Make sure the mounting holes are lined up! Use the three holes near the bottom as a reference guide.

Secure Tracks

With the three plates now aligned together, insert a screw into one of the mounting holes – Going through the top track layer first. Slowly turn by hand at first. Lead the screw through and follow the tapped threads of each part. Use a screw driver to fasten the screw through the three pieces. Optionally use a power drill to speed this up once you get a nice flow going.




Secure Tracks

You'll want to be sure to drive the screws into the holes as straight as possible. If the screw gets stuck, back it out slowly, realign and fasten again. Having the mounting holes tapped with a coarse threaded tapping tool improves the joinery greatly.

Stand Installation

We'll need two M3 x 16mm screws to secure the stands to the track assembly. Gather up your hardware and let's get fastening!

Secure Stand

The two tabs on the stand has mounting holes that line up with remaining holes in the track assembly. Press the tabs onto the lower bottom of the track assembly and adjust to line up the holes. Straight out the alignment and square it up. Insert and fasten a screw through the tabs and track assembly. 




Installed Stands

The entire length of the screw should go through the whole assembly. Use a hex nut if longer screws were used. 

Motor Wheel Assembly

Now it's time to put the motor and wheel together. We'll need the motor assembly, geared wheel and track assembly.

Registration Key

If we look at the center of the geared wheel there's a recessed hexagon shaped cavity. This allows the pin to snap onto the wheel. The top of the pin features a hexagonal shape that keys into the wheel. This ideally should have a tight fit and could be used "as it" but we'll use a screw and threaded insert to secure these piece together. It'll help ensure the wheel doesn't pop off while in motion!

Install Motor and Wheel

Place the motor housing onto the motor track. The pin from the motor should pass through the slot. If it doesn't, turnover the motor housing until it fits. The pin should protrude through the base. Place the geared wheel over the pin and rotate until the registration lines up with the key on the pin. Press them together to install the wheel to the pin. 




Secure Wheel

Check the placement of the wheel and ensure it's on straight and level with the track. Rotate the wheel if needed. The thin circles on the wheel should just barely touch the base. Insert a short M3 x 6mm screw through the wheel and drive it through the threaded insert in the pin.

Test Track

With the wheel now secured to the pin, you should be able to test out the mechanism. Start by moving the motor all the way to the left and rotating the gear counter-clockwise until it stops on the first tooth of the lower track. Then, rotate the wheel clockwise until the teeth engage the lower track. If you gently push the motor along the track, back and forth steadily, the gear should rotate following the tracks. 

Connecting Motor Wires

The wires from the motor are secured to the screw block terminals on the motor section of the CRICKIT board. You can use a jumper cable extension to extend the motor wiring. This way you can easily connect the wires from the motor.

Screw Block Terminals

Use the motor section of the CRICKIT to connect the wires. Two input blocks are labeled. The far most block is positive (red wire) and the middle is for ground (black wire). The pins from the jumper cables are inserted into the blocks and fastened with a screwdriver. 

Smooth Gear Motion

Getting smooth and consistent motion of the gear was difficult to achieve when prototyping. The gear would often jam into the teeth and lock in place. To prevent this from happening, the wheel is raised away from the surface of the base with the aid of thin concentric rings. These minimize the amount of friction introduced by mating surfaces.

This guide was first published on Aug 08, 2018. It was last updated on Aug 08, 2018.