Before starting the project,
Now considering room scenario, an Arduino UNO will control devices and reads sensor data. Periodically, Raspberry Pi requests for the sensor data collected by Arduino UNO. The figure"Room Architecture"depicts how the Arduino UNO will connects with the devices and sensors. Each room have multiple controllable devices(i.e. Light(s), Fan, Wall Socket(s), etc.), one PassiveIR (to detect human presence in the room), one temperature sensor (LM35 to collect room temperature) and LDR (to detect light intensity near room window).
The most important part is how we will identify devices? Its simple. We will make device address by combining room number with device number.
Room Number 1 having three devices.
Device address will be:
So up till now we know the overall configuration. In short, a Raspberry Pi will act as primary controller. Each room have its own one Arduino UNO which act as slave of Raspberry Pi. Communication between Raspberry Pi and Arduino UNO will be done using I2C.
To make it more easy, lets start implementing for
Note: I2C address for Room 1's Arduino is 0x40. You can change
addressbut make sure to change it back in Aruino's sketch and room's slave address in the app provided below, too. Note that each Arduino resides on the bus must have unique slave address.
I2C Bus Stripe: To attach more than one Arduino you can use I2C Bus Stripe as
The relay shown in the schematic
are operatedby 5VDC. You may have different rating of coil to drive relay. In such situation you need logic level converter circuit.
WARNINGPlease make sure that the device is disconnected from the wall outlet and outlet is switched-off. Parent observation is required for small children.
WARNING: IN CASE OF ANY PROBLEM, SHUT DOWN HOUSE'S MAIN LINE OR ROOM'S TRIPPER LIKE MCB OR ELCB AND CALL ELECTRICIAN. PARENT OBSERVATION IS REQUIRED.
All done at hardware side. Now its time to build software.
Our project consists of a Raspberry Pi 2 and Arduino UNO. Raspberry Pi 2 software developed in Visual Studio 2015. I am assuming that
Arduinois new for you, please refer this link. For Raspberry Pi 2 beginner, please refer this link.
Let's understand software in following
Before going further,
I have defined protocol for sending and receiving bytes. Sending bytes are fixed of three while receiving byte array is
Refer following schematics to understand protocol defined for this project ('X' denotes random value or '0', it will be ignored while communicating):
If you are newer to I2C of RPi2 (Windows IoT Core), refer this link. If you are newer to Arduino's I2C,
referthislink. There is an article available for Arduino I2C Communication with RPi2 (Windows IoT Core) written by Christiano Faig.
Now, we have defined a proper communication scheme that is able to give status and values of sensors, devices and also provides accessibility to set device state.
As discussed first, this project considered whole home.
Primary class"Home"consists of multiple room objects as
Note: Class diagram is provided in
project. To view it, goto'Solution Explorer' and double click on ' ClassDiagram . cd'.
Any application must be user-friendly. To make user-friendly application, start with wire-frame. Assume that you are going to use your own application and find out the main objectives and how to integrate them in such way that they will be
To do so, I have
Based on the wire-frame, I have developed
I am assuming that you are familiar with XAML
So, have already developed UI. Hope you can modify it
I have tried to make this software as easy as possible. With
You can attach water-pump and geyser same way you add device. But you can't attach water-pump or geyser directly to the relay board to power them up. It will blow-up relay board as well as hazardous.
WARNING: DO NOT CONNECT WATER-PUMP OR GEYSER DIRECTLY TO RELAY-BOARD. IT IS HAZARDOUS. YOU NEED CONTACTOR TO OPERATE HIGH CURRENT DEVICES LIKE WATER-PUMP OR GEYSER. IF YOU DO NOT KNOW, PLEASE CONSULT ELECTRICIAN. YOU CAN FIND DETAILS ABOUT CONTACTOR BELOW IN PART LIST.
To operate water-pump or geyser, connect water-pump or geyser with contactor and connect contactor's coil with relay board. So now, when you operate device, relay activates contactor's coil and thus pump or geyser starts/stop. Before purchasing contactor, please make sure its coil rating and contactor's rating. Contactor are available in so many variety. So verify it with your water-pump's rating. It is advisable to purchase slightly higher rated contactor than your water-pump's rating.
WARNING: DO NOT TOGGLE DEVICES QUICKLY. IT MAY FRY DEVICE AND MAY LEAD TO ELECTRONIC SHORT-CIRCUIT. IN CASE OF ANY PROBLEM, SHUT DOWN HOUSE'S MAIN LINE OR ROOM'S TRIPPER LIKE MCB OR ELCB.
You can refer this link to understand deployment process.
Lot's of hobbyist wants their application start right after the Raspberry Pi 2 boots. To do so, read my article: Windows 10 IoT Core : Setting Startup App
When Arduio boots, it flickers D13 pin. It is good to do not connect any relay pin on D13 because when Arduino boots or reboots, D13 will be flickerd once and if any device connected with Relay (controlled via D13) will flicker, too.
Solution: There are two options: first one, simply do not connect realy with D13. Second one is bit complicated. You can rewrite Aruino's OptiBoot firmware that do not use D13 while booting and burn that bootloader to Arduino.
Raspberry Pi 2 does not have on-board Real Time Clock chip. Thus it is not possible to maintain time after power-failure or fresh boot. Thus external RTC must be attached and programmed to maintain date time.
Solution: NTP can be used but needs Internet connection or even Arduino can deals with RTC and Raspberry Pi requests for the date time at boot. It is also good to attach external RTC directly with RPi 2.
I had faced many issues while developing Universal App in C#. Universal app is superset of WinRT and thus so much asynchronous operation needed to be performed. If error arises in asynchronous operation, it becomes headache to solve. Whenever any exception or error occurred, most of time I faced following screen:
No point to the error prone line, no programmer friendly message, nothing. I have to place so many breakpoint to find out the cause of the error. In debugging, sometimes universal app just shuts-down without any prior notice and suddenly my watch window becomes useless. The cause of the behavior is described at this link.
Solution: Place breakpoint before the expected error prone line.
In short, at this moment (while this article was published) universal app is great but lacks of debugging features as conventional Windows application have.
There is no limitation when it comes to features, new ideas or even to overcome
Good Luck & Be Safe :)
Feel free to ask for help or questions.
This tutorial is originally created by Anurag S.