The estimated reading time for this post is 96 seconds

I found really useful rc -switch library to read sensor data.

First of all i wanted to understand what happens when I activate the door sensor or PIR sensor.

I connected the receiver to Arduino as the table below:

Pin Receiver Pin Arduino Vcc 5 V GND GND DATA Pin 2 (digital)

I used the breadboard included in the arduino starter kit.



I included the rc switch library and copied it in Arduino library folder.

My filesystem under libraries\RCswitch\ look like:

keywords.txt

RCSwitch.cpp

RCSwitch.h

example folder

We can open Arduino Ide and copy and paste this code:

#include <RCSwitch.h>; RCSwitch mySwitch = RCSwitch(); void setup() { Serial.begin(9600); mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2 } void loop() { if (mySwitch.available()) { int value = mySwitch.getReceivedValue(); if (value == 0) { Serial.print("Unknown encoding"); } else { Serial.print("Received "); Serial.print( mySwitch.getReceivedValue() ); Serial.print(" / "); Serial.print( mySwitch.getReceivedBitlength() ); Serial.print("bit "); Serial.print("Protocol: "); Serial.println( mySwitch.getReceivedProtocol() ); } mySwitch.resetAvailable(); } }

Uploading sketch to Arduino and opening console monitor on 9600 baud I can read this values:

door sensor 1: Received 1398111 / 24bit Protocol: 1 door sensor 2: Received 1394004 / 24bit Protocol: 1 PIR sensor :Received 1392102 / 24bit Protocol: 1

At this point I can use these values ​​to intercept door opening or movements into house and make Arduino send me an email or a text message.

I opted to receive an email: here comes ethernet shield .

Share this: Facebook

LinkedIn

Google

Reddit

Tumblr

More

Twitter

Pinterest



Pocket

