Introduction: CPX Locating System

Humans don't have the best memory. We forget things very easily, especially when it's things that we don't pay attention to in the first place, like where we put our pencils. You put your pencil on the table for one second, and the next time you look for it, it's gone. You can't even call out to it and hope for a response like you would if you lost a child in the mall. So what do you do in a case like this? Well, why not build something to solve the problem!

With this tutorial, you can make a device that makes its location known via an alarm system. You can attach the device to your pencil, or any small object that you lose often, and then when you lose that object, you can call out to it and the alarm system in the device will go off so you can locate where it is and find the attached lost object.

Supplies

Here's what you'll need for this tutorial:

    • Circuit Playground Express (CPX)
    • The battery pack for the CPX
    • A USB cable for downloading code to your CPX from your computer
    • String, could be any type of string: yarn, shoelace, etc., as long as it doesn't break easily and fits through the small hole on the battery pack.
      • Length of string depends on the size of your object, larger objects will require longer strings.
    • Your object (I'll be using a pencil in this tutorial, but you can use anything you'd like to be able to locate)
    • Small Ziploc baggie, could also be replaced by a small pouch or something similar as long as it can hold objects inside it, would also be preferable if it closed but that's not necessary
      • Big enough to fit the CPX and battery pack inside
    • Rubber band (only necessary for objects that you can't securely tie a string around)
    • Alligator clip (optional, only if you want to change the object after you've created your product

    Step 1: Circuit

    First, let's start by setting up our CPX that will later play a sound and flash lights when it detects a loud sound. All you need is your battery pack to make it work. Use the battery pack's wire to connect your battery to your CPX so that it can run.

    Step 2: Code

    Now that we have our CPX circuit ready, let's write our code. Here's a link to my code that makes a sound and flashes lights when it detects a loud sound. The code also allows the user to turn off the alarm system once it plays, and turn it on after they turned it off.

    Below is a short explanation of how I created the code. Once you understand what the different pieces of code do, feel free to make adjustments as you see fit.

    First, I created two variables in the on start block. The play variable stores whether the alarm system is activated or not. The run variable stores if the alarm is going off or not. (img 1)

    Next, I used a forever block and an if statement. In the if statement, if the sound level was above 150, I used a while loop to check if the alarm was activated by checking if play was true. While the alarm was activated, the alarm system would go off, so a siren sound would play, and a ring of alternately lit up red LEDs would flash with a gap of 2 seconds between each flash. In the while loop, the run variable was also set to true to indicate that the alarm was going off. (img 2)

    After that, I included another if statement inside the forever loop that checked if button A was pressed and the alarm was going off. If both the conditions were true, the current animations and sound would stop, and a new sound and animation would play. Then the board would be cleared, play would be set to false so the alarm wouldn’t be activated anymore, and run would be set to false since the alarm wouldn’t be going off anymore. (img 3)

    Lastly, I had one more if statement within the forever loop that checked if button B was pressed. If it was triggered, the alarm would be reactivated, so after a pause of 4 seconds, the play variable would be set to true. (img 4)

    When you want to download the code onto your CPX, connect the USB cable to your CPX and laptop, and click the reset button on the CPX. Once you see green LEDs on the CPX, download your program and it should load onto the CPX.

    Step 3: Physical Build

    Now to build the product that holds the device and attaches it to your object.

    First, tie a square knot with your string, through the little hole in the battery pack. (img 1 & 2)

    Next, place your battery pack and CPX into your baggie with the buttons on the CPX facing you. Leave your string hanging out of the bag and then close your bag if possible. (img 3)

    Now, tie the other end of your string around your object using the same square knot as before. At this point, your object should be securely attached to the device and you're done creating your product! (img 4)

    Notes:

    For an object that is slippery or just too large for a string to be tied around it, tie the object end of your string to a rubber band and then tie the rubber band around your object. (img 5)

    If you would like to change your object, you can easily untie the knot at the object end of your string using your alligator clip. With your alligator clip, carefully grab one piece of string in your knot and gently pull and wiggle the clip around until the knot starts to loosen, then pull it apart by hand from there. (img 6)