Wouldn't you like to have a best buddy by your side at the workbench? Someone to keep your spirits up and give you positive feedback while you work on your electronics? (Ok well maybe not the positive feedback part...)

Here we'll be building a Sparky the Blue Smoke Monster robot friend! He'll be there when you put the chip in backwards, swap power and ground, or forget the decoupling cap. You might be a little crestfallen when you let the blue smoke out of your chips, but at least you have someone by your side.

This project shows you how to build a talking automaton using cardboard, popsicle sticks and some other household materials, paired with Adafruit's CRICKIT for Circuit Playground Express and a micro servo motor.

Project Parts

Household materials you will need

  • Scotch tape
  • Glue stick
  • Double sided foam tape
  • Pieces of cardboard (one 8.5" x 11", one 3"x6")
  • 2 sheets printer paper
  • Popsicle stick
  • Scissors or X-acto knife

Materials from Adafruit

1 x Circuit Playground Express
Circuit Playground Express is the perfect introduction to electronics and programming
1 x Adafruit CRICKIT for Circuit Playground Express
Creative Robotics and Interactive Construction Kit is an add-on to our popular Circuit Playground Express that lets you #MakeRobotFriend using CircuitPython
1 x Micro Servo
This little servo can rotate approximately 180 degrees (90 in each direction). Works just like standard servos you're used to but smaller.
1 x USB cable - A/MicroB - 3ft
Standard A to micro-B USB cable
1 x Mini Metal Speaker
1" diameter speaker cone with an 8 Ω impedance and 0.5W or less of power draw.
1 x 3 x AA Battery Holder
With On/Off Switch, JST, and Belt Clip
1 x Male DC Power adapter
2.1 mm plug to screw terminal block
1 x Alkaline AA batteries - 3 pack
These batteries are good quality at a good price, and work fantastic with any of the kits or projects that use AAs.

If your Circuit Playground Express and CRICKIT aren't already connected, now is the time to do that.

The animation below demonstrates how the two become one.

First, download the image of Sparky by clicking on the green box below. Print out two copies. We'll use the second copy to create his mouth.

Next, you'll need some pieces of cardboard, scissors, and a glue stick.

For best results, add glue to both the paper and the cardboard. 

 

Place Sparky on cardboard base. Press these two together firmly, smoothing out any creases. 

 

Cut out Sparky's teeth from second printout. Glue this jaw to a small piece of cardboard.

It can be helpful to place Sparky under a very heavy book (or multiple smaller books, etc.) while the glue dries. 

After waiting for about 10-15 minutes for the glue to dry, you're ready to start cutting the outline!

Cut out Sparky's blue-flame outline.

 

Cut around the outline of the jaw.

 

Outline a slot on Sparky's chin through which the jaw will be attached.

 

Cut out the slot in Sparky's chin carefully with points of scissors or an X-acto blade.

Now it's time to give Sparky a place to stand. An Adafruit packing box is great for this purpose (but any box or other cardboard will be fine). This will also provide a place to house the electronics and make Sparky portable.

Cut out two supports to hold up Sparky. Trim the corners just enough so that they don't extend off the back of the box.

 

IMPORTANT: Use your servo to measure the distance from the the hole to where you'll place the right support. Add a little extra distance to account for the thickness of the foam tape.

 

Allow the supports to extend beyond Sparky's outline by about 1 inch. This will give clearance for the mouth to move.

 

Tape supports firmly in place. 

Now Sparky is ready to be mounted on his box.

Add strips of tape to the bottom of the supports.

 

Align the back edge of the box with the back edges of the supports, and tape Sparky in place.

 

Cut a small hole in the space between the supports. This hole will allow you to thread the motor cable into the box and store the electronics inside.

 

Now you're ready for the next step! Onwards!

Start by (CAREFULLY!) chopping off one end of your popsicle stick.

 

Position the mouth where you'd like it on Sparky.

 

Then, holding it carefully in place, flip it over and mark the location where you'll attach the popsicle stick.

 

Tape popsicle stick in place. It's OK to use lots of tape.

Calibrating the Servo

This servo can only rotate about 180 degrees back and forth. When we create that slot, we limit it to about 10 or so degrees. Because of this, it's important that we find the limits so we can avoid damaging the motor or our automaton.

Take the servo arm and place it on the servo horn. Use the arm to rotate the motor until you find its extents (limits). 

 

Find the middle zone, the spot where you can rotate the arm about 90 degrees in either direction. This is where we want it! 

 

You can now remove the arm from the servo motor.

