Introduction: Easy Wake-Up: a Smart Wake-Up Light Made With Raspberry Pi
For the curriculum Project1 I had to make something. I was always fascinated about how a wake-up light like would benefit you in waking up like the ones from philips.
So I decided to make a wake-up light.
I made the wake-up light with a Raspberry Pi as base, a led strip, speakers and a couple of environmental sensors to get measurements.
Here are its features:
- Webserver gets hosted on the Pi
- Data gets exported to a MySql database
- Webpage that shows data
- Webpage that execute statements
This project has been a great learning experience for me. It got me solving some unexpected problems. I learned quite a bit about the capabilities of the Pi and how php communicate with everything.
Step 1: Gathering the Materials
For my project I need it multiple parts that I will be listing below, There will be also an excel file with all the the prices of the components with corresponding websites from where I ordered them.
- Raspberry Pi 3 model B+
- Raspberry Pi power supply
- Raspberry Pi T-cobbler
- Stereo 3.7W Class D Audio Amplifier-Max98306
- 2 x Speaker - 3" diameter - 4 Ohm 3 Watt
- RGB Backlight negative LCD 20x4
- Adafruit Dotstar Digital LED Strip - White 144 - 0.5 meter
- Ultrasonic sensor HC-SR04
- DHT11 sensor
- Jumper wires (m to f) and (m to m)
- 470 Ohm & 330 Ohm resistor
- MDF wood 7mm
- Soldering iron
- Glue gun
In total the materials will cost around 210 Euros.
Step 2: Wiring All the Compenents Together
I build the circuit by following the Fritzing scheme that I made, you can find the documents pdf of the breaboard and electrical scheme below.
The circuit has multiple sensors, speakers, lcd display and a led strip that works together as one. I will list for each component on how you will need to connect these and can find in the scheme.
- The Ultrasonic sensor: this sensor calculates the distance between the sensor and a object in front of him. With this function we can automate certain abilities by holding your hand infront of it. It has 4 pins: ground, 5V, trigger and an echo. Echo output needs resistors between the ground and the echo pin.
- The DHT11 sensor: this sensor measures the temperature and the humidity. If you buy one with a PCB than the 10k resistor is soldered with the sensor already and makes it super easy to wire it up.
- The ledstrip: for the ledstrip an external power supply is need it to power it up otherwise you can dmg your raspberry pi without using one. DI wire goes to the MOSI pin of the pi and CI goes to the SCLK pin.
- The lcd display: specially the rbg displays requires alot of wires, all of used pins of the pi can be used with normal GPIO.pins. It also has a potentiometer with it to change the contrast of the display.
- The push button: I use it to put the raspberry in shutdown mode and by pressing again to wake-up mode. Normally open connection is need it for it.
- At last the amplifier with the speakers: since we use just speakers we need an amplifier to make the signal strong enough to produce sound. Its connected with the audio input of the raspberry pi.
Step 3: Setting Up the Pi
First of all you will need Raspbian which you can download here.
I used a monitor connected with the hdmi of the raspberry pi after installation of the sd card. With mouse and keyboard connected to the usb ports of the pi. Then you follow the begin settings on the screen to initialise the raspberry pi, make sure to change in the configuration panel certain functions like SPI, I2C, ... to enable.
Enter the following command in your command prompt on your Pi:
sudo apt-get update
This may take a while, so get comfortable. After the update we will upgrade
sudo apt-get upgrade
Step 4: Installing Modules & Packages and Setting Up the Webserver
We install each modules for python with:
sudo pip3 install name_of_module
List of modules need it:
There could be more but if you get an error that says can't find the module, just install it.
Also the following command, because you need version 3.4 and not 3.3!
python3 -m pip install --upgrade --force-reinstall spidev
For setting up a webserver I used flask.
Step 5: Applying the Code
For the code you need to make sure that everything is in the folder of /var/www/html
You can get the code from Github.
The site is also responsive so it could be opened on mobile without losing features or otherwise.
While the Pi is booting up, it will start running my main python script. This will be taking care of getting the data to show on the website. To add a script on boot you need to do systemd preferable way. Check link.
For the button you need to use physical pin 5 of the pi and the ground. Use pins on the button, normal open pin and common pin. Btw polarity doesn't matter!
Do the following commands in the terminal of your raspberry pi and you should be able to shutdown and startup your pi with the button press.
git clone https://github.com/Howchoo/pi-power-button.git
Step 6: Building the Housing
For the housing I used scavanged wood that I cut into pieces and putted together by glue. For making the front a bit slant I had to calculate the slant side because when you don't calculate it, even if it's not a huge slant the wooden pieces won't fit together.
You must always be very careful with the measurements on the wooden pieces, because you can sometimes forget the thickness of the wood.
The holes were done with drill and sawing machines.
After that was done you can start painting it, I used spray painter with brown color for it. Make sure you do it outside and try to stand away from where the toxic fumes are going to.
For the speaker and the backside I used scews to connect them.
The top I used plastic that also got glued.
Finnaly I added some device feets.