I was inspired to create this project because I'm honestly really lazy in the mornings and I never have enough motivation to travel to the other corner of my room to turn on my record player. And even when it is on, I always forget to turn it off.
At first, I wanted to use the Spotify API to control my speakers, but since I couldn't find a way to bypass the whole token-expiring-every-two-hours fiasco, I decided to use both the Blynk app and small sound sensor, with the intention of having the Blynk app control the physical toggle of my record player and the small sound sensor continually checking whether or not music was playing in order to automatically turn it off.
Hardware Setup:- Place the Particle Argon on the breadboard.
- Using a jumper wire, connect the GND pin of the Particle Argon to the negative rail on the breadboard.
- Using another jumper wire, connect the VUSB pin of the Particle Argon to the positive rail on the breadboard.
- Connect the power and ground pins of the Micro Servo to the positive and negative rail of the breadboard, respectively. Connect the Micro Servo's signal pin to A5.
- Connect the digital pin of the small sound sensor to D8, the VCC and GND pins to the positive and negative rails of the breadboard respectively, and the analog pin to A0.
- Place the LCD display on the breadboard.
- Make the following connections on the LCD display: VSS pin to the negative rail of the breadboard, VDD to the positive rail, V0 to the middle pin of the potentiometer, RS to D2, RW to the negative rail, E to D3, LCD D4 pin to D4, LCD D5 pin to D5, LCD D6 pin to D6, LCD D7 pin to D7, LCD A pin to a 220 Ohm resistor connected to the positive power rail, and LCD K pin to the negative rail.
- Place the potentiometer on the breadboard and make the following connections: the first pin to the negative rail of the breadboard, the second pin to V0 on the LCD display, and the third pin to the positive rail.
- Turn the knob of the potentiometer until you can see the characters on the LCD display.
Since my record player has a physical ON/OFF toggle switch that is fairly easy to flip, I knew that my hardware wouldn't need to exert a drastic amount of force in order to turn it on and off. For this reason, I decided to mount a Micro Servo directly atop the toggle and use tape to secure it down. Since the toggle was fairly short, I used a quarter of a popsicle stick in order to extend the switch and taped it into place. Since I still needed something to actually pull the toggle, I decided to use a paper clip because it was easy to bend and had enough tension to pull the toggle on and off. In order to do this, I attached one end of the paper clip to one of the holes in the servo's horn and the other end to my popsicle stick via hot glue.
Since the small sound sensor is highly sensitive to sound and only responds to sound pressure (not necessarily sound in general), I knew that I needed to create something that would help isolate the source of the sound and help capture the sound waves/"vibrations" of the music. The solution? A small wooden box to house the sensor!
I used some spare wood sheets that I had bought at the Dollar Store for a previous project to construct my box. I hot-glued all five sides together and voilà: a state-of-the-art wooden contraption!
Calibrating the Small Sound Sensor:The small sound sensor is highly sensitive. To combat this, the sensor features a built-in potentiometer that allows you to adjust the sensitivity of the sensor so that when the sound level exceeds a certain point, an LED on the sensor module illuminates.
However, adjusting the sensitivity/calibrating it is a very very VERY tedious process. It's always either constantly HIGH or constantly LOW unless you turn the potentiometer to a very particular point. It also depends on how loud you want to play your music. If you're okay blasting your music in order for the sensor to work, then you probably don't need to mess with the sensitivity too much, but I wanted my sensor to work with reasonable volumes, so it took a lot of trial-and-error in order to figure out how sensitive it should be.
To calibrate it, I would place the sound sensor underneath the box and occasionally peek underneath it to see what volumes and what kinds of songs it best reacted to. If it didn't pick up any readings at a reasonable volume, I would increase the sensitivity and vice-versa.
Setting up the Blynk App:In case you are unfamiliar with Blynk, it is a simple app that allows you to interact with your Particle device. You can control your hardware wirelessly and also send data from both the app and the Particle device.
The process to set up a Blynk app is fairly straightforward. All you have to do is create an account --> create a new app and receive an authorization token (to be used in the code) --> add a Styled Button widget and use the following configurations shown in the image below:
While the sound sensor is an important aspect of our project, the Blynk app is ultimately what wirelessly controls the servo's movements and the toggle's state.
The Code:This is where my already-faltering mental decline begins. As a quick refresher, we have two objectives with this project: (1) to wirelessly turn on the speakers and (2) to automatically turn off the speakers when not in use.
To accomplish these two tasks, my code ultimately does two things: it changes the servo position to turn the speakers ON/OFF, depending on the user's button input; and once it is on, it checks how many times within a 30-second interval has the small sound sensor detected music and stores it in a counter. If the counter is less than 1, it means that no music is playing and the speakers should therefore be automatically turned off.
The following are brief descriptions for each of the methods used in my code:
- setup() --> Nothing too fancy, it just initiates the Serial monitor (used for debugging), the Blynk app, attaches the servo and defaults it to off, and specifies the rows and columns of the LCD screen.
- BLYNK_WRITE(V0) --> called every time the program receives data from the app (aka every time the button changes state). Depending on the button's value, it either calls the turnOn() or turnOff() methods. V0 denotes that the data is coming from virtual pin 0, which is what controls the Blynk button.
- checkSound() --> called every half-a-second for 30 seconds ONLY when the record player is on. It stores how many times the small sound sensor has detected music in a counter. The variable, lastEvent, refers to the last time the method was called, which is used to make sure that the method is only called every second.
- turnOn() --> pulls the toggle of the record player to on and resets the timer that checks the sound state every 30 seconds.
- turnOff() --> pulls the toggle of the record player to off and resets the onCounter for the next time it is turned on.
- loop() --> assigns a start time to whenever the speakers are turned on. If the speakers are turned on, it checks if 30-seconds have elapsed since the last time the speakers were turned on or the last time 30-seconds had elapsed. If 30-seconds have not yet elapsed, it calls the checkSound() method every half-a-second. If 30-seconds have elapsed and the speakers are still turned on, it checks if the sensor had detected at least one sound and if not, it automatically turns it off.
Comments