Maker.io main logo

Halloween Sentry-Bot with CRICKIT for CPX

2018-10-17 | By Adafruit Industries

License: See Original Project Circuit Playground

Courtesy of Adafruit

Guide by Dano Wall

Overview

This sentry robot will wait quietly for someone to pass by, then it springs to life! A lot of fun anytime or make it especially for Halloween.

Using MakeCode drag and drop blocks you will make a scary monster that can protect all your precious, precious candy.

In addition to basic programming concepts, this guide also demonstrates the construction of a simple mechanical movement, translating rotary motion into linear motion.

The Electronics

This project uses the following items from the Adafruit store:

Tools & Materials

For this project you will need these materials:

  • Clear plastic cup
  • Scrap cardboard
  • Double sided tape
  • Pipe cleaners
  • Googly eyes

And these tools:

  • Hobby knife
  • Tweezers (or something pointy)
  • Screwdriver
  • Scissors
  • Hot glue gun

Tools

Build the Circuit

The circuit for this bot requires connecting a servo motor and a DC motor to CRICKIT, the all-in-one motor controller that pairs with the best microcontroller anywhere: the Adafruit Circuit Playground Express.

Building%20the%20Circuit

A standard size plastic drinking cup fits almost perfectly over the CRICKIT. We will be using this cup as a housing for the electronics as well as a form upon which to build.

Standard%20plastic%20cup%20fits%20perfectly%20over%20CRICKIT

Here is a diagram showing the wiring for the motor, servo, and Crickit

diagram%20showing%20the%20wiring

Connect the DC motor

Bend pins on DC motor. This will allow the cable to fit comfortably inside the rim of the cup.

Bend%20pins%20on%20DC%20motor

Plug into motor terminals.

Plug%20into%20motor%20terminals

Use a screwdriver to tighten down connections.

tighten%20down%20connections

Connect the Servo Motor

Plug servo into servo port 1 on CRICKIT.

Plug%20servo%20into%20servo%20port%201%20on%20CRICKIT

Make sure ground wire (brown) is facing inwards.

Make%20sure%20ground%20wire%20(brown)%20is%20facing%20inwards

Test the Code

It's a good idea to test out your code before moving on to the final build. This page will lead you through a dry-run.

We will be using Microsoft MakeCode for Adafruit, a web-based code editor. It provides a block editor, similar to Scratch or Code.org, and also a JavaScript editor for more advanced users.

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

Getting into Bootloader Mode

To make your board work with MakeCode we need to put it into bootloader mode. All that's required to do this is to connect the board to your computer with a micro USB cable and click the small reset button in the center of the board.

Getting%20into%20Bootloader%20Mode

Now we're ready for MakeCode!

Click this link or the button below to enter the portal to interact with the code for this project.

Upload the MakeCode file for this project

How to Upload the Code

To upload code, connect you Circuit Playground Express to your computer using the micro USB cable, click the Download button to download the .uf2 file to your computer, and drag 'n drop it onto the CPLAYBOOT drive.

The drive will automatically eject itself. (Your computer may give you a "failed to eject drive correctly" error, you can ignore this.) The code is now on your Circuit Playground Express and ready to run!

Upload%20the%20Code

Testing the Code

This sketch in MakeCode uses the light sensor on Circuit Playground Express to control the motors.

In the on start block, we can see three startup commands. The threshold for what is considered a "loud sound" is lowered to 10, the volume level is set to almost full volume, and the servo motor is initialized, so it will always start in the same position.

In the three forever blocks, there are if / else statements, which gives the following instructions:

  • If sound level goes above the specified value, move the servo back and forth 4 times.
  • If light level goes below the specified value (in this case, 50), run the DC motor.
  • If acceleration strength goes above 1022, turn all neopixels white.

Microphone

Once powered on, you should be able to test your circuit by snapping or clapping. In response, the servo arm should twitch back and forth.

test%20your%20circuit%20by%20snapping%20or%20clapping

Circuit Playground Express has a small microphone on it, allowing it to detect sounds.

CPExpress%20has%20a%20small%20microphone%20on%20it

Light Sensor

The light sensor is used to detect when the light level falls below a specified value. When you cast a shadow over the board you should see the DC motor start spinning in response.

Light%20sensor

The component that makes this possible is the tiny analog light sensor in the top left part of the board. This is used to detect ambient light with similar spectral response to the human eye.

With MakeCode we are able to use the readings coming from this light sensor to control the motors, but it's also possible, with some clever code, to use this as a color sensor or even a pulse sensor!

tiny%20analog%20light%20sensor

Accelerometer

Finally, your board should now be sensitive to being moved, even small vibrations. You can test this by tapping your board or thumping the table it's on, and the NeoPixels LEDs should flash white in response.

Accelerometer

The small but very accurate accelerometer on the board makes it possible to detect slight movement. Acceleration is read by CPX as a value between 0 - 1023.

