Things used in this project

Hardware components:
A000066 iso both
Arduino UNO & Genuino UNO
For each room you want to automate, take separate Arduino UNO.
×1
R8326274 01
Raspberry Pi 2 Model B
×1
11026 02
Jumper wires (generic)
×1
12002 04
Breadboard (generic)
×1
LDR (Light Dependent Resistor)
LDR provides different voltage reading for different light intensity.
×1
13285 01
PIR Motion Sensor (generic)
Passive IR detects human presence.
×1
Relay (generic)
You can use any kind of relay module. No of relay will depend upon how many devices you want to control. [NoOfDevices = NoOfRelay]
×1
Siemens Contactor (3TF32 00-0AP0)
Contactor is going to be used to control water-pump of maximum rating of AC3: 16A 415VAC. Before purchasing contactor, please check ratings of your water-pump and your contry dependencies if there. "3TF32 00-AP0" is capable to drive up-to 16A and 415VAC water-pump. This contactor operates usinf in-built coil. Coil ratings are (specific to 3TF32 00-0AP0 only) 250VAC.
×1
Miniature Circuit Breaker (1P C16A)
MCB is attached before contactor to protect water-pump from electrical faults and overload. Here MCB also have specific ratings. Our contactor is of 16A and thus I have used 16A MCB. You can modify according to your convenience.
×1
Software apps and online services:
Ide web
Arduino IDE
To write Arduino firmware. Have explain in the article.
Vs2015logo
Microsoft Visual Studio 2015
Community edition is commanded and its free for up-to five users. But you can use higher than it if you have purchased licensed copy of Visual Studio 2015.
10
Microsoft Windows 10 IoT Core
As a primary OS, which controls the devices via Arduino and provides management console.

Schematics

Schematic for one room
You can add multiple room by attaching individual Arduino with unique I2C slave address on the bus.
%5benhanced%20updated%5d%20main%20circuit%20diagram
Fritzing Schematic File
Fritzing file containing complete schematic.
Home Automation Schematic - Anurag S Vasanwala.fzz

Code

Arduino SketchC/C++
/*
	Arduino Sketch v0.4

	This sketch is written for "Home Automation using Raspberry Pi 2 and Window 10 IoT"
	Refer this link: https://www.hackster.io/AnuragVasanwala/home-automation

	This sketch is tested on Atmega328p only.

	This sketch prepares an Arduino device as slave	device on I2C bus operated by
	Raspberry Pi 2 running Windows 10 IoT Core.

	Objectives:
		+ Periodically collect sensor data (Function: loop)
		+ OnRecevive, collect 3-bytes mode instruction
		  and performa operation based upon it. (Function: ReceiveData)
		+ OnRequest, send 14-bytes response array based
		  on selected mode by OnReceive. (Function: SendData)
	
	This sketch is provided as it is without any WARRANTY. You can use it for personal as well as
	commercial use.

	I am not liable for any loss of data or injuries caused by this sketch.
*/

#include <Wire.h>  
#define _DEBUG_

/* Arduino's I2C Slave Address */
#define SLAVE_ADDRESS 0x40

/* PIN DECLARATION */
int Pin_AmbientLight_LDR = A0;
int Pin_PassiveIR = 2;
int Pin_Temperature = A1;

/* Global Variable */
volatile short Value_AmbientLight_LDR, Value_Temperature;
volatile bool Value_PassiveIR;

/* Protocol Variable */
byte Mode, Pin, Value;
byte Response[14];


void setup()
{
	// Initialize pins
    pinMode(Pin_AmbientLight_LDR, INPUT);
    pinMode(Pin_PassiveIR, INPUT);
    pinMode(Pin_Temperature, INPUT);
    pinMode(0, OUTPUT);
    pinMode(1, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);

#ifdef _DEBUG_
    Serial.begin(9600);
#endif
	
	// Initialize I2C Slave on address 'SLAVE_ADDRESS'
    Wire.begin(SLAVE_ADDRESS);
    Wire.onRequest(SendData);
    Wire.onReceive(ReceiveData);
}

void loop()
{
  // Read LDR
  //         Arduino supports 10-bit Analog Read.
  //             Thus we need to convert it into 8-bit.
  Value_AmbientLight_LDR = analogRead(Pin_AmbientLight_LDR);
  Value_AmbientLight_LDR = map(Value_AmbientLight_LDR, 0, 1023, 0, 255);
  
  // Read PassiveIR value
  Value_PassiveIR = (digitalRead(Pin_PassiveIR) == HIGH) ? true : false;

  // Read Temperature Sensor and Convert Voltage into Celsius
  Value_Temperature = (short)((float)(analogRead(Pin_Temperature) * 0.48828125));
  
  // Wait for 100 ms
  delay(100);
}