Attach the Servo

Add some small strips of double sided foam tape to the base of the motor and the top of the servo arm.

 

Stick the servo motor to the inside wall of the support leg, making sure to position it in the middle of the slot.

 

Remove the covering from the tape on the servo arm. Place the popsicle stick attached to the mouth through the slot and affix it to the servo arm.

A battery pack supplying 4.5V can be connected to make Sparky portable.

Connecting the Servo to CRICKIT

Connect your servo to CRICKIT on the Servo group of pins position 1. The orange wire towards the front, the brown or black wire towards the Circuit Playground Express.

Make sure 4.5 to 5 volt power is supplied via the DC jack on CRICKIT and the Circuit Playground Express is connected to your computer with the micro USB cable.

Now we're ready for some code!

If you haven't used MakeCode before, this guide is a good place to start.

Noise Activated!

This example demonstrates how to make Sparky's mouth move in response to noise. MakeCode doesn't currently have a way to play back sounds from wav files. So instead, we'll make the sounds and Sparky will 'talk' along!

MakeCode is used to turn the microphone on your CPX into a trigger for the servo motor. 

But before you move on...

...you will need to make sure you have the CRICKIT extension installed in MakeCode. Detailed instructions on how to do that can be found in this guide.

Once you've got that taken care of, get the Makecode below or via this link.

What's going on here?

This block of code tells the Circuit Playground Express that sits on top of CRICKIT to use its microphone to listen for sounds above a certain loudness threshold.

If it hears a noise, it's told to move the servo motor back and forth between 100-80 degrees.

There are also a couple pause 100ms placed in the code to help smooth out the motion of the motor.

Before testing this code for the first time, remove the mouth from the servo horn!
Be sure you use the Servo blocks under the CRICKIT group and NOT the Servo blocks under the PINS block group!

Making changes

You can change the value in the if sound level > 10 then to change how sensitive Sparky is to noises. 

Decrease it to 1 and he'll start chattering at even the slightest whisper.

Increase it to 100 and it'll take a loud clap to set Sparky off.

The default value of 10 is already quite sensitive, even quiet sounds like tapping on his box will make Sparky start chattering. 

If you'd like to make Sparky portable, you can use 3 AA batteries in a battery pack as a power supply. This should provide power to Sparky for about 3 hours of continuous interaction. 

Troubleshooting

Problem: My servo isn't moving!

Solution: Make sure you have 5V power connected and that the small slide switch on the CRICKIT is set to "ON".

 

Problem: My Circuit Playground Express doesn't show up as CPLAYBOOT!

Solution: Your Circuit Playground Express board comes ready to work with CircuitPython, and will show up on your computer as a flash drive named CIRCUITPY when the Circuit Playground Express is connected via USB. To switch over to work with MakeCode, connect the board to your computer with a micro USB cable and click the small reset button in the center of the board.  

When the Circuit Playground Express is in Bootloader mode, all the LEDs will turn red briefly, then green. Verify your status LED is also pulsing redYour computer should show a new removable drive called CPLAYBOOT. Now you can copy the MakeCode file to the CPLAYBOOT flash drive.

Exploring further

If you enjoy MakeCode and want to continue exploring you can check out lots more MakeCode projects on the Adafruit Learn System.

This example demonstrates how to attach a speaker to CRICKIT to make Sparky talk.

Getting Familiar

This uses CircuitPython, which requires installing Mu. If you haven't previously used Mu, this guide will get you started.

CircuitPython is a programming language based on Python, one of the fastest growing programming languages in the world. It is specifically designed to simplify experimenting and learning to code on low-cost microcontroller boards.

If you haven't used Circuit Playground Express with CRICKIT before, make sure you've updated it with the latest special 'seesaw' version of the CPX firmware. This guide will show you how.

Mount the speaker

Time to give Sparky a voice. This small 0.5 Watt speaker is just right, although larger 4 and 8 ohm speakers work also.

Cut out a small square of double sided foam tape.

 

Use this to stick the speaker to the outside edge of the box. 

 

Then connect the speaker wires to CRICKIT as depicted.

Connect the speaker wires to CRICKIT as shown in the diagram below.

Audio Files

Click the button below to download a collection of audio clips for Sparky.

Unzip, then drag and drop these audio clips onto your CIRCUITPY drive.

If you want to create and use your own wav files, see this guide to ensure they are formatted for playing on CRICKIT.

Load the Code

The CircuitPython code for this project is available below.

Copy and paste this code into your Mu editor.