small%20but%20very%20accurate%20accelerometer%20on%20the%20board%20

Making Changes

If you'd like to play with this code, click Edit and a new window will open in which you can create your own version.

When you want to try out your new code, connect Circuit Playground Express to your computer with a micro USB cable, download your adapted code, and drag the new .uf2 file onto your CPLAYBOOT drive.

Troubleshooting

Problem: My motors aren't working!

Solution: Make sure that the small slide switch on the CRICKIT is set to "ON".

Problem: My motors still aren'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.

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 as a flash drive named CIRCUITPY the first time it's connected to your computer. 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 Circuit Playground Express is in Bootloader mode, all the LEDs will flash red briefly, then turn green. Your computer should now show removable drive called CPLAYBOOT. Now you can copy the MakeCode file to the CPLAYBOOT flash drive.

Constructing the Monster

Make the Leg Gantry

Cut out a T-shaped piece of cardboard like the one pictured.

Crease cardboard in two places so it can bend around the cup.

Cut%20out%20a%20T-shaped%20piece%20of%20cardboard

Cut two slits down the side.

Cut%20two%20slits%20down%20the%20side

Fold into shape and use hot glue to attach a cardboard brace to hold in place.

Fold%20into%20shape/use%20glue%20to%20attach%20a%20cardboard%20brace%20

Using hot glue guns can cause burns if the gun tip or glue touches exposed skin. Be very careful.

Mount the DC Motor

Position DC motor inside cup and mark placement of holes with a marker.

Position%20motor%20inside%20cup/mark%20placement%20of%20holes%20

Poke holes in the cup using tweezers (or something else pointy).

Poke%20holes%20in%20the%20cup%20

Cut out a thin rectangle of cardboard and poke two holes, matching the spacing of the two holes in the cup.

Cut%20out%20thin%20rectangle%20of%20cardboard/poke%20two%20holes

Attach DC motor to inside and bar to outside of cup using two screws or a twist-tie.

Attach%20DC%20motor%20to%20inside%20and%20bar%20to%20outside%20

Stick the eccentric hub on the motor.

Stick%20the%20eccentric%20hub%20on%20the%20motor

Test Fit

Test the fit of the leg gantry on the cup, it should be able to slide easily up and down.

Test%20the%20fit%20of%20the%20leg%20gantry%20on%20the%20cup

If the gantry feels sticky, now is the time to reposition the brace or widen the slits so that it can move up and down freely.

Add Spider Legs

Use hot glue to stick pipe cleaners to the cardboard.

Use%20hot%20glue%20to%20stick%20pipe%20cleaners%20to%20the%20cardboard

A spider has eight legs!

A%20spider%20has%20eight%20legs

Cut the Cable Holes

Use a hobby knife to cut a hole in the top of the cup for the servo cable.

Use%20a%20hobby%20knife%20to%20cut%20a%20hole%20in%20top%20of%20cup

Add a cutout for the DC jack at the rim of the cup.

Add%20a%20cutout%20for%20the%20DC%20jack%20at%20the%20rim%20of%20the%20cup

This cutout will allow you to easily plug/unplug your power cable.

Add a Face

Two jagged-cut pieces of cardstock glued to a popsicle stick make a scary looking face.

Cardstock%20glued%20to%20a%20popsicle%20stick%20makes%20a%20scary%20face

Use tape to affix servo motor arm to the base of a popsicle stick.

Affix%20servo%20motor%20arm%20to%20the%20base%20of%20a%20popsicle%20stick

Hot glue or glue sticks work well to attach googly eyes.

attach%20googly%20eyes

A short piece from a straw also works to attach eyes to the servo motor arm.

Boo!

Boo%21

Sentry on Duty

Now it's time to have some fun.

Place your finished bot in a place with ample bright light. The bright light will keep its light sensor from being triggered and setting it off.

Place%20your%20finished%20bot%20in%20a%20place%20with%20bright%20light

Your sentry should be sensitive to different indications of people passing by.

Sound Sensitivity

Sound%20Sensitivity

Vibration Sensitivity

Vibration%20Sensitivity

Light Sensitivity

Light%20Sensitivity

制造商零件编号 3333
CIRCUIT PLAYGROUND EXPRESS
Adafruit Industries LLC
制造商零件编号 3093
CRICKIT CIRCUIT PLAYGROUND EXP
Adafruit Industries LLC
制造商零件编号 169
SERVOMOTOR RC 5V TOWERPRO
Adafruit Industries LLC
制造商零件编号 3777
GEARMOTOR 200 RPM 3-6V DC
Adafruit Industries LLC
制造商零件编号 UR050-003
CBL USB2.0 A PLUG-MCR B PLUG 3'
Tripp Lite
制造商零件编号 3842
BATTERY HOLDER AA 3 CELL LEADS
Adafruit Industries LLC
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum