This Clever Device Detects the Amount of Metal in Music

With a bit of machine learning and a microphone, this gauge can sense whether or not the music being played is metal enough.

The idea for the metal detector

When it comes to music, a massive variety of genres abound from which to choose. Whether you enjoy listening to the light guitar strumming of country, upbeat and catchy pop, or the laid back soothing sounds of jazz, there's something for everyone. But for Phil Caridi, he likes his music loud and bold, which typically means he listens to heavy metal music. So as a fun application of machine learning and audio processing, he decided to build a metal detector that can determine just how rock-and-roll a sample of audio really is.

Components used

As the basis of his device, Caridi's metal detector uses an Arduino Nano 33 BLE Sense due to its onboard microphone, adequate processing power, and tight integration with Edge Impulse's data ingestion service. In order to move the needle back and forth as the amount of metal changes, a micro servo is positioned at its base. And finally, a single 9V battery supplies power to everything via a 5V linear regulator.

Collecting and processing data

After getting the components together, Caridi then moved onto the next step of teaching a neural network about what exactly metal music sounds like when compared to other genres. To accomplish this, he recorded around 20 minutes of audio samples and split them into two categories: "metal" and "non_metal." Each sample was then put through a Mel-filterbank processing block on Edge Impulse, which takes in the raw waveform, generates a spectrogram, and then extracts certain frequencies to better match the human ear's interpretation.

The model

Once trained on this now-processed data, the Keras neural network was able to achieve an impressive accuracy of 88.2%. Caridi then built and exported this model as an Arduino library for use his sketch. His Edge Impulse project can be found here.

Putting it all together

Caridi's code starts by initializing the microphone to take audio samples at a rate of 16KHz, after which it gets stored in a buffer for later inferencing by the neural network. The result of this process is a pair of values that ascribe a probability to each label, with a higher number for the "metal" label being equal to the song having more hard rock elements in it. The servo motor's position is derived from this value that allows it to move further to the right if the music is right.

To see this project in action, you can watch Caridi's demonstration video above or read more about the project here on his blog.

Arduino “having11” Guy
20 year-old IoT and embedded systems enthusiast. Also produce content for and love working on projects and sharing knowledge.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles