Published © GPL3+

Raspberry Pi Wireless Home Automation With Azure DB Support

Control your home appliances from anywhere in the world with automation options.

AdvancedFull instructions provided14,175
Raspberry Pi Wireless Home Automation With Azure DB Support

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
Microchip PIC18F24K20
BT136 Triac
For high speed switching (Light intensity control)
12v Relay
Darlington Pair IC to On/Off relay safely.
L293D or L293
Motor Driver IC
Temperature sensor
PIR Sensor (HC-SR501)
Passive IR Sensor
Light Intensity Sensor
optocoupler IC to isolate microcontroller from Triac circuit.
Comparator to detect zeros crossing points of AC line (For proper triac triggering)
Push Button
It is not possible to add each and every tiny parts like resistor capacitors LEDs etc. Refer schematics of different boards to know other component details.

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015
Windows 10 IoT Core
Microsoft Windows 10 IoT Core
Microchip MPLAB X (XC8 Compiler)
Eagle CAD
Android Studio
Android Studio
Microsoft Azure
Microsoft Azure


Read more

Custom parts and enclosures

Eagle CAD Slave Device PCB Layout

Eagle CAD Triac Control Board Schematics

Eagle CAD Triac Control Board PCB Layout

nRF24L01+ Module Eagle Library

Eagle CAD Slave Device Schematics


Slave Device Schematics

Triac Control Board Schematics

Motor Driver Schematics

Simple 1 Relay Driver


Windows IoT C# SPI Initialization

Not complete code. This is just to show SPI init steps
using Windows.Devices.Gpio;
using Windows.Devices.Spi;
//SPI initialization
private SpiDevice Spi_port;
GpioPin nRF_CE; //Hope you remember nRF pinout
   private async Task init_spi()
                var settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE); /* Create SPI initialization settings                               */
                settings.ClockFrequency = 1000000;                             /*     */
                settings.Mode = SpiMode.Mode0; //this is very important. nrf modules won't work with other modes

                string spiAqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);       /* Find the selector string for the SPI bus controller          */
                var devicesInfo = await DeviceInformation.FindAllAsync(spiAqs);         /* Find the SPI bus controller device with our selector string  */
                Spi_port = await SpiDevice.FromIdAsync(devicesInfo[0].Id, settings);  /* Create an SpiDevice with our bus controller and SPI settings */


            catch (Exception excep)
                throw new Exception("SPI Initialization Failed", excep);


nRF module C# Class file

//Public Functions available in this class
 public nRF(GpioPin nrf_ce, SpiDevice SPI_DEV) //Constructor
  public void SPI_WRITE(byte[] data)           // Write Byte stream to nRF device
  public byte[] SPI_READ()                   /// Read Byte array from nRF device (Don't call this function unless you know what you are really doing)
        /// You need to write RX_PAYLOAD before bulk reading.
public async void init_nRF()   //Initialize nRF module
       public  void Flush_TX()   /// Clear TX Buffer
       public  void Flush_RX()   /// Clear RX Buffer
       public async void RX_MODE()  /// Switch nRF mode to Receiver (Full duplex communication is not possible, half duplex only ie., one direction at a time.
       //But high switching speed makes it feel like full duplex
        public async void TX_MODE()
         public async void TX_PAYLOAD(byte[] data)///     Transmit payload
///     before transmission, switch to TX_MODE(). Now not necessary to change mode (updated on 10/09/2015)
        public byte[]  RX_PAYLOAD()      ///     Receieve payload 
        //in github file the comment is wrong. ignore the comment (github file). i will update the file later

PIC Side nRF Module Driver File XC8 compiler

I used software SPI on PIC due to PICs hardware SPI limitation and greater flexibility.
void init_spi(void);  //Initialize SPI. Not necessary if you have already done init in main()
void CSNtoggle(void); //Toggle CSN pin (Equivalent to nSS or slave select)
void init_nrf(void);   //Initialize nRF module
void TXpayload(char*);  //Transmit payload. variable payload size possible. But remember, windows iot payload size is 10bytes so you have to use 10 bytes payload here
void RXpayload(char* tmparray); //receive payload

void rx_mode(void); //switch to rx mode
void tx_mode(void); // switch to tx mode
void nrf_FLUSH_TX(void); //flush tx buffer
void nrf_FLUSH_RX(void); //flush rx buffer

PIC Side XC8 Code Snips

                //RemoveMe Packet Structure
                char ch[] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55}; 
                send_data(ch,remove_packet);      //i'm not including this function details here. refer XC8 compiler code to understand. hint. this function will add other header bytes. Don't wanna make this article lengthy

//to send add me packet, all you need is call below function
void send_init(void); 

 //it is very important to use timer for time delay for providing trigger delay, loop delay freezes the uC and not recommended in my Windows IoT system. This device will not work properly if loop delay used instead of timer delay
 //Triac triggering
///////////////Interrupt Service Routines///////////
   void interrupt Trigger_Triac()
       if(ZERO_CROSS)         ///Checks zero crossing points of 230v AC (Triac circuit adjusts the voltage levels readable and compares with a reference variable to generate square pulses) check the circuit to know more.
           ZERO_CROSS = 0;                 //reset zero cross interrupt
           TMR0L = 255-TRIGGER_DELAY;      //set timer value
           TIMER_ON_OFF = 1;               //on timer
       if(TIMER_OVER_FLOW)                // if timer overflows
           R3 = 1;                        //triger triac
           TIMER_ON_OFF = 0;              //off timer 
           TIMER_OVER_FLOW = 0;           //reset overflow interrupt flag 
           __delay_us(15);                //hold time
           R3 = 0;                        //no more high gate pulse require already triggered

Raspberry Pi Windows IoT Home Automation

WindowsIoT Raspberry Pi - Fully Commented Raspberry Pi's GUI app WindowsIoTAutomation - Android Studio Datagram - WIndows App - Universal Windows App (Demo) pic18_nrf.X 0 - PIC microcontroller program (Slave Device)




2 projects • 34 followers