Saturday, April 18, 2015

Ledstrip Controlling 2

Ok so last times on this weblog we made a little detour. In a previous post I showed you how to cut the ledstrip and attach wires to the 12volt and RGB connections. Next I showed you how to control a ledstrip with switches. And then I showed you how to control a relay throught bluetooth with your Android Phone. Lets combine that and lets control the ledstrip with our Android Phone.

Ok so first we have the setup with the power transistors that are attached to the ledstrip just like we did last time. As you can see I am using the TIP 120 transistors again as they are much more powerfull as the BC547. And power is what we need to control a ledstrip.

.If you can not find the TIP 120 the TIP122 will do equally well 

But here the similarity ends. We want to control this with an Attiny85. So lets attach the Attiny pins to the ledstrip.

Now we do have a small problem. That is that we can not feed the Attiny85 with the 12 volts power supply from the ledstrip. So we need to bring the 12 volt down to 5 volts. I used a 7805 voltage regulator for that purpose. You can see that in the next layout:

So now there is only one thing left to do. The Attiny has to know what commands to send to the ledstrip and we are going to do that with the HC06 bluetooth module. Here is the final layout.

So here is the breadboard layout.

Some notes:
On the red strip on the side of the breadboard the + 12 volts will be attached
On the blue strip on the side of the breadboard the ground is attached.
On each middle pin of the transistor is the R, G or B wire attached from the ledstrip.

Check and check again especially the power lines. It would be a shame if you blew up your Attiny85 or the Bluetooth module or even the transistors.

So we now have the hardware complete. Now for the software.

Ok a bit about the code. Attiny85 digital pin 0 is Transmit (TxD) to the HC-06 module and pin digital pin1 is the Receive pin (RxD). The led strip is connected to digital pins 2,3 and 4.

The code:


Tests constantly if a character is received. We just test for 1 character. With 1 character we can give the Attiny 62 commands !!
Hows that you say. Well we do have 26 letters (A-Z) and then 26 capitals (A-Z) and 10 figures (0-9).
62 commands should be sufficient for many many projects.......

So lets look at a part of the code:

else if(recvChar == '7') // wit
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);

Ok as you can see this part tests if the figure 7 is received from the bluetooth module. If that is the case the Attiny85 will put a HIGH signal on the digital pins. This will send a signal to the RGB strip putting all leds ON which gives the color white.
Easy !!

So now for the Android part.
The code was just as in previous posts made in App-Inventor. You should really dive into App-Inventor as it is really easy to write apps in this environment. You can find App-Inventor here.

So I am not going to teach you how to program in app inventor but I am going to show you partially how this app is made.

First you determine the layout of the screen. For this app it looks like this:

Yep sorry it is in Dutch. Hey I am Dutch. So to translate it in English learn how to use App-Inventor. It is really worth it.

As you can see I defined 13 buttons. 12 Buttons for setting a colour on or off and 1 button for the Copyright announcement.

Copyright ???
Well not really. Off course this code is made by me and therefore I own the Copyright. However you are free to modify it to your own liking and needs. The code will be ready for downloading at the bottom of this text.

And lastly there is a Listpicker for selecting the Bluetooth device. In App-Inventor it looks like this:

And then we have the App-Inventor blocks (code). Look at them and see how easy it is to make an App. I can not emphasize this enough.

So how to use this App.

First click on the white button for choosing your bliuetooth device. Somewhere in the list (if there is a list) you will find the HC-06 module. Choose it and you will see that the blinking led will stop blinking and light up continuously. This indicates that the connection between your phone and the HC-06 has been established.

Now you can choose the individual colors red, blue and green and you will see the corresponding colors light up on the led-strip. Put them off with the corresponding black button.

Cyaan, Magenta, Yellow and White are combination colours. Yellow for instance is made by lightning up the red and the green leds. Magenta is a combination of red and blue and white is made by lightning all colors. So to put these colors Off you will need to switch off the individual colors by using the black texted buttons.
There is one special button with the name random. It is obvious what that does.

If you need more buttons or different functions you are welcome to add your own codeblocks.

OK for the code here we go. First the Arduino code. Next the App-Inventor codeblocks which you can import in App-Inventor and last but not least the ready to use Android APP.

So thats it. Till next time. Have fun.


Ledstripcommander listing

Ledstrip commander APK