// Callback for I2C Received Data
void ReceiveData(int byteCount)
{
	// Read first byte which is Protocol Mode
  Mode = Wire.read();

	// Read second byte which is Pin. Only Valid for Mode 2
  Pin = Wire.read();

	// Read third byte which is Pin-Value. Only Valid for Mode 2
  Value = Wire.read();

	// Signal specified pin if Mode 2 is received
  if (Mode == 2)
  {
      digitalWrite(Pin, Value);
  }

#ifdef _DEBUG_
    Serial.print(Mode);
    Serial.print(" ");
    Serial.print(Pin);
    Serial.print(" ");
    Serial.println(Value);
#endif
}

void SendData()
{
    switch (Mode)
    {
        case 0: // Mode: Read Sensor
            Response[0] = (byte)Value_AmbientLight_LDR;

            // Value_PassiveIR is boolean so that we need to convert it into byte
            Response[1] = (byte)((Value_PassiveIR == true) ? 1 : 0);
            
            // Response[2] byte is Sign byte for Temperature
            //         0 - -ve Temperature
            //         1 - +ve Temperature
            Response[2] = (byte)((Value_Temperature < 0) ? 0 : 1);
      
            Serial.println(Value_Temperature);
            
            // -ve Temperature can't be sent in byte. Convert it into +ve equivalent
            Response[3] = (byte)((Value_Temperature < 0) ? (Value_Temperature*(-1)) : Value_Temperature);
            break;
        case 1: // Mode: Read Devices State
            Response[0] = (digitalRead(0) == HIGH) ? 1 : 0;
            Response[1] = (digitalRead(1) == HIGH) ? 1 : 0;
            Response[2] = (digitalRead(3) == HIGH) ? 1 : 0;
            Response[3] = (digitalRead(4) == HIGH) ? 1 : 0;
            Response[4] = (digitalRead(5) == HIGH) ? 1 : 0;
            Response[5] = (digitalRead(6) == HIGH) ? 1 : 0;
            Response[6] = (digitalRead(7) == HIGH) ? 1 : 0;
            Response[7] = (digitalRead(8) == HIGH) ? 1 : 0;
            Response[8] = (digitalRead(9) == HIGH) ? 1 : 0;
            Response[9] = (digitalRead(10) == HIGH) ? 1 : 0;
            Response[10] = (digitalRead(11) == HIGH) ? 1 : 0;
            Response[11] = (digitalRead(12) == HIGH) ? 1 : 0;
            Response[12] = (digitalRead(A2) == HIGH) ? 1 : 0;
            Response[13] = (digitalRead(A3) == HIGH) ? 1 : 0;
            break;
        case 2: // Mode: Set Device State
            Response[0] = (digitalRead(Pin) == HIGH) ? 1 : 0;
            break;
        default:
            break;
    }

	// Wire back response
  Wire.write(Response, 14);
}
Raspberry Pi 2 (Windows Headed App) Software

Issues

Voltage Level-Shifter Missing
Issue #1
On Oct 8, 2015 at 7:39 PM - 1 comment

The schematic showing connection between RPi2 and Arduino is wrong configures. RPi2 works on 3.3V while UNO works on 5V. Thus voltage level-shifter is needed.

Room Page - Shows wrong device status
Issue #2
On Oct 8, 2015 at 7:42 PM - 0 comments

One of the hackster found that Room Page sometimes shows wrong device status.
See all issues

Credits

Replications

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

VNC Configuration Without Display On Pi Zero W
Intermediate
  • 302
  • 5

Protip

Get started with Pi Zero W without a display. This tutorial helps you to enable SSH, VNC and configure VNC on your smartphone.

Pulse Train HAT for Raspberry Pi Mecanum Bot Example
Intermediate
  • 1,089
  • 17

Full instructions

With this example, we show how to use the PTHAT and wireless Xbox controller to control a Mecanum Bot.

MicroPython to Python via SigFox and Azure IoT Hub
Intermediate
  • 192
  • 4

Protip

This is to show how to get messages from a SiPy to your computer via SigFox and Azure IoT Hub.

Android Things A.I. Candy Dispenser
Intermediate
  • 346
  • 6

Full instructions

A candy dispenser running Android Things that exchanges photos for candies. It uses computer vision to classify the image.

Smart Garden
Intermediate
  • 1,668
  • 16

Smart Garden is a plant environmental monitoring system.

Both Physical & Cloud Cayenne Lights Switch
Intermediate
  • 79
  • 2

The cloud switches are well known, but what happens when the local internet fails and the switch cannot connect to the internet?

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login