Personal Noise Detector With a CPX
by danielofcambridge in Circuits > Microcontrollers
279 Views, 1 Favorites, 0 Comments
Personal Noise Detector With a CPX


Ever had noisy tenants who tend to break things a lot and avoid owning up to mistakes? Or had a sibling that frequently sneaks into your room when you arent around? In this guide, we'll be creating a noise detector that'll log when a loud noise occurs so you could hold the respective parties accountable for their actions. To this end, we'll be using a Circuit Playground Express as the pivotal microcontroller for our product since it will be taking care of everything from taking sound input to outputing a text file of its logs.
Supplies
- One Circuit Playground Express Board
- One Battery Pack with a JST PH type 2-pin connector
- Three AAA batteries
- A box of 1 in x 3 in x 2ΒΌ in or similar dimensions
- A fairly sharp pen
Programming the CPX: Start Function

Before diving into the building aspect of this project, it is important that the programming aspect of this product is properly addressed. At the beginning of this program, there are four important items are initialized:
- A "seconds" variable
- A "minutes" variable
- An "hours" variable
- An empty list
As assumed by the names of the three variables, these will serve to hold the time. However, since the CPX cannot synchronize itself with the actual time, it will instead track how many hours, minutes, and seconds have passed by since the CPX was turned on. the The empty list is used to hold the relevant logs, in other words, it will hold all the times recorded at which the sound level was high.
Programming the CPX: Our Forever Function

This section of the code makes up a bulk of what the program actually does. In this forever function, so long as the CPX has power, it will run every line of code inside the function. The first part of the code can be summarized as followed:
- Log the current sound level
- If the sound level is greater than 187, output the time at which this noise occurred and its sound level and append this info to the list
After this section of the code, the program simply adds seconds to our CPX's internal "clock", thus altering the seconds, minutes, and hours variables to show how much time has passed since the CPX was turned on.
Programming the CPX: Final Output Function

This function of the code is used to create a text file of all the relevant logs the CPX has taken so the user can sift through these and use them for the noise-related problem they are trying to tackle. When the user presses and holds the A and B buttons, the text file is output and can be downloaded onto the user's computer when they connect the CPX to it.
Building the Physical Apparatus: Prepping the Materials


As for the box:
Use the fairly sharp pen to poke a large enough hole on the side of the box to ensure that the connectors and wires of the battery pack could easily slide in and out of the box. Once completed, push the connector through the hole and hook it up to the CPX.
As for the battery pack:
Open up the battery pack's lid, put all three of the AAA batteries in the battery pack then close its lid.
Building the Physical Apparatus: Securing the Product

Close the box and use two inches of packaging tape on each side of the box to ensure it stayed closed. This will make it so that the CPX doesn't easily fall out of the box.
In addition to that, fold the battery pack under the box and tape it to the box's bottom using 4 inches of tape.
Enjoy Your Noise Detector!
