Introduction: Safety First Helmet With Circuit Playground Express

Have you ever gone for a bike ride and worried about taking your hand off the handlebar to signal which direction you are turning?

Now that fear can be in the past!

This tutorial will show you how to create a hands-free helmet blinker system using Circuit Playground Express.

Supplies

-Circuit Playground Express

- Three AAA batteries

- Bike Helmet

-Tape

Step 1: Create a New Make Code Project

First, you need to go to Adafruit's Make Code browser system.

https://makecode.adafruit.com/

Then, make a new project. This project will be using the block code in Make Code.

(If you are new to this website, I highly recommend watching the Adafruit Circuit Playground Express tutorials before you begin coding)

Step 2: Set the LED Brightness

Before you begin creating code for the blinkers, you will need to set the LED brightness. This will help to preserve battery life.

Look under the green "loops" menu for the block "on start". This code will start each time your Circuit Playground Express is turned on.

Look under the blue "light" menu for the block "set brightness" and place that inside the green "on start" loop. I set my brightness to 10 so the LEDs would be easier to photograph. You would want to set the LEDs to a higher brightness.

Step 3: Code for the Left Blinker

To set up the code:

  • Under the purple "input" category, find the "on shake" block and drag it onto the workspace.
  • Click "on shake" in order to open the pull-down menu and select "tilt left". This will make it so the code is activated when the Circuit Playground Express is tilted to the left.
  • Next, look under the green "loops" category. Pull the "repeat x times... do" loop and nest it in the "tilt left" block. Then, type "3" into the blank space so the code will loop through 3 times.

Now, we will be creating a blinker animation for a left turn.

  • Go under the blue "light" category and find the "show ring" block. This will have an illustration of the Circuit Playground Express. Place this inside the "repeat" block.
  • Click the gray inside circle on the illustration and then click the surrounding circles in order to deselect all of the lights. All the lights should be gray. This will be the first part of the blinker animation.
  • Place a "clear" block below.
    • You can find it in the blue "light" category.
  • Next, place a "pause for 100 ms" block under the "clear block". This will help the movement of the blinkers be more noticeable.
  • Next, insert another "show ring" block under the "pause" block. Select the middle three LED circles on the left side. You can make these any color you like.
    • Simply click the color (when you select it, the outline becomes yellow) and then click the circles. I chose red so the blinker would be highly visible.
    • Place another "pause" and "clear" block underneath.
  • Then, insert a "show ring" below. This is the last piece of the blinker animation. Select all of the LEDs on the left side.
  • Place a "pause" and a "clear" block beneath.

Last step!

  • Place a final "clear" block outside of the green "repeat" loop but inside the purple "tilt left" bracket. This will clear the animation once the loop has run through the code three times. If you don't do this, the blinker will stay lit on the helmet after the animation finishes.

Step 4: Code for Right Blinker

You will repeat all the same steps from Step 3 except make it for the right side of the Circuit Playground Express.

Select "tilt right" and mark the LEDs in the same way and in the same progression but on the right side of the circle.

Step 5: Code for Going Forward

This code will be activated when the Circuit Playground Express is tilted down. On the helmet, it will be activated when you put your head down.

To create a forward blinker, use the same process as in Steps 3 and 4 except you will edit the "on shake" block to "on tilt down". The LEDs you will select are on the top of the circuit and will extend on both the left and right sides.

Step 6: Optional Additional Features

On my helmet, I also included a code that will play an animation and make a siren noise if I fall off my bike and a color-matching tool so the Circuit Playground Express can color coordinate with the helmet.

Step 7: Optional Fall Sequence

The Circuit Playground Express can sense gravity and has a free-fall setting. This is found in the menu under the same "on shake" block.

When the circuit doesn't sense gravity (like if you are in the midst of falling), it will activate this code.

  • Nest a 3 times "repeat" loop under the "on free fall" block. You can find light animations under the blue light menu. I chose rainbow LED animation for 2 seconds.
  • You can find sounds inside the orange "music" category. I chose the siren sound.
  • I used the "play sound until done" block. This sets the sound to play until the sound recording is finished. If I were to fall, the circuit would light up in rainbow LEDs and then repeat a siren sound 3 times.

Step 8: Optional Color Coordinating

The Circuit Playground Express has a light sensor on the upper left side of the circle. It is marked by an "eye" icon. If you were to activate this feature and hold a solid color up to it, the LEDs will match their color with the color of the object. For the fashion-conscious, this could be a great feature for the circuit helmet! Your helmet and this circuit could completely color coordinate.

To create this code you need to look under the purple "input" menu for the block "on button A click". This means the code will begin when you press button A on the Circuit Playground Express.

  • In the blue "light" menu, drag the block "set all pixels to" under the "on button A click" bracket.
  • Then, under the "input" menu look for "ambient color".
  • You will need to drag this into the circle space on the "set all pixels to" block.
  • This will make the code read "set all pixels to ambient color". Now, the Circuit Playground Express can color match.

To turn the LEDs off, you will need to create a new set of code.

  • Select "on button B click" and place it on the workspace.
  • Then insert "clear" and "set all pixels to 0". Both of those blocks will be found under the "light" menu.

Step 9: Downloading the Code Onto the Circuit Playground Express

You need to plug in your Circuit Playground Express with a micro USB to your computer.

If you have a PC, you can click the "download" button at the bottom of Make Code and it will download the code onto your Circuit Playground Express.

If you have a Mac, you can either click the "download" button or the "save" button. This will save the code onto your computer. Then you need to look for the "boot loader" drive on your screen or in your location folder under Finder. It may not appear right away. If it doesn't appear, press the "reset" button on the Circuit Playground Express once and wait for the lights to turn green. Then, the "boot loader" drive should appear. Drag the saved or downloaded code file onto the drive and your code will then be transferred to the Circuit Playground Express. An error code will pop up saying that the drive was improperly removed. This seems to be a glitch in the system and is harmless.

Step 10: Attach It to a Helmet!

This is the last step!

You need to attach your Circuit Playground Express onto a bike helmet.

First, plug the Circuit Playground Express into the battery pack. The battery pack requires 3 AAA batteries. Be conscious of the orientation of the Circuit Playground Express. Because many of these features are tilt activated, the Circuit Playground Express needs to be facing upwards.

Then, use tape or use the clip on the battery pack to attach the Circuit Playground Express onto your bike helmet!

You are ready to go for a ride!