In this project we’re making a motion activated gift box using Adafruit Crickit and Circuit Playground Express.

This holiday themed box moves around the floor as it makes creepy sounds and lights.

 

It uses a PIR motion sensor to detect movement and a TT motor to spin a wheel. It also triggers lights and sounds making this an interactive gift box.

 

With Adafruits Crickit robotics platform, you can program with Circuit Python.

 

Use a cardbox and scraps to house the components and get crafty with the decorations.

 

It's easy to prototype with cardboard and paper crafts to make a unique gift box that you can customize!

Parts

 

You can find the list of all parts used to make this project linked below!

 

We used Circuit Python and programed our Gift Box to activate when the PIR sensor detects any moment. You can use the on-board sensors on the Circuit Playground Express to make it even more  interactive!

 

3D Printed Parts

 

Although not require, our 3D printed mount is design to easily mount the Crickit to a battery 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.

1 x Adafruit Crickit for CPX
Robotics Platform
1 x Circuit Playground Express
Perfect introduction to electronics and programming
1 x PIR Motion Sensor
PIR sensors are used to detect motion from pets/humanoids from about 20 feet away
1 x Speaker
4ohm 3w 40mm diameter
1 x TT Motor
DC Gearbox motor - 200RPM
1 x Motor Mount for TT Gearbox DC
L-Bracket for DC Motor
1 x Wheel for TT Motor
Skinny wheel with rubber track
1 x Battery Holder
3x AA Battery holder with 2.1mm plug
1 x Alligator Clips
6pc small alligator clip to male jumper wire
1 x Jumper Wires
Premium female/male extension 20 x 3"
1 x Jumper Wires
female/male extension jumper wires 40 x 6"

Circuit Diagram

This provides a visual reference for wiring of the components. They aren't true to scale, just meant to be used as reference. This diagrams was created using Fritzing software.

Adafruit Library for Fritzing

Use our Fritzing parts library to create circuit diagrams for your projects. Download the library or just grab the individual parts. Files are hosted on our github repo linked below.

Connections

Motor

We used male to female jumper wires to easy connect and disconnect the Crickit from the motor.

Connect each wire to the number 1 terminal on the Crickit's Motor terminal block.

Battery

The  3xAA battery case connects to the barrel port on the Crickit and is mounted to the bottom side of the printed lid or secured to the bottom the the Crickit with foam tape.

Speaker

Use two Alligator clip to Jumper wires to connect the speaker terminals. Attached the alligator clips to the two tabs on the speaker and the jumper ends to the Crickit Speaker terminal blocks.

 

Passive Infrared Sensor (PIR)

 

Set the Jumper on the back of the PIR sensor from H to L.  The sensor connects to the 5v terminal on the NeoPixel side, while the GND and Signal connect to the 1 header on the Signal I/O side of the Cricket.    

CircuitPython

The Adafruit Crickit and Cricuit Playground Express can run CircuitPython for programming fast and easy to read code. Use the special Crickit CPX build firmware and follow the learn guide for setting up the board. This special build includes libraries so it saves space and gets you quickly up and running.

Upload Python Code

We recommend using the Mu editor for writing your python code. It's a simple Python editor for beginner programmers. Follow the Introductory Guide to CircuitPython to learn how to setup Mu.

Code

The code is below. You can use the download link to get a copy.

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

# NeoPixels on the Circuit Playground Express
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.3)
pixels.fill(0)                # Off to start

# PIR sensor on signal #1
PIR_SENSOR = crickit.SIGNAL1
crickit.seesaw.pin_mode(PIR_SENSOR, crickit.seesaw.INPUT)

# Set audio out on speaker
speaker = audioio.AudioOut(board.A0)
audio_files = ["evillaugh3.wav", "laugh.wav"]

# One motor
motor_1 = crickit.dc_motor_1
motor_1.throttle = 0             # off to start

while True:
    pixels.fill(0)
    print("Waiting for trigger")
    while not crickit.seesaw.digital_read(PIR_SENSOR):
        pass
    print("PIR triggered")
    pixels.fill((100, 0, 0))    # NeoPixels red

    # Start playing the file (in the background)
    audio_file = open(random.choice(audio_files), "rb")   # muahaha
    wav = audiocore.WaveFile(audio_file)
    speaker.play(wav)

    # move motor back and forth for 3 seconds total
    timestamp = time.monotonic()
    while time.monotonic() - timestamp < 3:
        motor_1.throttle = 1        # full speed forward
        time.sleep(0.25 + random.random())  # random delay from 0.25 to 1.25 seconds
        motor_1.throttle = -1        # full speed backward
        time.sleep(0.25 + random.random())  # random delay from 0.25 to 1.25 seconds
    motor_1.throttle = 0        # stop!

    # wait for audio to stop
    while speaker.playing:
        pass
    # clean up and close file
    audio_file.close()

