Wireless motion sensor activated light

In this tutorial we will show you how to build a motion sensor that can wirelessly switch a light in a different location. The light will stay on for 5 minutes and then go off automatically. You can configure the default 5 minute setting as detailed below in the software section. The transmitter is able to send signals from two motion sensors and the receiver has two relay switches that will switch depending on which motion sensor was triggered. 

WARNING : Mains electricity can kill if you are careless or lacking in knowledge of how to connect high voltage.


What you will need:

Unlike many of our projects this project does not require a microprocessor like the Raspberry Pi or Arduino.

If you do not want to program the wireless receiver yourself and wish us to pre-program the device with the software required for this project, please include that note in your purchase. The wireless receiver is a programmable device based on the popular Arduino Uno (Atmega 328). If you want to learn how to program this device see this section of this website.


Construction:

Step 1 - Build the wireless Motion Sensor. This tutorial does talk about linking the sensor to your PrivateEyePi alarm system, but this is not required for this project. You can however use this wireless motion sensor as dual purpose, if you like. It can be used to switch lights as well as send motion detection signals to the PrivateEyePi alarm. 

Step 2 - Build the wireless Dual Relay Switching Kit. This build guide is not our tutorial but it is very comprehensive.

Step 3 - Wireless Receiver

Solder the two 10 pin headers into the row of holes either side the receiver. Then solder the antennae in the position shown in the following diagram:

Step 4 - Connect the RFu-328 to the relay switching kit simply by plugging it into the two headers on the top right with the angled sides of the wireless receiver matching the angled white lines on the board. 

Software

Installing the software is optional as we can pre-load the software for you providing you include a note in the comments of the purchase. The following code is standard Arduino Uno code. This section shows you how to configure a development environment for the receiver (Rfu-328).

Take note the DEVICEID setting. The DeviceID of your wireless transmitter must be the value specified in the code (30 in this case). 

If you want to change the timer interval for the lebgth of time the light stays on then change the setting in the following line which is set in milliseconds:

unsigned long interval = 300000; //300 Seconds or 5 Minutes


Paste the following code into the Arduino IDE and download it to the receiver:

//TimerSwitch 1.00 Motion sensor activated switch with timer
//---------------------------------------------------------------------------------
// Visit projects.privateeyepi.com for full details                                                                                                                
// J. Evans July 2015
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                                       
                                                                                  
// Revision History                                                                  
// V1.00 - 


#include "LLAPSerial.h"

#define DEVICEID "30"

unsigned long timeElapsed1;
unsigned long timeElapsed2;
unsigned long interval = 300000; //300 Seconds or 5 Minutes

int SwitchA;
int SwitchB;

void setup() {
 
  Serial.begin(115200);         // Start the serial port
  
  LLAP.init(DEVICEID);              // Initialise the LLAPSerial library and the device identity

  pinMode(8, OUTPUT);           // pin 8 controls the radio
  digitalWrite(8, HIGH);        // select the radio

  pinMode(4, OUTPUT);           // pin 4 controls the radio sleep
  digitalWrite(4, LOW);        // wake the radio

  delay(500);       // let everything start up
  
  LLAP.sendMessage(F("STARTED"));
  
  pinMode(10, OUTPUT);  
  pinMode(13, OUTPUT);  
  digitalWrite(10, LOW);
  digitalWrite(13, LOW);
  
  SwitchA=false;
  SwitchB=false;
  timeElapsed1 = 0;
  timeElapsed2 = 0;
  
}

void loop() {
String msg;
        // print the string when a newline arrives:
        
if (LLAP.bMsgReceived) {
msg=LLAP.sMessage; 
                LLAP.bMsgReceived = false; // if we do not clear the message flag then message processing will be blocked
                if (msg.compareTo("BUTTONA--") == 0)
                    {
                    LLAP.sendMessage(F("SwitchingA"));
                    digitalWrite(10, HIGH);
                    timeElapsed1 = millis(); // start timer
                    SwitchA = true;
                    }
                if (msg.compareTo("BUTTONB--") == 0)
                    {
                    LLAP.sendMessage(F("SwitchingB"));
                    digitalWrite(13, HIGH);
                    timeElapsed2 = millis(); // start timer
                    SwitchB = true;
                    }
         }


        if (SwitchA == true){
            if (millis()-timeElapsed1 > interval) {
               digitalWrite(10, LOW);
               SwitchA=false;
            }
        }
            
        if (SwitchB == true){
            if (millis()-timeElapsed2 > interval) {
               digitalWrite(13, LOW);
               SwitchB=false;
            }
        }

}





Comments