Home Presence Simulator and Security Control Device

2,295

10

2

This project allow us to simulate presence and to detect movements in our home.

We can configure a network of devices installed in differents rooms of our home all of them controlled by a main device.

This project combines these features on a single device (PICTURE 1):

  1. It is a presence simulator: the device switchs on and off one light bulb (PICTURE 1) and use an IR transmitter (PICTURE 2) to send 38 KHz IR control codes to IR controlled devices (TV, VCR, lamps, ...)
  2. It is a movement detector: the device has got a PIR sensor to detect movements (PICTURE 3)

The whole system is controlled by a master device that send signals to the others slave devices presents in the network to switch on and off the lights and to activate controlled IR devices according to a scheduled presence simulation.

The main features of the master device are the following:

  • It uses a scheduled secuence of commands to control each slave device. For example: the light in the slave station 1 will switch on every day during a random period of time or the slave station 2 will switch on the TV and will change channel after a period of time.
  • It receives the signals from the slave stations when a movement is detected and send us and e-mail
  • It configures a Web Server to control and update the whole system remotely from the Cloud

I hope you like and be useful for somebody.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Building a Slave Device

To build a slave device we will need the following:

  • Electric box
  • ARDUINO NANO or compatible ARDUINO NANO microcontroller
  • Protoboard 480
  • Relay
  • 38 KHz IR transmitter
  • PIR sensor
  • nRF24L01 module + antenna
  • Adapter for nRF24L01 module
  • Power supply 5V, 0.6 A
  • Lamp holder
  • Light bulb
  • Cables
  • Terminal block

The steps to mount it are the following (see the Fritzing drawing for each pin connection):

  1. PICTURE 1: open a hole in the electric box for the lamp holder
  2. PICTURE 2: install the protoboard 480 with the NANO microcontroller, the IR transmitter and the power supply
  3. PICTURE 3: connect the phase conductor of the lamp holder to the NC terminal of the relay and the neutral conductor to the neutral input in the terminal block. After that, connect the common terminal of the relay to the phase conductor of the input in the terminal block
  4. PICTURE 4: connect the IR transmitter and the PIR sensor to the NANO microcontroller. See the step 3 to configure the IR codes for the device you want to control
  5. PICTURE 5: install the nRF24L01 adapter outside the electric box and connect it to the NANO microcontroller. As you can see in this picture the cables goes into the electric box through a hole that also it is used to connect the USB programming cable to the NANO microcontroller

Step 2: Building the Master Device

To build the master device we will need the following:

The steps to mount it are very similar to the previous one because the master device is essentially a slave device with more features (see the Fritzing drawing for each pin connection):

  • PICTURE 1: open a hole in the electric box for the lamp holder
  • PICTURE 2, PICTURE 3: install the ESP8266 module in the protoboard 170 and place it over the MEGA 2560 microcontroller as you can see in the pictures
  • PICTURE 4: paste a piece of wood inside the eletric box. Over the piece of wood install the MEGA 2560 microcontroller with the ESP8266, the clock module DS3231 and the nRF24L01 adapter
  • PICTURE 5: install the power supply and the realy. Connect the phase conductor of the lamp holder to the NC terminal of the relay and the neutral conductor to the neutral input in the terminal block. After that, connect the common terminal of the relay to the phase conductor of the input in the terminal block.

Step 3: Configuring the Master and Slave Devices

To configure the devices you have to do the next steps:

STEP 3.1 (both devices)

Install the IRremote, RF24Network, RF24, DS3231 and Time libraries in your ARDUINO IDE

STEP 3.2 (only for a slave device)

Configure the address in the network. Just only look for the following code in the sketch "presence_slave.ino" and give an address in octal format. Only use addresses greater than 0 because the address 0 is reserved for the master device

const uint16_t this_node = 01;        // Address of our slave device in Octal format

Load the sketch "presence_slave.ino" into the microcontroller.

