Smart Light

by glenntroncquo in Living > Decorating

246 Views, 0 Favorites, 0 Comments

Smart Light

104336529_2790222581106038_4379202814221380489_n.jpg

Too lazy to turn on/off your bedroom light while in the night? Or are you stuck in the middle of the night searching for your bedroom light switches? Maybe you should try building a Smart Light!

I'm a student at Howest Kortrijk who studies Media and Communication Technology (MCT). For my end project of my first year I decided to make a Smart Light. As I'm a lazy person I thought it would be a great idea to control my lights from my phone/computer.

Besides controlling the lights and changing the collors I added some features to make it more interesting and fun. For this project I made website, a MySQL database and the system code run on the RPi and Arduino.

FEATURES

1. Control lights from distance and change the colors
2. Leds will turn on if it detects movement
3. Make the leds turn on if it's dark enough

On the website you will be able to turn on one of the features, if one features is selected the other will be turned off. You will also be able to see the history of the sensors and also turn off the RPi. On the lcd display you will see the IP of the RPi.

In this instructable I will guide you through each step so you can recreate this project for yourself.

Materials: What Do You Need

Circuit:

Most of the parts you can find in a DIY store.

  • Raspberry Pi Model 3 or 4
  • Arduino
  • APA102 Ledstrip
  • PIR Motion Sensor
  • LDR
  • TMP36 Temperature Sensor
  • Jumper Wires
  • T-Cobbler
  • LCD 16x2
  • SD Card (8GB MINIMUM
  • Resistors
  • Potentiometer

Case:

  • Wooden housing with open lid (I found some kind of wooden bowl in my house)
  • Cardboard (I used this as a lid since it's easy to cut and I could easy cut holes in it)
  • White paint (Definitly not needed, I used this to paint the cardboard)
  • Glue

A detailed list of parts with a link to the shops is given below in the BOM.

Construction

Capture.PNG

Connect the wires as above. I use serial communication over USB between the raspberry pi and arduino you could also use a level shifter.

--> NOTE: I could not find a fritzing component for the APA102 Ledstrip so I used another. The APA102 has CLOCK and DATA.

Database Scheme

Capture.PNG

My database has 3 tables:

  • Meting (measurement)
  • Actuator
  • Sensor

When the device is turned on, the temperature, motion and light resistance will be written every 5 minutes to the database. The motion will also be added when there is movement detected. This way we get a clear overview of the past. Make sure you get the database running on the pi. You can do this by making a new connection in mysql workbench and connect via ssh with the pi.

Setting Up the Pi and Arduino

Arduino:

There is not much configuration to do on the Arduino. Make sure you have installed Arduino on your computer. Launch Arduino, connect your Arduino to the pc via usb cable. Select the right arduino and the right port and upload the code.

Raspberry PI:

For the pi set it up so that it is connected to your network. We will be using serial communication and the one wire. You can enable this in raspi-config. For the coding I used ssh connection in vs code. Put the code of the frontend in the map www/var/html and the backend code in home/pi. If you set up everything correctly you should be able to connect wireless to the pi by entering the ip address of the pi. Don't forget to run the app.py. You could also make a service so that the app.py runs automatically on startup.

For the code you can go to my Github

If everything is set up we can start with the housing.

Housing

103965472_254600669132125_3234255728366636743_n.jpg
104298372_1130346834016790_2621882720577934584_n.jpg
104428144_558581878132947_3577904498244033677_n.jpg
104297453_737508493669128_1089676273009077135_n.jpg
104099396_264189901561537_2187241783960985522_n.jpg
104597760_263621105071084_6435230850988094843_n.jpg

There is not much to do in this step. Put everything in the wooden comb. Make 4 holes in the cardboard, 3 for the lamp holder and one in the middle for the pir sensor. Paint the cardboard in white if you want. Now just put the cardboard on the wooden comb (glue it if neceserry) and put the lamp holder in. Now just place the ledstrip inside the lamp holder