Introduction: Project Wemo
I study NMCT at Howest, as part of the finals we needed to create this. In this instructable I will explain how to build a smart outlet using a Raspberry PI and a couple of arduino's. To recreate this project you will have to possess some basic knowledge. I will also give you a list of the required materials for this project. I will explain how to use all of the parts needed.
How this supposed to work: The raspberry pi(RPI) is the main "brain" this controls everything. The RPI will receive the powerusage over RF(315Mhz) and will send it to the site, it also will turn them on and off over RF(433Mhz) which it will read the state from the Database.
The basic skills needed
- Python knowledge (Raspberry Pi),
- HTML and CSS knowledge,
- Knowledge of MySQL and databases,
- Knowledge of electrical circuits,
- Basic soldering skills,
- Installing LAMP stack/ some linux experiënce.
Step 1: Parts and Tools Needed.
As you already know, they communicate over RF, from arduino to arduino so for 1 outlet you would need 1 RPI and 2 arduino's of any kind. In this project we used 1 nano(RPI side) and one Pro mini(outlet side). for each extra outlet it adds one arduino. The casing was made of a single sheet of MDF.
- 1 Raspberry pi model 3B = 40€
- RF sets(they come in pairs) = 0.50€
- 5v 2a power supply
- Arduino pro mini/nano = 2€
- Current sensor 20A = 1.6€
- Power inlet = 1.15€
- Power outlet = Approx 2.5€ (came in pack of 4)
- Heatshrink(i bought a random assorted pack) = 1.8€
- Red, Black and yellow cable = 6€
- MDF sheet(1220-620-8mm, only used half) = 6.5€
- Some more cable, but more heavy duty.
- a hinge( i had one laying around)
- 1 stripboard = 1€
- Arduino pin headers = 2€ a pair
- Palm sander,
- Hot glue gun,
- Reciprocating saw,
- Circular saw,
- Soldering iron,
- Wood glue,
for the arduino Pro mini you need a FTDI connector!
- FTDI = 2.7€
Step 2: Building the Case
The case is pretty personal, i just bought one sheet of mdf. The shop cut it for me in 2 strips of 80, 2 strips of 100 and 2strips of 72. With one sheet i was able to make 6 cases, a rpi case and still had approximately half left over.
building these cases:
- 2 pieces of 80-80
- 2 pieces of 80-100
- 2 pieces of 72-84
1 one 80-80 piece i fitted the inlet, in the other one the outlet.
Step 3: Wiring It All Up.
Before we can test any code(except for the web part) we need to have everything connected.
First we start with connecting the outlet side.
Take the stripboard and cut it to size, if you take a knife and cut twice on the line you can brake it pretty straight. solder the arduino headers on the stripboard and also the sender (smaller pcb) and receiver(longer pcb). the connection is pretty straight forward, the only important thing is that the data pins of the RF modules must be PWM, i used 6 for receiver and 11 for sender. Also make sure that you have a positive lead and negative lead from the arduino so we can power it, once it has the code on it.
Next we will connect the relais to the arduino. Connect VCC and GND to the power supply, not the arduino, the in1 pin is connected to D3.
Next is the current sensor, again VCC and GND to the power supply and then pin OUT to A0.
Now you solder the GND and 1 of the AC side to the inlet and connec it to the outlet. The other one you route from inlet to current sensor, form current to relais, from relais to outlet.
And don't forget to wire in the power supply for the arduino.
i secured all the components with a little dab of hot glue.
The pi side, is pretty straight forward, you just connect the sender and receiver the same way as the outlet side.
Step 4: RPI Setup
To be able to use a Raspberry Pi 3, you'll need to have a micro SD card. Firstly, you'll have to install an OS on it. To do this, simply insert the SD card into your computer and put the OS on it. To put the OS on the SD card, i recommend using ' Win32DiskImager'. The OS itself is called 'Raspbian-jessie-with-pixel'.
When all this is done, you have to open the windows explorer. Then go to the SD card, and search for the file 'cmdline.txt'. When you have opened this file, add the following code to the file 'ip=169.254.10.1'. I included a picture of what the file should look like. When this is done, you can remove the SD card from your computer and insert it into the RPI. Using a LAN-cable, you can connect to the RPI through putty. Simply connect to the address that you put in the cmdline.txt file. To log into the RPI, you'll need to use:
Installing the LAMP stack:
<p>apt-get update</p><p>apt-get install apache2</p><p>apt-get install mysql-server</p><p>mysql_secure_installation</p><p> Enter current password for root (enter for none): </p><p style="margin-left: 20px;">OK, successfully used password, moving on...</p><p style="margin-left: 20px;">Yes to all</p><p>apt-get install php5 php-pear php5-mysql</p><p>sudo apt-get install phpmyadmin</p><p> select the database you want to use</p><p>service apache2 restart</p>
after this if you type the PRI's ip on your pc's browser you should see something like the screen above.
Step 5: Setting Up Database and Site
first go to rpi's ip/phpmyadmin. click new in the top left corner and create a database called 'project', after this is done you can import this database which is found on github.
next on you raspberry pi, you type the command:
sudo apt-get install filezilla sudo chmod 777 var/www
next you connect via filezilla on your laptop. you browse to the path var/www/html. everything that is found in the folder html should be deleted.
all these files should be put in that folder.
if you go in your browser to the ip you should see the site, the username is howest, the password is Win$4ever