Intro: Raspberry Pi Light Controller
Did you ever go out and realised you left some of the lights on at home? Then this is project is something for you! This light controller lets you control your lights through your smartphone or computer.
This is a prototype to represent a house to show how it would work.
In this instructable I will explain to you how to build this prototype using a Raspberry PI, MySQL database and Flask. To recreate this project you will have to possess some basic knowledge of Python, Flask, HTML, CSS, Raspberry Pi and MySQL.
This project is an assignment for school.
Step 1: The Materials
- Raspberry PI 3 (1x)
- Relay Card (1x)
- Female to Female connectors (13x)
- Junction box (1x)
- SD card 16GB (1x)
- Model material (depends how big you want it)
- Power supply 12V 1500mA (1x)
- LED lamps (8x)
- LED foots (8x)
- Cable shoes (16x)
- Vines (4x)
- PIR motion sensor (1x)
- Cable connector (8x)
If you have to buy everything your total cost will be around 147 euros, this may be less or more.
For more information about where I bought my materials check out the Bill Of Materials.
Step 2: Making the Database/ Electric Circuit
You should be able to setup the MySQL database with the picture above.
I used 2 batteries in the electric circuit but this should be replaced with the 12V power supply (I wasn't able to find it on Fritzing).
Step 3: Building the House
I started out with drawing a plan of the house with the dimensions it should have to make sure everything would be alright.
After I had all the dimensions I started cutting the pieces needed to build the walls.
Then I drilled the holes for the cables to reach the LEDS, and then I glued the LEDS on the bottom.
Step 4: Electric Circuit
To start with the electric circuit you should start with wiring the cable connectors and the relay card.
For the cable connector it is pretty straight forward, at one side you connect everything with each other (and the - side of the power supply) like in the first picture.
On the other side each hole is used to connect the ground of the LED.
For the relay you connect every middle hole (and the + side of the power supply. like in the second picture.
The left hole is used to connect + of the LED
The 3th picture is how I placed everything in the junction box (you may change this to however you like it)
Step 5: The Software
I made 1 login page, 2 pages to control the lights and 1 page to see what lights are on or off.
You can connect to the site with the following apipa: 169.254.1.1:8080
The first picture shows the login page, this is necessary so not everyone is able to turn your lights on and off. I used the user 'webuser' with the password 'lightz'. But if you click on register you can make new users if you have the register code that is displayed on the prototype (you can change this in the code to whatever you like).
The second picture shows the overview, the red dots mean the light is turned off. If a light is turned on you will see a green dot.
The third picture shows the page to control each light individually, you can put a light on or off or you can turn all lights on or off, this feature is good if you are leaving the house and you only have to press one button to turn off all lights.
The fourth picture shows the page to setup some timers or periods to turn lights on. The first option allows you to select a light and give it a time to turn on the light and a time to turn it off again without you doing anything. The second option allows you to turn on a light a given time and turn off when that time is over.
All the code for this project can be found on my Github.
Step 6: The Final Product
If you have done everything correct you should have a working product looking like the picture.