STEP 3.3 (only for a master device) (INTRODUCING IR CONTROL CODES)

If you are going to use a device controlled by 38KHz IR controls codes to simulate presence, you have to know some of them.

Otherwise, you have to obtain the IR control codes from your device.

To do that, you will need a 38KHz IR receiver, load in one NANO microcontroller the sketch "ir_codes.ino" and connect everything as you can see in the PICTURE 1

Then, point your remote control to the IR receiver, push any button and you will see in the serial monitor something similar to:

(12 bits)Decoded SONY: A90 (HEX) , 101010010000 (BIN)	// POWER button
(12 bits)Decoded SONY: C10 (HEX) , 110000010000 (BIN)	// 4 button
(12 bits)Decoded SONY: 210 (HEX) , 1000010000 (BIN)	// 5 button

In this case the remote control uses the SONY IR protocol and when we push the power button on the remote control we obtain the IR code "0xA90" of lenght 12 bits or when we push the button 4 on the remote control, we obtain the IR code "0xC10".

I recommend at least look for the power and several button numbers IR control code to simulate presence.

After you have obtained the IR codes before, you have to introduce them in the following way:

FIRST WAY

If you have configurated a wifi network you can do it using the web page (See the step: The Web Server)

SECOND WAY

Otherwise, you have to look for the next code in the file "ir_codes.ino" and update the information. In the code below you can see how we can introduce the information obtained above only for the master device (address = 0)

/******************************************/
/******* IR control codes *****************/
/******************************************/
// protocol_id, number_of_bits, 10 IR control codes for the master device (address = 0)
SONY,12,0xA90,0xC10,0x210,0,0,0,0,0,0,0,
// protocol_id, number_of_bits, 10 IR control codes for the slave device (address = 1)
UNKNOWN,0,0,0,0,0,0,0,0,0,0,0,
// protocol_id, number_of_bits, 10 IR control codes for the slave device (address = 2)
UNKNOWN,0,0,0,0,0,0,0,0,0,0,0,
// protocol_id, number_of_bits, 10 IR control codes for the slave device (address = 3)
UNKNOWN,0,0,0,0,0,0,0,0,0,0,0,
// protocol_id, number_of_bits, 10 IR control codes for the slave device (address = 4)
UNKNOWN,0,0,0,0,0,0,0,0,0,0,0
/*********************************************/
/********* End IR control codes **************/
/*********************************************/

The sketch is configurated to works with the following IR protocols:

  • NEC
  • SONY
  • RC5
  • RC6
  • LG
  • JVC
  • WHYNTER
  • SAMSUNG
  • SHARP
  • DISH
  • DENON
  • LEGO_PF

In the file "ir_codes.ino" you can find some IR control codes for SAMSUNG and SONY protocols.

/***************************************************************************/
// SOME IR_PROTOCOLS AND CODES
// (SAMSUNG,number_of_bits,button POWER,button 1,2,3)
// SAMSUNG,32,0xE0E010EF,0xE0E020DF,0xE0E0609F,0xE0E0A05F
// (SONY,number_of_bits,button POWER,button 1,2,3,4,5,6,7,8,9,0)
// SONY,12,0xA90,0x010,0x810,0x410,0xC10,0x210,0xA10,0x610,0xE10,0x110,0x910
/**************************************************************************/

IMPORTANT: the first IR control code introduced must be the IR control code to switch off the device. It will be sent by the master to the slaves when there is not any action planned for that device.

If some body knows or somebody has obtained some IR control codes of some of the protocols listed above, please post a comment in this instructable with the following information: protocol id, protocol length and IR control codes.

STEP 3.4 (only for the master device) (INTRODUCING THE PRESENCE SIMULATION PLANNING)

You can introduce the presence simulation planning in the following way:

FIRST WAY

If you have configurated a wifi network you can do it using the web page (See the step: The Web Server)

SECOND WAY