Save the code to your CIRCUITPY drive in your computer's file exploration program as code.py.

# SPDX-FileCopyrightText: 2018 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import os
import time
import random
import board
import audioio
import audiocore
from adafruit_crickit import crickit

# Sparky automaton

# Find all Wave files on the storage
wavefiles = [file for file in os.listdir("/")
             if (file.endswith(".wav") and not file.startswith("._"))]
print("Audio files found: ", wavefiles)

# mouth servo
mouth_servo = crickit.servo_1
# TowerPro servos like 500/2500 pulsewidths
mouth_servo.set_pulse_width_range(min_pulse=500, max_pulse=2500)

# Servo angles
MOUTH_START = 100
MOUTH_END = 90

# Starting servo location
mouth_servo.angle = MOUTH_START

# Audio playback object and helper to play a full file
a = audioio.AudioOut(board.A0)

# Play a wave file and move the mouth while its playing!
def play_file(wavfile):
    print("Playing", wavfile)
    with open(wavfile, "rb") as f:
        wav = audiocore.WaveFile(f)
        a.play(wav)
        while a.playing:  # turn servos, motors, etc. during playback
            mouth_servo.angle = MOUTH_END
            time.sleep(0.15)
            mouth_servo.angle = MOUTH_START
            time.sleep(0.15)

while True:
    # Play a random quip
    play_file(random.choice(wavefiles))
    # then hang out for a few seconds
    time.sleep(3)
Make sure the file saved to CIRCUITPY is named "code.py", this will allow it to run automatically when your CPX is powered on.

How The Code Works

We start by importing all our helper libraries

import os
import time
import random
import board
import audioio
import audiocore
from adafruit_crickit import crickit

Then we look on the little flash drive with os.listdir("/") to find all ".wav" audio files. We have a check to make sure we don't include any "._" files, these are special macOS files we ought to ignore

# Find all Wave files on the storage
wavefiles = [file for file in os.listdir("/")
             if (file.endswith(".wav") and not file.startswith("._"))]
print("Audio files found: ", wavefiles)

We get from the crickit library access to the Servo #1 port, where we have our micro-servo plugged in. The tiny TowerPro SG-9x servos we're using work best with a 500us to 2500us pulse width, so we let the servo know that.

Then we define some helper variables for the angles that correspond to where the mouth starts and ends when the automaton speaks:

# mouth servo
mouth_servo = crickit.servo_1
# TowerPro servos like 500/2500 pulsewidths
mouth_servo.set_pulse_width_range(min_pulse=500, max_pulse=2500)

# Servo angles
MOUTH_START = 100
MOUTH_END = 90

# Starting servo location
mouth_servo.angle = MOUTH_START

Our helper function play_file will use the audio capabilities of the CircuitPlayground to play the audio file. As it is playing we also move the servo up and down by assigning mouth_servo.angle to those helper variables above! When the audio is done, the servo stops moving

# Audio playback object and helper to play a full file
a = audioio.AudioOut(board.A0)

# Play a wave file and move the mouth while its playing!
def play_file(wavfile):
    print("Playing", wavfile)
    with open(wavfile, "rb") as f:
        wav = audiocore.WaveFile(f)
        a.play(wav)
        while a.playing:  # turn servos, motors, etc. during playback
            mouth_servo.angle = MOUTH_END
            time.sleep(0.15)
            mouth_servo.angle = MOUTH_START
            time.sleep(0.15)

Finally, in our loop we will play a random wavefile that we found on the disk and then pause in between.

while True:
    # Play a random quip
    play_file(random.choice(wavefiles))
    # then hang out for a few seconds
    time.sleep(3)

Save and Run!

Your CIRCUITPY drive should include the code file and audio files. 

If you have all these covered, you're ready to rock with Sparky!

Troubleshooting

Problem: My Circuit Playground Express isn't recognized by Mu!

Solution: Make sure your board is set up with CircuitPython, which has the Circuit Playground Express show up as a flash drive named CIRCUITPY when you connect the CPX to your computer. If it is showing up as CPLAYBOOT on your computer, you can follow the steps in this guide to ensure CircuitPython is loaded and you see the CIRCUITPY drive.

 

Problem: My motor isn't moving! 

Solution: Make sure you've updated your Circuit Playground Express with the latest special 'seesaw' version of the CPX firmware. This guide will show you how.

Exploring further

If you enjoy CircuitPython and want to continue learning you can find lots more CircuitPython projects on the Adafruit Learn System.

This guide was first published on Jun 21, 2018. It was last updated on Mar 28, 2024.