Monday, June 6, 2016

Making the party room (Theory Post)

Remember when I said, "sooner than you expect?"

Well, this post here is a tutorial, like my RasPi lighting system. Actually, its more of an extension to that project really, since I am using the same LED Strips I got back then. Only now, they are properly mounted.

So what is different now? 

Have you ever been fascinated by those disco lights? Ones that change their color and intensity according to the song that is being played? I bet you have. I bet some of you even wanted those in your room. I know because I wanted one. But those system, don't come cheap. And I'm already on a shoestring budget, pretty much always. The cheaper solution is (pretty much) always to make your own. And hence, I turned to Arduino, the nifty little microprocessor.


The Arduino Nano. There are many versions available. The Uno being the most popular. You can use the Uno or the Nano. They have the same processors, but the Nano is easier on the breadboard.



Basically, What I needed to do was to split the audio into 2 signals, one going to my main stereo system, and one going to the analysis chip to break down the sound into diff parts, identifying the lows, mids, and highs of the sound. and somehow drive / light up the LED strips according to those processing values,

The first part is easy, splitting the audio signal. I just bought the 3.5 mm audio jack splitter. DUH! You can also use a microphone placed near the speaker, in-case you do not want to tamper much. But, that will also pick up the ambient noise, so will be good only in silent environment. Only thing that is required is getting a clean audio signal.


Simple Audio Splitter. You can use a microphone board as well, if you like.


Now for the second part, the signal analysis. It's a bit tricky. Especially if you plan to use an arduino only. That is because the Arduino itself is not meant for direct audio. We can however, turn it into a spectrum analyser using some pretty complex maths. Remember Fourier transforms? That's what the Arduino will have to do, hundreds of time per second, to separate the audio into different frequency bands.

Okay, a little bit about Fourier transforms...  

"The Fourier transform decomposes a function of time (a signal) into the frequencies that make it up, in a way similar to how a musical chord can be expressed as the amplitude (or loudness) of its constituent notes. The Fourier transform of a function of time itself is a complex-valued function of frequency, whose absolute value represents the amount of that frequency present in the original function, and whose complex argument is the phase offset of the basic sinusoid in that frequency."

Didn't got any of that? Me neither. In simplest terms, any sound you hear, in music, is a mashed mixture of sounds of various frequencies and amplitudes together hitting your ear. What this transform does is that it takes this sound, and breaks it into individual components of the sounds that make the original sound. For example, a drum kit will have bass, mid and treble, all together. Fourier will separate out these different frequencies so that they become a simple sinusoidal function, which can be easily processed by a computer.


Here, the Red line is the sound pattern you hear. 

The blue lines in the background are what the fourier transform does.
Breaking the main sound  into its components, so that computers can process it.




The problem however is that these transformation equations are complex. Humans, like me take forever to solve them, and even small microprocessors like the arduino may not be fast enough to calculate them for a proper song. The obvious solution is to use a faster CPU, which is done in providing visualisations of music in music players on PC and mobiles. But, we are on a budget, right?

Thankfully, there is a simpler solution. Enter the MSGEQ7 IC.


It's TINY!


What this IC (integrated circuit) does, is that it takes away all the maths that's needed and stuffs it into a tiny space, one that we do not even need to go into. 

"The seven band graphic equalizer IC divides the incoming audio signal into seven bands of 63Hz, 160Hz, 400Hz, 1kHz, 2.5kHz, 6.25kHz and 16kHz. The seven frequencies are peak detected and multiplexed to the output to provide a DC representation of the amplitude of each band."



The frequency splitting graph of the MSGEQ7 IC


So, this chip solves 2 major problems for us. It splits the audio signal into 7 bands of the mentioned frequencies, and also gives a voltage output for these frequencies according to their respective amplitude. That is great, since we can use that output as a signal to drive the LED lights. And since every frequency will have a different voltage level, We can make the LEDs light up in different colours as per the frequency. Example, Red glows for bass or the low end, green for the mids, and blue for the high end.






The green chip on the breadboard is the MSGEQ7 IC
The 3 black parts on the left are the MOSFET's which are driving a simple single RGB LED. 
Here is a basic circuit diagram, if you want to start right away. Obviously, there is Google as well, so you might as well just search for this thing. There are plenty of guides on how to make one. Ofc, I'll be posting a proper hardware guide later..


Here it is in working. (What I made)







I think this might have piqued your interest,after the boring part of theory. But that was a bit necessary. Without knowing how all this is actually working, there is no point in making it. You might as well buy something off the shelf. The advantage here is that once you know why you are doing what you are doing, you can customize it however you want.

So ultimately, what we are going to do, is to feed the audio signal into the MSGEQ7 IC, let it do it's thing, Take the Voltage output of the analysed signal from the IC, and feed it into one of the Analog pins of the Arduino. Once the signal is in the Arduino, we simply take the signal values for the different frequencies and map them to the PWM output, which with the help of some MOSFET's light up the LEDs according to the beats of the song. SIMPLE!

That's probably it for the theory part. I'll be updating this with the parctical guide in the coming time as well. Stay tuned!

And as always, Feedback and suggestions are very much appreciated. Thanks for reading!

Wednesday, June 1, 2016

The 10-Month Hiatus

Yeah, I know.
10 months.

I cannot stick to a schedule. I know that as well. But, I keep on working. I may not document what all I've been doing, even though I want to, but I just don't end up having that much time to do it.

You might ask then, What have I been doing since the last post here.

It's been a roller coaster, frankly. If you guys follow me on Google+, you would have some idea as to what all has happened.

First, let's talk about the update to my RasPi Lights. (Previous post)



The Main "Brain"
This took more than a year, from start to finish, and back then, I knew nothing about anything in this pic.


As you can see, It's now more or less in its final form. Here are the basics.


  • RasPi connected to
  • BMP180 for ambient temperature and pressure
  • DHT11 for ambient temperature and humidity
  • DHT11 for room temperature and humidity



IP address at top
Readings from BMP180 (outside room)
Readings from DHT11 (Blue sensor just below the screen)
Readings frm DHT11 Outside the room, alomgside the BMP180


All the sensor reading are now recorded and stored in a web server database at intervals of 10 minutes.
Graphs of all the readings plotted in real time on the web page hosted by the Pi itself.


BMP180 readings graphs, Opened on Chrome.
Blue is Temperature, Red is Pressure
I can actually predict the weather with these!


And obviously a much neater RGB LED Driver system.
Prepare to be dazzled!



My favourite setting. There's a red Laptop missing from the table here tho.

I saw somewhere speakers from LG that had LED Lights in them. That right then was a "Challenge Accepted" moment.
Turned out to be pretty good, I think

Obviously, It's an RGB LED Strip

Not sure if this is gaming mode, or the red one is...


Usually in this setting. The LED's are very bright and I do not end up needing any additional lighting in this config.
Photos look dark because they are underexposed to -2EV



Next, There's now an Arduino Nano controlling the power to my Pi, Speakers, Desk-Lamp, which is controlled by Bluetooth.
And it also monitors the Battery Charge, current drawn and the voltage of the Solar power system.


From left to right:- Buck converter, ACS712 Current sensor, Nano, Relay board (hidden), Screen.


Yeah, Everything I've mentioned above is running off solar energy. 12 Watts panel connected to a total of 14Ah of Lead Acid battery.


Salvaged PWM Solar charge controller I had lying around. Gives a total of 150W of backup.

And no more breadboards here. Its all Permanent, Although I think I could have made it a little better with more planning. But it works fine ATM.

That's what I have done for my room. But that's not the only thing. Me and my pals were also working on a project for college.
Here it is.





Basically, what we tried is to make a robot that mimics the movements of the human arm and replicates it in a servo driven arm with at least 1 degree precision.
Its close, but calibration is quite hard, considering all the parts we are using are cheap ripoffs and no original stuff can be found here. Tough luck.








For the curious, we are again using a Nano, with 6 Potentiometers as the angle sensors, and then feeding the angles measured to servos via a PCA9685 PWM driver board.
Servos are Tower Pro MG996R (Again, not originals)

The electronics on this were easy. The manufacturing and assembly of the parts were not even close to easy. It took a lot of time (about 3-4 months), and a little blood, to get to this point here.
And the best part was, when I got to present my project, the teacher just scoffed and said that we got it made from the market.

And then people ask why India is not doing so well in R&D. Short answer, because of people like him, no one actually bothers to work.



But that's not the worst.
Along with all this, I also got involved in what has to be one of the most challenging and amazing projects I have ever heard about. The CanSat competition organized by the American Astronomical Society and NASA.

We had to design a can shaped payload, which would be  launched and ejected into the atmosphere at approximate 10km from the surface. The payload then would descent, using parachute, and at a height of 400m, a fixed wing glider should be deployed, which is recording the temperature, pressure, humidity, air velocity, GPS data every second and transmitting it back to the ground station using XBee radios, whose graphs were to plotted using MATLAB in real time. Not to mention, there was also a TTL Camera to be there in the Glider.

That sounds AMAZING, right? That's because it is. We had to make everything from scratch, test everything, pack everything in a space of nothing more than 300mm by 120mm diameter, having a weight of less than 500gm.

And I'm pretty sure we would have managed to make the satellite, possibly even be in the top 10, if it were not for some really, REALLY big IDIOTS in the team. And sadly, those idiots were my seniors, and I couldn't really do much. It was out of my control.

The work got delayed, the parts were late, there were only discussions, and no actual work had started until April, and were were scheduled to go to Texas, USA for the launch in June.

Now fortunately / Unfortunately, we were kicked out of the competition in the final round of presenting the Critical Design Review to the judges, Mostly because the guy making the presentation had english grammar skills worse than that of a 10 year old. Also, we had not actually made a single thing, and we were presenting a CRITICAL DESIGN REVIEW of that.

I say fortunately, because thankfully I do not have to deal with such level of insane and imbecility anymore, let alone stay with them as a team for 2 weeks in US during the competition.
Unfortunately, because this was once in a lifetime kind of opportunity for me, and because of them, we lost it. Not to mention the visa fees and other stuff. Those guys were just looking for a visa and I don't think that they were really interested in making cool stuff.

I should have been packing my bags for the trip, but I'm just typing away at my keyboard. Feels bad, but what are my options anyways?

One option is, to make Sound Reactive LED lights, the ones that respond and change color and brightness according to the beats of the song. It looks good!  I've already started working on it, and as of now, after spending about 5-6 hours on that, at least the basic circuit is working. 

I also got a 10 watt RGB LED module, just because I was curious, and I am working on that as well. 



It's a MONSTER! At full power, you cannot even look at it, and heats up the Intel 775 Heatsink fairly quickly.
Just  pure insane, but very fun!

And that is what I'm gonna be doing in my Vacations now. Apart from maybe a few other small things. I'll try to write some small guides here... some sort of documentation, but I can only hope.

If you guys like what you see here, Follow me on Google+! There's my Photography Collection and a basic IoT Collection as well. And obviously, its not updated once in 10 months. :P


Questions, requests and feedbacks is much appreciated.  Until next time, and it will be sooner than you think. :)