RPi IoT Smart Light Using Firebase

Demonstrated with a 3D printed case, a Pi Zero W, a Powerboost 1000C, a battery and a Blinkt!

Introduction

This guide shows you how to make and setup an app to control the Raspberry Pi via Firebase (A online database).
And then 3D printing a case for the Pi Zero W, a Powerboost 1000C, a battery, and a Blinkt!.

To be able to follow along most easily, i recommend being familiar with Xcode and Raspberry Pi.

3. In the viewDidLoad function, under the super.viewDidLoad(), insert this line for each button (For multiple buttons, just change the (number). See picture...) :

num1(state: "OFF")

Layout of the Main.storyboard and buttons

1. Go to the Main.storyboard, and put in some buttons. You could layout them like I did, or customize them as you like.

2. Connect the buttons with the ViewController. Each button need to be connected twice:
One as an action and UIButton called num(number)Button, and the other one as the default Outlet and call it num(number)Color. See picture...

3. Then for all of the buttons, paste in this line to each of the functions. See picture... :

6. Fill in your Firebase ApiKey and ProjectId. You can find these by going to your Firebase Project, and clicking Add Another App and then Add Firebase to your web app. Here you can copy your ApiKey and ProjectId.

7. Customize the functions, and save your changes by pressing ctrl-o(enter) and close with ctrl-x.

8. Now run it with:

sudo python3 RPiAppControl_Template.py

9. Then if you are using a Blinkt, you can try the example, when you have filled in your Firebase ApiKey and ProjectId:

cd examples
nano RPiAppControl_blinkt_demo.py

sudo python3 RPiAppControl_blinkt_demo.py

Keep in mind that after you run the script, it takes about a minute to get ready (At least on the Pi Zero). And the script has to be run in python 3.

10. BONUS: If you want the script to run on boot, you can find out how, here.

Assembly

1. Solder wires as shown on the circuit diagram. The wires are NOT to scale.

2. Screw the Powerboost to the Powerboost Rest, ontop of the stand-off's, with small scrap screws.

I recommend punching holes in the stand-off's, to give the screws a better grip.

3. Place the components in the box, as shown on the picture. The Pi shall sit on the smallest stand-offs, and the Powerboost Rest ontop of the battery. The switch and button have to be set into posision and through the cut-outs.

4. Screw the components down with screws.

5. Snap on the lid, by putting it down at an angle. To remove it, use a nail or a small screwdriver.