Chapter 4. Wi-Fi Smart Power Plug
In this chapter, we will build an open source version of a very commonly connected object—a Wi-Fi power plug. Indeed, these kind of plugs can be bought from many stores, and usually come with their own iOS or Android app.
In this chapter, we will build such a power plug from scratch, based on Arduino. We will connect a relay module, a current sensor, and a Wi-Fi module to an Arduino board to make our own Wi-Fi power plug. The power plug will be able to switch any device on and off, and will continuously measure the power consumption of the device.
We will build an Android app to switch on and off the power plug remotely via Wi-Fi. We will also be able to get the power output on request and display it on a screen.
The following topics will be the major takeaways from this chapter:
Connecting a relay module, a current sensor, and a Wi-Fi module to Arduino
Controlling the project by sending commands via Wi-Fi
Building an Android application to control the project...
Hardware and software requirements
First, let's see the required hardware components for this chapter.
We need an Arduino Uno board. To control the lamp remotely (the lamp was used as an example in the chapter, but of course any 110V or 230V device can be used here), you will also need a relay module. We used a 5V relay module from Polulu, but you can use any 5V relay module that you want.
To measure the instant power consumption of the device connected to the plug, you will also need a current sensor. For this part, we will choose a breakout board based on the ACS712 chip. The following is a picture of the board I used:
You will also need a board that includes the CC3000 Wi-Fi chip, which we will use to receive commands via the Android device. For this project, we will choose a CC3000 breakout board from Adafruit. Of course, you can also use a shield from the same brand for this project; the code will be exactly the same.
To make the different connections, you will also need a breadboard and...
Writing the Arduino sketch
Now that we are sure that the connections of the relay, the current sensor, and the power cables are correct, we will write an Arduino sketch to accept connections coming via Wi-Fi from the Android device.
The following is the complete sketch for this part:
We created a DIY version of a smart power switch, based on Arduino, and controlled by an Android application via Wi-Fi. We connected all the required components to the Arduino board, wrote an Arduino sketch to accept commands via Wi-Fi, and finally, created an Android application to control the switch remotely.
In the next chapter, we will use another Arduino board, called the Arduino Yún, where we will be able to plug an USB camera. As this board will have Wi-Fi as well, we will use the project to create a remote Wi-Fi security camera.