In the hub bub of everyday life we forget to do many things. Some of those things like forgetting to switch off lights, fans and several appliances at home can cost us huge amounts which reflect in our electricity bills. This forgetfulness not only costs us huge bills but is also damaging to the environment as it wastes a lot of valuable resources. This problem has been addressed in our project with the creation of an automated home.
There are several technologies that have been used to create automated homes like Bluetooth, Zigbee, GSM technology, etc.The technology that we have used in our project to accomplish the ease and efficiency of fully automated home is MQTT along with the concept of Zone Beacons. The idea is to divide the house into several zones. Each zone with its own beacon and these individual beacons control only the devices connected to them.
In order to achieve the final result we used WIZnet’s S2E, along with Arduino UNO controlled by a mobile app.
Step One: Gathering Components
- Arduino UNO: It is the decision maker. It decides which device connected to it is switched on/off.
- Raspberry Pi: It acts as the broker for transfer of messages via MQTT.
- WIZ750SR/S2E: It is a protocol converter that transmits data sent by serial equipment (e.g. Arduino) as TCP/IP data and converts the TCP/IP data received through the network(e.g. Mobile App) back into serial data to the serial equipment. Hence, it receives data from the Android app installed on a mobile and transmits this data serially to the Arduino.
- WIZ750SR-EVB: This is the evaluation board for the WIZ750SR. The S2E can be fixed on top of this board.
- Relay Module: It is used to amplify the electrical signals received from the Arduino so that it can be used to power devices that operate on higher voltages.
Step Two: Set Up the Circuit
The S2E can be fixed on top of the evaluation board. The S2E acts as a protocol converter using its Ethernet MCU i.e. W7500P. It transmits the TCP/IP messages received from the mobile app as serial data to the Arduino board.
Since, our project works using the Zone Beacon technology, the setup for one of the zones of the house will be as illustrated below:
Take a female to female RS232 cable and plug it into the RS232 port of the S2E. The other end of the RS232 cable needs to be connected to the Arduino. In the RS232 female head, pin 2 acts as the transmitter and pin 3 acts as the receiver. These pins are connected to the Arduino digital pins 11 and 10 respectively. The ground of the RS232 (pin 5) is connected to the ground of the Arduino.
The device that we want to power using the app can be connected to the digital pins of the Arduino. In our project we have selected pins D7, D8 and D12 for this purpose. However, since the voltage supplied by the Arduino is not enough to power up devices used at our homes, we’ll be using a relay module to aid in the voltage conversion. The connections between the Arduino and the relay module are specified in the diagram above.
Step Three: Set Up Android Studio
The Android Studio IDE is freely available for download on their official website: https://developer.android.com/studio/.
Once the installation is done download the android code from the given GITHUB link. Open the downloaded file in the Android IDE. Then connect an Android device to the laptop via a USB cable. Then connect the device with the IDE. When connecting the device make sure that the developer option is activated in the settings of the device. The device should also be in debug mode.
Then run the code by clicking the green arrow button or using the “Run” option given in the menu highlighted using the red box in the image given below. These options upload the code onto the Android device in the form of an app.
After the setup and upload of the code onto a Android Device. The UI should look similar to what is shown in the images above.
Step Four: Set Up Raspberry Pi as MQTT Broker
MQTT is a lightweight publish-subscribe messaging protocol meant to be used by mobile devices and small sensors. The MQTT broker is responsible for receiving all messages and determining who is subscribed to each message, and sending the message to these subscribed clients. The MQTT client is any device that runs an MQTT library and connects to an MQTT broker over a network. In this project, we use a Raspberry Pi to act as the MQTT broker.
Raspberry Pi is a Linux based minicomputer. A MQTT broker can be easily installed in any Linux based OS with three simple commands :
- sudo apt-get update
- sudo apt-get dist-upgrade
- sudo apt-get install mosquitto
We set up the Raspberry Pi using the above commands. Once set up, all we need to make sure is that the broker stays switched on when trying to send data across from one device to another.
Also make sure that the Pi is connected to your local Wifi connection. Then note the IP address assigned to Pi after it is connected to Wifi. This is our broker’s IP address, it is necessary so that our devices are able to communicate.
This step is essential because when we use the Android app to turn on a device it publishes a request to the MQTT broker i.e. Raspberry Pi with the help of the IP address obtained above.
Step Five: Upload the Code to S2E
1. First and most step is to set the pin on the evaluation board of the S2E to BOOT mode and press reset. i.e. move the center switch (highlighted using a black box in the bottom left hand corner of the above image) to the right before starting the next step.
2. Then download the W7500P ISP tool from the following link : http://wizwiki.net/wiki/doku.php?id=products:wiz750sr:download:start.The ISP tool will look as shown below:
3. Connect the S2E to a laptop via its microUSB port to figure which COM number is assigned to it using “Device Manager”. The USB to UART driver can be downloaded from https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers if it’s not installed on your device. In the image below it can be seen that COM6 has been assigned to the S2E.
Then hit “Refresh” button in the ISP tool and select the appropriate port number from the drop down list. The baud rate should be fixed at 115200.
2. Then hit “Open” button in the ISP tool. If successful, one can see the result – “Serial Open Complete” in the left bottom corner.
3. The S2E uses ARM Cortex-M0 architecture. In order to program the S2E we’ll have to use the ARM compiler that can be accessed using: http://os.mbed.com/compiler. When you login into the compiler select the board as “WIZwiki- W7500P”.
4. Upload the “S2E_W7500P_Code” available in the “Code” section of this project into the Mbed compiler. Then compile the code and the corresponding bin file will be downloaded automatically into your system.
5. The next step is to open the W7500P ISP and select the bin file downloaded from the MBED compiler. Once selected, hit the “ISP Start” button to write into the WIZnet Board.
Step Six: Upload the Code to Arduino
The Arduino is the mastermind of the project. It decides which device gets the power supply based on the input from the mobile app. In our project we have used an Arduino Uno. It’s the one that is most commonly available in the market and can be purchased from any electronics hobby shop or even ordered online.
In order to use the Arduino we must first install its IDE. The Arduino IDE is easy to use as well as open source and can be easily downloaded from the official Arduino website. Once the IDE is installed, the next step would be to select the board. The board can be selected by going through the “Tools” option as depicted in the image below:
Once the board is selected. The port at which the Arduino will be available for serial communication needs to be selected as depicted below:
The next step would be to upload the “Arduino_code”(available in the code section of this project’s description) into the IDE. Once that is done the code can be compiled and uploaded onto the board by clicking the tick mark and arrow button respectively.
Step Eight: Final Result
We can use CoolTerm to test out the serial port, which can be downloaded from https://coolterm.en.lo4d.com/. CoolTerm will enable us to read all the messages sent to the COM port.
When the message is sent via the app the response output from the Arduino can be seen on the CoolTerm terminal.
The MQTT model, publishes the message from the Android app to the broker i.e. the Raspberry Pi, where the broker forwards the data to any devices subscribing to that data. In the case of our project, the S2E is the device subscribing to the data available with the broker. The data read by the S2E is interpreted by the Arduino and decision is taken on which device is to be turned on/off.