You have to look for the next code in the file "ir_codes.ino" and update the information.

The presence simulation planning format is the following:

(hour_init_interval1) , (hour_end_interval1) , (hour_init_interval2) , (hour_end_interval2) ,(min_delay_ir) , (max_delay_ir) , (min_delay_light) , (max_delay_light)
/************ PRESENCE SIMULATION PLANNING ************/
7,8,17,3,5,60,10,40,      // master device (address = 0)
0,0,17,23,3,30,5,10,      // slave device  (address = 1)
0,0,0,0,0,0,0,0,          // slave device  (address = 2)
0,0,0,0,0,0,0,0,          // slave device  (address = 3)
0,0,0,0,0,0,0,0           // slave device  (address = 4)
/************ END PRESENCE SIMULATOR ********************/

In the example above the presence simulation planning for the master device is the following:

  • (hour_init_interval1 = 7) The first interval simulation will begin at 7:00 a.m. everyday
  • (hour_end_interval1 = 8) The first interval simulation will end at 8:00 a.m. of the same day
  • (hour_init_interval2 = 17) The second interval simulation will begin at 17:00 p.m. everyday
  • (hour_end_interval2 = 3) The second interval simulation will end at 3:00 a.m. of the next day
  • (min_delay_ir = 5) (max_delay_ir = 60) The delay time in minutes between random sendings of IR control codes is a random number between 5 and 60
  • (min_delay_light = 10) (max_delay_light = 40) The delay time in minutes between the light switch on and off is a random number between 10 and 40

and the presence simulation planning for the slave device with address 2 is the following:

  • (hour_init_interval1

    = 0) There isn´t first interval simulation defined
  • (hour_end_interval1 = 0) There isn´t first interval simulation defined
  • (hour_init_interval2 = 17) The simulation will init at 17:00 p.m. everyday
  • (hour_end_interval2 = 23) The simulation will end at 23:00 p.m. of the same day
  • (min_delay_ir = 3)

    (max_delay_ir

    = 30) The delay time in minutes between random sendings of IR control codes is a random number between 3 and 30
  • (min_delay_light = 5)

    (max_delay_light

    = 10) The delay time in minutes between the light switch on and off is a random number between 5 and 10

STEP 3.5 (only for the master device) (CONFIGURING THE REAL TIME CLOCK)

One of the key of this proyect is the time. We need to set the time of the ARDUINO when the sketch begins to run. To do that we need a real time clock module. One clock module is the DS3231 which support is a backup battery trickle charger, which can be used unless being connected to the microcontroller with three data cables using the I2C protocol.

Previous to use the DS3231 you have to set the time in this module. To do that, you have to run in the master device the sketch "DS3231_set.ino".

STEP 3.6 (only for the master device) (CONFIGURING THE ESP8266 MODULE)

The sketch running in this module try to connect to your local wifi network and configure a web server.

So we need to update the following information in the sketch "presence_web.ino" to access to your local wifi network and to configure the Gmail e-mail address from where the ESP8266 is going to send the movements detected by all the devices in the network and the e-mail address where you want to receive the notifications (ESP8266 Gmail Sender instructable)

const char* ssid = "ssid of your local wifi network";
const char* password = "password of your local wifi network";
const char* to_email = "e-mail where you want receive notifications of movement detections";
WiFiServer server(80); // the port used to listen

and the following information in the sketch "Gsender.h".

const char* EMAILBASE64_LOGIN = "*** your Gmail login encode in BASE64 ***";
const char* EMAILBASE64_PASSWORD = "*** your Gmail password encode in BASE64 ***"; 
const char* FROM = "*** your gmail address ***";

IMPORTANT: this code doesn't work with ESP8266 core for Arduino version 2.5.0. For a temporary solution use core version 2.4.2

STEP 3.7 (only for the master device)

After doing the previous step 3.3, 3.4, 3.5 and 3.6 load the sketch "presence_master.ino" in the NANO microcontroller and the sketch "presence_web.ino" in the ESP8266 module

