Satisfying LED Patterns
For many sleep has become a virtually unattainable commodity, a luxury reserved for the fortunate few who don’t feel the various strings of responsibility pulling them in different directions at once. Sleeping is vital and can help you feel refreshed throughout the day.
Counting sheep is not only an obsolete technique preached to us in childhood and now long gone, it is useless most of the times. Studies suggest that dim lights and patterns can not only help you sleep but also improve the quality of your sleep.
So here is An IOT based Bluetooth Controlled Sleep Inducing Night Lamp Using Arduino. This comes with an app consisting of 4 soothing and calming patterns, thus, making it possible for you to control these patterns straight on your lamp straight from your bed.
This works on bluetooth where the app sends data to arduino via bluetooth which interprets this data and displays the pattern as requested from the app.
It has 4 relaxing patterns:
- SPIRAL IN
- BARS
- FADE IN
- TRAIL
The setup is powered by a power bank so that your lamp is handy and you can take it wherever you want and due to minimal current consumption of 50 milliAmps it can stay lit for hours.
Now lets dig in and start building this awesome and useful sleep inducing lamp!!
PATTERNS
1) SPIRAL IN : In this pattern it looks as if a red dot is spiraling inwards to the center, something similar to the fibonacci spiral. For this , the logic is to turn on the LED for 1 millisecond, then turning it off and after that turning the next led on and so on. THIS IS BASED ON THE PRINCIPAL OF PERSISTENCE OF VISION
2) BARS : Just like the above pattern in this, instead of individual leds , parallel rows and columns will spiral inwards giving it a really soothing feel.
3) FADE IN : In this pattern the LEDs look as they are being sucked in , which makes a beautiful pattern
4) TRAIL : A slow pattern in which the LED seems to run across the Matrix which is really fun to watch.
Skills Required
The best part about digital electronics is that everything is either on or off and thus no matter how complex or daunting the task might look, it can be accomplished easily with a little effort.
One does not need to be an electronics expert to make this project but some skills are required to complete this project.
The skills required are as follows:
- Basic Electronics How to Solder.
- How to use a multimeter to check for shorting and other things.
- How to code in C to write the code for arduino however a fully funcitonal code will be provided.
- How to make an App either by coding (java, python) or without coding (using software's like mit app inventor).
Component List
As it is not a high-tech project getting the components won't be tough. You can find them easily online at cheap prices. Given below is the component list and amazon links to buy them:
- 1XBluetooth Module HC-05 https://amzn.to/2C3wGll
- 1X Mini Usb Cabke to connect arduino https://amzn.to/2SJpS3a
- 1XArduino Nano https://amzn.to/2TzfDij
-
1XDot Matrix Common Anode Red LED Display Module 8 * 8 8x8 3mm https://amzn.to/2VvpWFR
-
Electrical Tape, Jumper Wires, Zero Board, Conducting Wires, Cutters, Pliers, Wire Strippers, Digital Multimeter and a Power Bank to power the Lamp and superglue.
Finding Out the Cathode and Anode of LED's in the Matrix
As nothing is mentioned on the LED matrix about which LED corresponds to cathode and anode as well as to which row and column, we will use an arduino and two jumper wires.
To do so, we will connect one male to female jumper wire to the +5v pin of the arduino and the other pin to the Ground of arduino. Now connecting the jumper wires to the pins of LED matrix one by one we will find which pin corresponds to which row and which column in the led matrix and mark it as cathode or anode.
It is preferable to note somewhere as to which pin is Cathode and which is Anode for ease of remembering.
These results will vary based on how you have placed your LED matrix and because the Matrix is perfectly symmetric the position of cathode and anode pins will vary depending on how you position your LED matrix.
Assigning Pins of Arduino Nano
Here we will use 8 + 8 = 16 pins of the arduino to connect our LED matrix because we have 8 anodes and 8 cathodes.
Make sure you do not connect the LED Matrix's pins to digital pin 0 or 1 of the arduino as those are used for Rx and Tx communications and will be used for our bluetooth module.
I have used the following pins however, you are free to use any pin you want.
DIGITAL PINS 2,3,4,5,6,7,8,9,10,11
ANALOG PINS A0, A1, A2, A3, A4,A5
Above mentioned are the pins used by me.
MAKE SURE YOU DON'T USE A6 AND A7 BECAUSE YOU CANNOT DIGITAL WRITE ON THESE PINS.
Soldering the Components
Now comes the interesting part of soldering the components to our zero board.
Firstly, we will begin by super gluing a piece of zero board perpendicularly to our main zero board on which we will solder our LED matrix and this perpendicular piece will be used to solder the arduino nano just to make the entire circuit as compact as possible.
Next we will solder our arduino nano to the perpendicular zero board and our LED matrix to the main zero boards.
Next we will connect our Anodes of the Led Matrix to pins {2,3,4,5,6,7,8,9} and Cathodes of the LED Matrix to pins {10, 11, A0, A1, A2, A3, A4, A5} of the arduino. For this we will take some insulated connecting wires and strip it using wire strippers. I chose insulated wires so as to avoid shorting in our compact circuit. Now we will solder the anode to one of the pin corresponding to the pins assigned for anodes on arduino that is here {2,3,4,5,6,7,8,9} and same for all the cathodes till you get all 16 pins soldered perfectly as in the above pictures.
Now we will use a multimeter and set it on diode mode and check for shorting in our circuit. If the wires are shorted at some place we will use a soldering iron to heat that section and a suction pump to desolder it and will solder it again properly.
Next we want to connect the bluetooth module so that we can operate it and change the patterns wirelessly.
The bluetooth module consists of Vcc Gnd and an Rx and Tx pin. The Rx of bluetooth module goes to the Tx of arduino and not the Rx of arduino. I have connected the bluetooth module to the nano using jumper wires so as for easy debugging of code because you cannot upload your code to nano with the Rx and Tx pins connected. However I will provide you with my final code so you can directly solder the Vcc and Gnd pins to the nano and the Rx and Tx pins once you have uploaded the code to arduino. If you too use jumper wires for ease of accessibility of the bluetooth module your final board should look like the one in the above pictures.
You can see other instructables on how to set up a bluetooth module because we will not discuss that here.
That's all for the soldering and electronic's part.
CODE - Based on the Principle of Persistence of Vision
If we try to glow two diagonal LED's giving high to the Anode and low to the Cathodes of the corresponding rows and columns it won't work as instead of turning on 2 LED's it will turn on the 4 LED's at the cross-section of those rows and columns.
So we use the concept of persistence of vision according to which if two LED's glow one by one with time delay between them less than 100 milliseconds our eye will not notice the 100 milliseconds time period when both the LED's were off and it seems as if both the LED's were on simultaneously.f
This is used everywhere in the code to turn on LED's so that only the desired LED's turn on and not the undesired ones.
The code is attached below because of it's length.
Downloads
Application to Control Our Lamp
If you know how to develop applications using java or python or any other language you can continue with that and feel free to make your own app with your desired interface. You can see the interface of my App for reference purpose.
(In the above screenshots I have blacked out the names of first three bluetooth connections for personal reasons.)
However if you don't know application development or if you are a beginner feel free to use my app. The APK is provided below.
Downloads
Application Tutorial
To install the application you will first have to go to your mobile settings and allow installation from unknown sources. Once you have installed the APK turn on your bluetooth and make sure you have paired the Bluetooth Module by the name of HC-05 or HC-06 with your phone.
Once you have paired the module open the app again and click on connect.
Then select the module from the list of the paired devices list available.
You can 3-d print your own casing for this project whichever way you want.
Now all you have to do is keep your lamp along with the power bank powering it wherever you want in your room select the desired pattern and look at the soothing patterns and wait for the magic to happen as you slowly and peacefully fall asleep!!