Hi! Steven here from Core Electronics! I am here today to talk to you about making sound reactive lights using Circuit Python and Adafruit Circuit Playground Express.
The Adafruit Circuit Playground Express is a great educator friendly board with a lot of sensors and lights built into it so this is just one of many projects that you can do using just the board itself. If we take a look at the board the microphone is located in the bottom right hand side and the microphone is really cool on this particular board because its not just amplitude sensing like many simple mics are, it’s frequency sensing. But for this project we are just using sound amplitude and as you can see, I have already got the sketch uploaded onto the board. As it detects sound the string of lights, light up further around the wheel and it does it in a rainbow pattern and it does this by taking many samples and then averaging them out and then that value is used to display on the lights and if it doesn’t do it this way then you’ll end up with really spiky and somewhat uneven display on your LEDs.
If we look at the code in Circuit Python, there is quite a bit of math involved in this. So, we will not break down all the different parts and what they do, you can find the full code in our tutorial section but what I do want to go over with you is the variables that control the behaviour of the lights themselves. So the first one is curve, which is an exponential scaling factor and if you change that between 1 and 10, it changes how much the LEDs climb every time they detect sound and we can change the top colour of the Neopixel here with “PEAK_COLOR” and for this sketch it’s purple and the number of pixels in the strip is 10 and if we wanted to use an external strip with this project it could be any number of Neopixels long and it would have basically the same effect and it would be a really simple change to make. All you would need to do is change the output from the board Neopixels to a digital output pin.
The last variable that affects the behaviour of the board is the number of samples variable. As you can see its at 160 samples now, so for every value it returns from the microphone, its taking 160 samples, making the average of all those and sending them as one output and it does all that extremely quickly. If we take a look at our serial monitor, I have set up to print the readings off of the microphone, the calculated average and as you can see it’s climbing between a value of about 40 and at my loudest 400, and you could use this raw data to change your calculations as you want but really I’d just encourage playing around with them, see the effects that have on your lights and have fun with it.
So that wraps up my tutorial on making sound reactive lights, using Circuit Python and Adafruit Circuit playground express. If you have any questions, check out our forums and leave a comment. If you want to learn more about the Adafruit Circuit Playground Express, Circuit Python or programming with MakeCode check out our tutorial sections, we’ve got more videos and more great content up there on the Adafruit Circuit Playground Express and other boards, thanks.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.