Step 4: Testing the System

To test if everything works as we want, the sketch "presence_master.ino" can run in test mode.

You can test a specific device in two ways:

FIRST WAY: if you don´t use a wifi network, you have to look for the next code in the file "presence_master.ino", change to "true" the initial value for the "bool_test_activated" variable and update the address of one device to test in the next code line and load the sketch into the ARDUINO microcontroller in the master device.

boolean bool_test_activated = false;		// change to true to init test mode
int device_to_test = 0;				// slave device address to test

Don´t forget to change the value to false when you want exit the test mode and reload the sketch

SECOND WAY: If you use a wifi network, you can use the web page to activate the test mode. See the step "The Web Server"

If the device to test is going to send IR control codes, place the master or slave device in front of the IR controlled device (TV, radio ...).

This mode works in the following way:

  • TESTING THE LIGHT. The light of the specific device must switch on and off every 10 seconds.
  • TESTING THE IR CODES. The sketch will choose randomly a IR code previously introduced and it will send to the IR controlled device every 10 seconds. So you have to test if that device is doing the action corresponding to the IR code received
  • TESTING THE MOVEMENT DETECTOR. If the device detects movement in front of its PIR sensor, it will send the signal to the master device and its light must begin to flash several times

In the video at the end of this instructable you can see the test mode running.

Step 5: The Web Server

To control the system and test if everything works properly, the ESP8266 module is configurated as a Web Server. You don´t need any other aditional software to access remotely to the network, just only type in a web browser the IP of your router. In your router you have previously configurated port forwarding to access the ESP8266 module using a static local IP configurated by you.

This module is connected to the ARDUINO microcontroller using the I2C protocol.

You can see the initial web page in the PICTURE 1:

  • The SYSTEM STATE section show us information about the system:
    • The date and time of the system. It is very important that the date and time are on time
    • The state of the presence simulator (enabled or disabled), the date and time of the last presence action and the address of the device that has executed the action (PICTURE 2)
    • The state of the movement detector (enabled or disabled) and a historic of movement detections by device: counter and date and time of last movement detection (PICTURE 3) In this picture we can see that in the device with address 1 has been detected 1 movement and the last one was at 16:50:34
  • The COMMANDS section allow us to do the following:
    • To activate the presence simulator
    • To activate the movement detector
    • To choose a device to init and stop the test (PICTURE 4)
  • The PRESENCE COMMAND section allow us to do the following:
    • To introduce or update the presence simulation planning for a specific device. In the PICTURE 5 you can see how to update the presence simulation planning for the address device 1. The string format is the following: (addr_device),(hour_init1),(end_init1),(hour_init2),(end_init2),(min_delay_ir),(max_delay_ir),(min_delay_light),(max_delay_light). All the numbers are integer numbers. If you have introduced a valid string you will see the new presence simulation planning before the text "LAST", otherwise you will see the message "LAST: NOT VALID"
  • The IR CODE COMMAND section allow us to do the following:
    • To introduce or update a IR control code for a specific device. In the PICTURE 6 you can see how to update or introduce a new IR control code for the address device 1. The string format is the following: (addr_device),(IR_protocol),(protocol_bits_length),(index_IR_control_code), (IR_control_code) . The (IR_protocol) is a case sensitive string that only accept the next values (SONY,NEC,RC5,RC6,LG,JVC,WHYNTER,SAMSUNG,DISH,DENON,SHARP,LEGO_PF) and the (IR_control_code) is a hexadecimal number. Because the system is configurated to store 10 IR control codes, (index_IR_control_code) is an integer number between 1 and 10. As before, if you have introduced a valid string format you will see the new IR control code before the text "LAST", otherwise you will see the message "LAST: NOT VALID".

To acces to this web page from your local wifi network, just type the IP that your router has assigned to the ESP8266 in a web browser. In all the pictures you can see that the IP assigned by my router is 192.168.43.120.

