CPX Locating System
![Screenshot 2021-03-21 7.29.53 AM.png](/proxy/?url=https://content.instructables.com/F51/GVZ2/KMHQRFH7/F51GVZ2KMHQRFH7.png&filename=Screenshot 2021-03-21 7.29.53 AM.png)
![File_000 (24).jpeg](/proxy/?url=https://content.instructables.com/FI0/DHAR/KMJ67X0M/FI0DHARKMJ67X0M.jpg&filename=File_000 (24).jpeg)
![File_000 (20).jpeg](/proxy/?url=https://content.instructables.com/F86/OQ3K/KMJ67X0O/F86OQ3KKMJ67X0O.jpg&filename=File_000 (20).jpeg)
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
Circuit
![File_000 (21).jpeg](/proxy/?url=https://content.instructables.com/FBG/5GHP/KMHQRF1P/FBG5GHPKMHQRF1P.jpg&filename=File_000 (21).jpeg)
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.
Code
![Screenshot 2021-03-17 at 1.06.39 AM.png](/proxy/?url=https://content.instructables.com/F3I/ZC04/KMHQREZX/F3IZC04KMHQREZX.png&filename=Screenshot 2021-03-17 at 1.06.39 AM.png)
![Screenshot 2021-03-17 at 1.07.11 AM.png](/proxy/?url=https://content.instructables.com/FNZ/JGJZ/KMHQREZW/FNZJGJZKMHQREZW.png&filename=Screenshot 2021-03-17 at 1.07.11 AM.png)
![Screenshot 2021-03-17 at 1.07.58 AM.png](/proxy/?url=https://content.instructables.com/FYI/Z6WF/KMHQREZV/FYIZ6WFKMHQREZV.png&filename=Screenshot 2021-03-17 at 1.07.58 AM.png)
![Screenshot 2021-03-17 at 1.08.16 AM.png](/proxy/?url=https://content.instructables.com/F28/IDVI/KMHQREZT/F28IDVIKMHQREZT.png&filename=Screenshot 2021-03-17 at 1.08.16 AM.png)
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.
Physical Build
![Screenshot 2021-03-22 5.28.55 AM.png](/proxy/?url=https://content.instructables.com/FAR/0XEQ/KMJ681ZV/FAR0XEQKMJ681ZV.png&filename=Screenshot 2021-03-22 5.28.55 AM.png)
![File_000 (22).jpeg](/proxy/?url=https://content.instructables.com/FBS/FSPM/KMHQRF77/FBSFSPMKMHQRF77.jpg&filename=File_000 (22).jpeg)
![File_000 (23).jpeg](/proxy/?url=https://content.instructables.com/FHT/WHT6/KMHQRF6D/FHTWHT6KMHQRF6D.jpg&filename=File_000 (23).jpeg)
![File_000 (24).jpeg](/proxy/?url=https://content.instructables.com/FO2/OYWY/KMHQRF6C/FO2OYWYKMHQRF6C.jpg&filename=File_000 (24).jpeg)
![File_000 (20).jpeg](/proxy/?url=https://content.instructables.com/F0H/I2WN/KMJ67WZQ/F0HI2WNKMJ67WZQ.jpg&filename=File_000 (20).jpeg)
![File_000 (25).jpeg](/proxy/?url=https://content.instructables.com/F1O/8VVA/KMHQRF6B/F1O8VVAKMHQRF6B.jpg&filename=File_000 (25).jpeg)
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)