Audio Sounds

You will need to provide your own audio files. In the code, on line 18, audio_files defines the file names. Modify this to reflect the audio files you'd like to use. The audio files will need to be in the following format.

  • WAV, Mono PCM, 11.025kHz   

Royal free sounds can be sourced from https://freesound.org/.

See this guide on how to convert audio formats for microcontroller projects.

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

Not to worry! You can use a 3D printing service or a local 3D printer operator to 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.

Slice Settings


These settings are for a 0.4mm and 0.8mm nozzle profiles using CURA 3.4.1. Optimized for the Ultimaker 2/3.

  • Nozzle .4mm 
  • Layer Height .2mm
  • Line Width .38 to .4mm
  • Print Speed 50mm/s or 70mm/s
  • Retraction 6.5mm
  • Build plate adhesion type – skirt
  • Bed 60c
  • No supports

Fusion 360 files 

Below are links to modify the design of the enclosure, noodle size and motor parts to fine tune them to adjust to your printer tolerances.

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.

Trace Components

 

We can use any box that can accommodate all of the components. Standard Adabox size (9.5x2.5x6.5) will work perfectly! 

 

Start by tracing the Crickit board in the back corner of the box, with the power barrel arranged as shown in the picture. Next we'll trace a TT motor with the wheel attached, slight off center on the opposite side of the box. 

 

Wheel Cutout

 

Use a sharp hobby knife to cut away at the wheel section of the traced outline. Fit the motor and wheel over the cutout and make sure the wheel can freely spin without touching any of the sides.

Attach and Trace Bracket

 

Next we'll need to temporarily attach the bracket and trace it over our previous outline.

 

After tracing the outline, remove the bracket and outline the mounting holes. 

 

Use M3 screws to create threads in the box. Create the hole so it only reaches the first layer of the box. 

 

Bracket Standoff

 

To securely mount the motor and elevate the wheel, we'll need to create a standoff for the bracket.

 

We'll trace the cardboard pieces using the bracket as a reference and then glue the pieces to the box as shown.

 

Allow the glued parts to dry before mounting the bracket and motor.

Mount the TT Motor

 

Next we can move on to mounting the motor back on to the bracket. 

 

Use the longer screws and nuts that are included with the bracket to secure the motor.

 

Once the nuts and screws a tightened, attach the wheel by inserting it at an angle.

Battery Mount

 

If you don't have access to a printer, we can simply use foam tape to attach the battery pack to the bottom of the Crickit.

 

A detail look at assembling the 3D printed Crickit Mount can be found here: https://learn.adafruit.com/mount-for-crickit/3d-printing#step-6

 

Thread the wires through the frame and use the included M3 screws to mount the 3xAA battery case to the bottom of the mount.

 

We'll need additional M3x6mm screws to mount the Crickit to the 3D printed mount.

Connect Components

 

Follow the circuit diagram to correctly wire each component to each terminal on the Crickit.

Infrared Sensor Mount

 

Now we can create the cut away to flush mount the PIR sensor to the side of the box.

 

Measure a circle with 55.8mm (2.2in) radius and create a template to trace on to the side of the box as shown in the picture.   

 

If using an Adabox, we can add the cutout over the "d" to align it to the center of the box.

 

Use a hobby knife to create the cutout and then press fit the PIR lens into place.

Ribs

 

We used scraps of cardboard to create boarders around the speaker and Crickit. This will help prevent the components from shifting around the box during movements.  

 

Position the speaker in the front corner and trace an outline. Bend a strip of cardboard and glue the bottom to the box. We'll do the same for the boards around the Crickit.

 

Allow the glue to dry before press fitting the speaker and Crickit into place.

Box Flap

 

The flaps on the box will obstruct the PIR sensor, so we'll need to remove it. We can save the cut strip and reuse it to hide some of the components. 

 

Wrapping paper

 

Next on to decorating our gift box! we'll measure our wrapping paper so the side are separate, allowing the box to full open.  

 

The rest of the box can have one continuous strip of wrapping paper.  

 

Bow

 

For the last touch of detail, we added strips of ribbon a bow and a set of bells to jingle as the box moves! 

This guide was first published on Nov 14, 2018. It was last updated on Nov 14, 2018.