To access remotely outside of your local wifi network you have to configure in your router the port you are going to use to listen incomings datas and redirect it to the ESP8266 in your local network. After that just type the IP of your router in a web browser.

Step 6: An Example to Clarify All

I have designed a specific example to clarify all

I have built the following devices (PICTURE 2)

  • One IR controlled device using a NANO microcontroller, a RGB led inside a ping-pong ball and one IR receiver module (PICTURE 1). When we push the control button from 1 to 7 of the IR remote, the ping-pong ball changes its color.
  • The master device (address 0)
  • One slave device (address 1)

With all above we are going to test all the features of the project. The presence simulation planning could be:

  1. The ball controlled by the slave device will change its colors from 17:00 p.m. to 23:00 p.m. and in the morning from 7:00 a.m. to 8:00 a.m. every a random interval of minutes between 1 and 1.
  2. The light controlled by the slave device will switch on and off from 17:00 p.m. to 23:00 p.m. and in the morning from 7:00 a.m. to 8:00 a.m. every a random interval of minutes between 1 and 2
  3. The light controlled by the master device will switch on and off from 16:00 p.m. to 1:00 a.m. of the next day every a random interval of minutes between 1 and 2

After executing the sketch "ir_codes.ino" we have obteined that the IR protocol used by the IR remote is "NEC", the lenght of the IR codes is 32 bits and the IR control codes for the buttons between 1 to 7 in hexadecimal format are:

BUTTON 1 = FF30CF

BUTTON 2 = FF18E7

BUTTON 3 = FF7A85

BUTTON 4 = FF10EF

BUTTON 5 = FF38C7

BUTTON 6 = FF5AA5

BUTTON 7 = FF42BD

You can configure the system in two ways:

FIRST WAY: using the web page (see the video at the end of this instructable)

SECOND WAY: updating the file "ir_codes.ino" and uploading it after:

/******************************************/  
/******* IR control codes *****************/
/******************************************/
// protocol_id, number_of_bits, 10 IR control codes for the master device (address = 0)
NEC,32,0xFF30CF,0xFF18E7,0xFF7A85,0xFF10EF,0xFF38C7,0xFF5AA5,0xFF42BD,0,0,0,
// protocol_id, number_of_bits, 10 IR control codes for the slave device (address = 1)
UNKNOWN,0,0,0,0,0,0,0,0,0,0,0,                           
// protocol_id, number_of_bits, 10 IR control codes for the slave device (address = 2)
UNKNOWN,0,0,0,0,0,0,0,0,0,0,0,
// protocol_id, number_of_bits, 10 IR control codes for the slave device (address = 3)
UNKNOWN,0,0,0,0,0,0,0,0,0,0,0,
// protocol_id, number_of_bits, 10 IR control codes for the slave device (address = 4)
UNKNOWN,0,0,0,0,0,0,0,0,0,0,0
/*********************************************/
/********* End IR control codes **************/
/*********************************************/
/************ PRESENCE SIMULATION PLANNING ************/
0,0,16,1,0,0,1,2,        // master device (address = 0) 
7,8,17,23,1,1,1,2,       // slave device  (address = 1) RGB ball
0,0,0,0,0,0,0,0,         // slave device  (address = 2) 
0,0,0,0,0,0,0,0,         // slave device  (address = 3)
0,0,0,0,0,0,0,0          // slave device  (address = 4)
/************ END PRESENCE SIMULATOR ********************/
Arduino Contest 2019

Participated in the
Arduino Contest 2019

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    2 Discussions

    0
    None
    diy_bloke

    2 months ago on Step 6

    Quite a project. Good presence simulation remains the best defense de against burglars

    1 reply
    0
    None
    TecnoProfesordiy_bloke

    Reply 2 months ago

    Thank you for your comment.
    I think just like you and that was my intention when I made it.
    It´s installed and working at home.