LowPowerLab Forum

Hardware support => Projects => Topic started by: gianmarko on August 10, 2015, 10:19:48 AM

Title: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gianmarko on August 10, 2015, 10:19:48 AM
last sunday at 3.15 AM burglars broke into my cellar.

my anti intrusion system, based on a network of moteino, triggered an alarm and i was able to scare them away with just my Ipod and a shooting timer/watch

so this is a thank you to the great work done, Felix, from a very happy customer :-)

im in the process of improving the anti intrusion system with more sensors and better software and functiopnality.

gm

Title: Re: Moteino sensors stop real burglars!
Post by: Felix on August 10, 2015, 02:01:05 PM
Wow really?! That's awesome!
I assume there's evidence of them breaking in and not just a false alarm somehow.

Anyway this would be the first record of a Moteino stopping a real break-in :)
Any more details? Was this a MotionMote or just another type of detection using Moteino? Any photos? Anything that can be blogged about or plan to blog about it yourself?
Title: Re: Thank you Felix - Moteino sensors stop real burglars!
Post by: gianmarko on August 11, 2015, 06:31:40 AM
Hi Felix

i have developed the system using some stuff bought from you, mostly moteinos, and stuff sourced on ebay

of course i used some of your code and the knowledge found on your site and elsewhere

system is based mostly on PIR motion sensors, and door switches that use common magnetic contacts connected to a moteino.

my house is quite big but standard moteinos dont have any problem communicating with the "base station"

the base station sits on my bedside. it shows the last 4 alarms on a 4x20 display. display is usually dark, if any alarm is triggered it will light up and show which sensor triggered the alarm.

if "night mode" is selected through a switch, any alarm will sound a beep and wake me up. only certain sensors will trigger a beep.

a push button clears up the display and switches off the display illumination

a GSM module is connected to the base station's moteino and will send a text message on my cellphone if the function is activated . text message sending is activated through a remote control, which is also based on a moteino. i can have multiple remote so my wife also has one, so when i leave the house i can activate the alarm from outside.

the base station is powered by a mightyboost, so the system will work even if there is a power failure or the burglars cut the power.

i have a large old house with lots of storage spaces, workshops, etc, and a cellar, where i keep expensive equiipment and personal belongings. the doors are very old, around 100 years, and locks very rudimentary, also the main door to the house is very old, but i like it and dont want to replace it with a security door, besides, then i would have to secure all windows and i dont want to live in a prison.

i live with my wife and my son. Rural Switzerland used to be very safe but things are changing here too, so burglaries are becoming more common and burglars are not afraid of entering your house at night while you are sleeping;  i dont care too much if burglars enter in the house when we are away, i have a good insurance, but i have a small child and an intrusion will be dealt with with maximum prejudice.

thats why i decided to build this system. i could buy one, but of course is a lot more fun to build my own :-)

the system is designed mainly to alert me if there is an intrusion somewhere when i and my family are  at home.

sunday morning around 3.20 i woke up, was a very hot night and i had all the windows open at the 1st floor where i sleep, my wife is away with my son so i was alone. the buzzer
of the alarm was switched off but the display was on showing an intrusion in the cellar at 3.15, so few minutes before. i sometimes get intrusion detections in the barn, but there are cats and mice there and sometimes i get false alarms. cellar alarm however is uncommon, so i got up, grabbed my bedside gun and a torchlight and went to the balcony, from where i can see the cellar door and back of the house. i could not see well if the door was closed so i went downstairs to check. cellar door was wide open, but i could not see anything strange, so i thought i forgot it open and the cat triggered the alarm.
i went twice around the house but could not see or hear anything, so i went back to bed.

the morning after i needed something that was in the car, so i noticed the car was open with evident signs of someone searching inside. i then went back in the cellar to check better and saw that my ipod and a watch/timer were missing. so yes, people were in and they probably heard me getting up (old house with very creaky floors) and left, or perhaps they saw the thousands of 9mm cases i keep in the cellar for making my ammunitions, and realized that there is someone who shoots a lot in the house and decided to leave in a hurry. perhaps they were hiding in the garden but i didnt see them.

they also entered the garden of my neighbour but they didnt take anything

so i am now 100% sure someone entered in the cellar,  and thanks to the anti intrusion system the burglary was cut short with limited damage for me and no serious damage for them...

if you like i will take a few pictures of the system i built and of the house, so to have an idea of the situation.

in the meanwhile i have rewired the base station, it was built on a breadboard and i had sometimes problems of false contacts, it is all soldered now and more reliable.

the code of the base station is nothing special, and needs improvements, if someone wants to look i will publish it.







 
Title: Re: Thank you Felix - Moteino sensors stop real burglars!
Post by: Felix on August 11, 2015, 07:54:05 AM
That's quite a story, if you want to add anything else, photos, code, this thread is a good place.
Thanks for the details and sharing your experience, I'm glad we can use this technology to do more useful things than blink LEDs!
Title: Re: Thank you Felix - Moteino sensors stop real burglars!
Post by: gianmarko on August 12, 2015, 06:29:56 AM
this technology can surely do a lot more than blinking leds!!!

in fact my motorbike is running on an quite sophisticated homemade fuel injection which is based on atmel processors., i havent designed the EFI but i worked with the designer to adapt it and integrate it on my engine

this technology has huge potential, and i think house automation and security are great fields of application. some of my friends laugh at my ideas  and applications but they are dead wrong.

and all the things i have built and developed, once the code is sorted out , are incredibly reliable even in the worst case scenario.



i will take some photos and post them when i have a little time.

i have also attached a moteino to one of those cheap smoke sensors and it seems to work fine, so i will also have smoke detection, which is nice, as the house is made of wood and my wife very distracted ;-)



keep up the good work Felix :-)
Title: Re: Thank you Felix - Moteino sensors stop real burglars!
Post by: Felix on August 12, 2015, 07:29:03 AM
Looking forward to photos!!
About your smoke detector Moteino, is it a passive or active install? Ie does it feed power from the detector or it runs on battery? And how does it detect the smoke alarm?
Title: Re: Thank you Felix - Moteino sensors stop real burglars!
Post by: gianmarko on August 12, 2015, 02:50:07 PM
Here are some pics.

(http://gianmarco.dyndns.org/public/1/20150812_201854.jpg)

this is the house, the side where the access to the cellar is. this is also the "back" door, there is another entrance door on the other side but it is visible from the road and it has a better protection. this side is not visible from the road and neighbours cant see the entrance

(http://gianmarco.dyndns.org/public/1/20150812_201854.jpg)
(http://gianmarco.dyndns.org/public/1/20150812_201924.jpg)

this is the cellar door. the cellar does not communicate with the house, unlike most houses. burglars often break in from the cellar

(http://gianmarco.dyndns.org/public/1/20150812_201946.jpg)

this is the remote control to activate the gms module. pretty rudimentary but works :-) really no time to take care of details. set to on or off and push the button till the red led activates. led is activated by the ack from the base station

(http://gianmarco.dyndns.org/public/1/20150812_202015.jpg)

this is the door, also visible the most precious thing i own :-)

(http://gianmarco.dyndns.org/public/1/20150812_202131.jpg)

this is the door sensor

(http://gianmarco.dyndns.org/public/1/20150813_100126.jpg)

this is the door lock....

(http://gianmarco.dyndns.org/public/1/20150812_202222.jpg)

this is the base station. again, pretty rudimentary, and lots of hot glue :-)

(http://gianmarco.dyndns.org/public/1/20150812_202453.jpg)

this is one of the motionmotes, this one without case. i still have a few cases but the fit is so tight i gave up :-)

(http://gianmarco.dyndns.org/public/1/20150812_202537.jpg)

as you can see i am a big fan of hot glue :-) perfect to stop flying wires from breaking up at the soldering point. a trick i learned racing car models
also good for assembling stuff quickly

Here is the receiver code (http://gianmarco.dyndns.org/public/1/receiver.ino),nothing to write home about

info on the smoke detector will follow
EDIT: pics resized for embedding and some corrections.


Title: Re: Thank you Felix - Moteino sensors stop real burglars!
Post by: Felix on August 12, 2015, 03:22:07 PM
Nice setup, very DIY, thanks for the details - just don't include the address :D
How does the MightyBoost handle power loss and GPRS transmissions?
Title: Re: Thank you Felix - Moteino sensors stop real burglars!
Post by: gregcope on August 13, 2015, 02:19:02 AM
GM,

Great stuff, this is something I also wanted to setup so interested in any code/hardware info.
Title: Re: Thank you Felix - Moteino sensors stop real burglars!
Post by: gianmarko on August 13, 2015, 04:34:09 AM
hi greg. the hardware is pretty straightforward, i will be happy to answer any question

the sensors are mostly motionmotes, and a variant of it where the PIR sensor is replaced by a cheap magnetic contact. there is room for improvement here because the contact is normally closed and works as pulldown against a pullup resistor. even using 220k pullup, batteries last less that motionmote batteries. would be good to find something better and with lower current consuption. i think that the internal moteino pullup will use more current, but havent checked that due to lack of time to experiment.

i studied the possibility of installing the magnet offset relative to the contact, so that the contact is normally open and it closes when the magnet passes close by when the door opens, but it is impractical as the magnet needs to be located quite far away and the thickness of the door is not enough

perhaps someone smarter than me will come up with a low power solution.

regarding the smoke detectors.

i am using these cheap smoke detectors. i bought them in france for 4 euro each.

 the sensor is based on a IR emitter and a IR received separated by a labirynth, so they normally dont see each other. when smoke enters, it will scatter IR light and activate the sensor.

(http://gianmarco.dyndns.org/public/smoke1.jpg)

i have opened it and found the usual IC that is used in these applications.

the pin 7 will go HIGH when the smoke detector activates, and manufacturers were kind enough to even provide a place where to solder a wire

(http://gianmarco.dyndns.org/public/smoke2.jpg)

(http://gianmarco.dyndns.org/public/smoke3.jpg)

connect that wire to a int pin of the moteino, exactly like in the motionmote, and you have a smoke detector

the detector uses a 9v battery, so you can use that to power the moteino. the whole thing uses very little current.

pretty straightforward.

i am still using the old moteino libraries without battery voltage checks, when i have time (probably when i retire, that is, never :D ) i will implement that. would be also good to retrofit the memory so i can reprogram the inos OTA interface.

so if anyone decides to do something similar, id recommend the above.

base station can be improved, first thing i need is to write some code so that when a text message must be sent, the program checks that the gsm module is on and registered to the network, and eventually turns it on if it isnt.

time is all i need....



Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gianmarko on August 13, 2015, 08:44:29 AM
just to sum it up

i think this is a quite good system. completely stand alone, self powered, very difficult to disable. you will need to jam the moteino tadio transmission, or the gsm network, so not something for the occasional burglar

missing the above, anyone breaking in will trigger an alarm.

and in case someone wants to test my system breaking in while im at home, this is the torchlight i keep beside my bed

(http://gianmarco.dyndns.org/public/1/20150813_124624.jpg)

it makes a lot of light, and when necessary, noise...



Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gregcope on August 15, 2015, 03:35:39 AM
Can I suggest putting all you code / data /design on GitHub?
Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gianmarko on August 16, 2015, 02:39:35 PM
i need to find the time and figure out github, then yes, definitely
Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gianmarko on August 21, 2018, 08:26:00 AM
Hi again

on request from a reader, i will post the code i used in my homemade home burglar alarm system

first a few words about the design choices

i dont have a loud alarm or siren; the base station will beep if an alarm is triggered; the base station sits on my bedside and will wake me up if there is any trigger; the display will show which sensor triggered; sensors are installed in layers, there are door sensors on doors, and motion sensors in rooms. if a motion sensor triggers i will evaulate if it is possible that someone was in the range of that specific sensor without having triggered other sensors, that allows me to evaluate false alarms; in principle, sensors are located so that is not possible to trigger one single alarm, which will be most likely a false alarm. also, motion sensors will usually generate more than one alarm. so far i never saw a false alarm from a door sensor, but pir sensors can generate false alarms, expecially if they see direct sunlight. so sensors should be placed so they dont see direct sunlight, or reflection from a bright wall of direct sunlight.
i have a motion sensor in a garage that, in may, will often trigger false alarms at sunset, when sunlight filters under the door. why may? because after may the trees will grow leaves and shield the sunrise, and before the sun rises at an angle that will not hit the garage door :-)

there is a day mode and a night mode. in day mode the base station will show on a 20x4 display only which alarm has received
in night mode some sensors will also trigger a sound alarm, and alarm is displayed. i exclude from the night mode those sensors that i will trigger for example getting up to go to the toilet...

there is a cancel button which will clear the display from all alarms and turn the display light off
when the first alarm is received, the display light turns on, showing an alarm has been received.
there is an away-from-home mode, that will cause the base station to send a text message over the mobile network when an alarm is triggered.
there is a remote control, based on a similar design as the sensors, that is used to turn on and off the away-from-home mode. the away-from-home mode can also be used to check that the GSM module is working and is connected to the mobile network.
activating or deactivating the away-from-home mode will also trigger a text message signalling that away-from-home mode is switching on or off.
a red led on the remote will show if an ack to the activation/deactivation has been received.

the base station is powered through a mightyboost, which allow it to be completely independent from power or internet connection.
all sensors are battery powered. motion sensors also last several months, depending on how much movement there is in the area. some of them are powered from 4xAA batteries, which ensure some 2 years of functionality.

i have 2 type of sensors, door sensors and motion sensors. lets start with the door sensors.
door sensors are based on common magnetic reed switches that are normally opened. something of the sort
https://www.ebay.com/itm/Recessed-Magnetic-Window-Door-Contacts-Security-Alarm-Switch-Reed-Adhesive-TB/392104317903?hash=item5b4b3d13cf:g:kwAAAOSwiOFZO4NJ

when the door is closed, the magnetic reed switch is closed, and the interrupt enabled digital input pin used in the moteino (D3) is in low state. when the door is opened, D3 will go high;  there is a pullup resistor of 330k ohm which has demonstrated to be enough for the task, and allows a 9v battery to last several months. each door sensor has its own number wich is sent OTA , which allows the base station to tell which sensor is which

all moteino used are equipped with a RFM69H transceiver, which has demonstrated to be more than adequate for the application. i have a big house with thick walls, sensors work everywhere in the house.

this is one of my first projects so the code is definitely crappy. but it works and has worked for several years now.
one thing i have noticed is that the serial data gets corrupted after the processor was in deep sleep, i never got round to figure out why, but is not critical. just need it during prototypeing


Code: [Select]

// Sample RFM69 sender/node sketch for motion sensor
// PIR motion sensor connected to D3 (INT1)
// When RISE happens on D3, the sketch transmits a "MOTION" msg to receiver Moteino and goes back to sleep
// In sleep mode, Moteino + PIR motion sensor use about ~78uA
// Library and code by Felix Rusu - felix@lowpowerlab.com
// Get the RFM69 and SPIFlash library at: https://github.com/LowPowerLab/

#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <LowPower.h> //get library from: https://github.com/rocketscream/Low-Power
                      //writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/

#include <SPI.h> //get it here: https://github.com/lowpowerlab/spiflash

#define NODEID 21 //unique for each node on same network
// 01 - receiver 1x motion sensors 2x door switches
#define NETWORKID 99 //the same on all nodes that talk to each other
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "0123456789012345" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME 30 // max # of ms to wait for an ack
#define LED 9 // Moteinos have LEDs on D9
#define SERIAL_BAUD 115200
#define MOTIONPIN 1 //hardware interrupt 1 (D3)

RFM69 radio;
volatile boolean motionDetected=false;

void setup() {
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);

  radio.encrypt(ENCRYPTKEY);
  attachInterrupt(MOTIONPIN, motionIRQ, RISING);
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
}

void motionIRQ()
{
  motionDetected=true;
}

void loop() {

       

  if (motionDetected)
  {
    Serial.println("Motion!!!");


    if (radio.sendWithRetry(GATEWAYID, "DO01", 4)) // door sensors send a message DO plus a number from 01 to 99
     Serial.println(" ok!");
     else Serial.println(" nothing...");
     
     motionDetected=false;

  }   radio.sleep();
     LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}

Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: Sergegsx on August 21, 2018, 12:27:16 PM
Thanks for such a detail explanation. How do you make sure a node has not run out of battery? Or is not working maybe due to a bad wire connection? What are you using as a gateway to receive the MOTION message ? Thank you
Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gianmarko on August 22, 2018, 09:30:42 AM
Thanks for such a detail explanation. How do you make sure a node has not run out of battery? Or is not working maybe due to a bad wire connection? What are you using as a gateway to receive the MOTION message ? Thank you

i periodically pick up the base station and check all the sensors...or measure voltage. below 7 volts i replace the battery
base station is a moteino with connected a display, a gsm module, a clock module, couple switches

motion sensors code, not much to say about this, pretty straight forward:

Code: [Select]
// Sample RFM69 sender/node sketch for motion sensor
// PIR motion sensor connected to D3 (INT1)
// When RISE happens on D3, the sketch transmits a "MOTION" msg to receiver Moteino and goes back to sleep
// In sleep mode, Moteino + PIR motion sensor use about ~78uA
// Library and code by Felix Rusu - felix@lowpowerlab.com
// Get the RFM69 and SPIFlash library at: https://github.com/LowPowerLab/

#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <LowPower.h> //get library from: https://github.com/rocketscream/Low-Power
                      //writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/

#include <SPI.h> //get it here: https://github.com/lowpowerlab/spiflash

#define NODEID 11 //unique for each node on same network
// 01 - receiver 1x motion sensors 2x door switches
#define NETWORKID 99 //the same on all nodes that talk to each other
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "0123456789012345" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME 30 // max # of ms to wait for an ack
#define LED 9 // Moteinos have LEDs on D9
#define SERIAL_BAUD 115200
#define MOTIONPIN 1 //hardware interrupt 1 (D3)

RFM69 radio;
volatile boolean motionDetected=false;

void setup() {
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);

  radio.encrypt(ENCRYPTKEY);
  attachInterrupt(MOTIONPIN, motionIRQ, RISING);
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
}

void motionIRQ()
{
  motionDetected=true;
}

void loop() {

       

  if (motionDetected)
  {
    Serial.println("Motion!!!");


    if (radio.sendWithRetry(GATEWAYID, "MO01", 6))
     Serial.println(" ok!");
     else Serial.println(" nothing...");
     
     motionDetected=false;

  }   radio.sleep();
     LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}
Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gianmarko on August 22, 2018, 09:39:54 AM
remote control code, activates and deactivates away from home mode and  text messages over gsm

a toggle switch is connected on D4 and D5, to set the remote control to enable or disable the away mode and text mesg over gsm

D6 is the ack led, will light when the base station ack the message

 a push button on the remote box will simply power the moteino

when the enable message is received the base station will show it on display, and send a text message signalling that away from home mode is on
same goes with the disable msg, that can also be used to verify the whole thing is working

again pretty straightforward



Code: [Select]
// Sample RFM69 sender/node sketch for motion sensor
// PIR motion sensor connected to D3 (INT1)
// When RISE happens on D3, the sketch transmits a "MOTION" msg to receiver Moteino and goes back to sleep
// In sleep mode, Moteino + PIR motion sensor use about ~78uA
// Library and code by Felix Rusu - felix@lowpowerlab.com
// Get the RFM69 and SPIFlash library at: https://github.com/LowPowerLab/

#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <LowPower.h> //get library from: https://github.com/rocketscream/Low-Power
                      //writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/

#include <SPI.h> //get it here: https://github.com/lowpowerlab/spiflash

#define NODEID 77 //unique for each node on same network
// 01 - receiver 1x motion sensors 2x door switches
#define NETWORKID 99 //the same on all nodes that talk to each other
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "0123456789012345" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME 80 // max # of ms to wait for an ack
#define LED 9 // Moteinos have LEDs on D9
#define SERIAL_BAUD 115200

RFM69 radio;


void setup() {
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);

  radio.encrypt(ENCRYPTKEY);

  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
  pinMode(4,INPUT_PULLUP);
  pinMode(5,INPUT_PULLUP);
  pinMode(6,OUTPUT);
  digitalWrite(6,LOW);
 
}


void loop() {

delay(1000);
     
     if (digitalRead(4) == HIGH)
     {
      Serial.println("disable");
     if (radio.sendWithRetry(GATEWAYID, "EN00", 4))
     digitalWrite(6,HIGH);
     else Serial.println(" nothing...");
     }
 
      if (digitalRead(5) == HIGH)
     {
     Serial.println("enable");
     if (radio.sendWithRetry(GATEWAYID, "EN01", 4))
     digitalWrite(6,HIGH);
     else Serial.println(" nothing...");
     }
  delay(100000);
}



void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}
Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gianmarko on August 27, 2018, 09:19:29 AM
this is the base station code

something i forgot to mention, when the same alarm is received, only the time will be updated, because alarms usually come in groups

Code: [Select]

// alarm receiver by gianmarco
// rev 0.5 20150122 - cleaned up code, added selective alarms and night mode
// rev 0.6 20150123 - added reset display, selective alarms tested
// rev 0.7 20150809 - changed a few details
// rev 0.8 20150915 - changed beeper type, introduced time limits for night mode
// rev 0.81 20151211 - added alarms

//

//    add this as reminder
//    boolean (8 bit) - simple logical true/false
//    byte (8 bit) - unsigned number from 0-255
//    char (8 bit) - signed number from -128 to 127. The compiler will attempt to interpret this data type as a character in some circumstances, which may yield unexpected results
//    unsigned char (8 bit) - same as ‘byte’; if this is what you’re after, you should use ‘byte’ instead, for reasons of clarity
//    word (16 bit) - unsigned number from 0-65535
//    unsigned int (16 bit)- the same as ‘word’. Use ‘word’ instead for clarity and brevity
//    int (16 bit) - signed number from -32768 to 32767. This is most commonly what you see used for general purpose variables in Arduino example code provided with the IDE
//    unsigned long (32 bit) - unsigned number from 0-4,294,967,295. The most common usage of this is to store the result of the millis() function, which returns the number of milliseconds the current code has been running
//    long (32 bit) - signed number from -2,147,483,648 to 2,147,483,647
//    float (32 bit) - signed number from -3.4028235E38 to 3.4028235E38. Floating point on the Arduino is not native; the compiler has to jump through hoops to make it work. If you can avoid it, you should. We’ll touch on this later.



#include <RFM69.h>
#include <SPI.h>
#include <SPIFlash.h>

#include <Wire.h>

#include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC
#include <Streaming.h>        //http://arduiniana.org/libraries/streaming/
#include <Time.h>             //http://playground.arduino.cc/Code/Time

#include <LiquidCrystal_I2C.h> // i2c lcd display library

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 20 chars and 4 line display


#include <SoftwareSerial.h> // software serial library
#include <String.h>

 
SoftwareSerial mySerial(5,6); // software serial port for GSM module on pin 5 and 6

#define NODEID 1 //unique for each node on same network
#define NETWORKID 99 //the same on all nodes that talk to each other
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "0123456789012345" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME 30 // max # of ms to wait for an ack
#define LED 9 // Moteinos have LEDs on D9
#define SERIAL_BAUD 115200
#define NIGHTMODEPIN 14 // pin to set high for night mode

RFM69 radio;
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network


void setup() {
 
  lcd.init(); // initialize lcd display
 
  Serial.begin(SERIAL_BAUD);
  mySerial.begin(9600); // initialize GSM serial. module was set to 19200, default 9600
  delay(10);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  //--------------------------------------------------------------
#ifdef IS_RFM69HW
  radio.setHighPower(); //uncomment only for RFM69HW!
#endif
  //--------------------------------------------------------------
 
  radio.encrypt(ENCRYPTKEY);
  radio.promiscuous(promiscuousMode);
  char buff[50];
  sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
  pinMode (NIGHTMODEPIN,INPUT);
  pinMode (3, OUTPUT);// enabled sms light
  pinMode (2, OUTPUT);// this pin will hardware switch on gsm module pulsating it on HIGH for 1 sec
  pinMode (15, INPUT);//pin used to clear display and switch off light
  digitalWrite(15, HIGH); //set pin to high by default
  delay(1000);
  digitalWrite(2,HIGH);
  delay(1000);
  digitalWrite(2,LOW);
 
  setSyncProvider(RTC.get); // initialize RTC clock

}

// declare most variables here.

// byte ackCount = 0; not used??
word totalarm = 0; // total alarms


char buff1[20];
char buffw[5] = "    ";
char buffx[5];
char buff2[20] = "                   ";
char line1[20] = "                   ";
char line2[20] = "                   ";
char line3[20] = "                   ";
char line4[20] = "                   ";
char tme[10] = "         ";
char tme1[10]= "         ";
char tme2[10]= "         ";
char tme3[10]= "         ";
char tme4[10]= "         ";

byte smsen = 0; // flag sms enabled starts at 0 : sms not enabled




void loop() {

  if (radio.receiveDone())
  {

    for (byte i = 0; i < radio.DATALEN+1; i++)
      buffx[i] = ((char)radio.DATA[i]);
   
// send ack to the xmitter

    if (radio.ACK_REQUESTED)
    {
      byte theNodeID = radio.SENDERID;
      radio.sendACK();
      Serial.println(" - ACK sent."); 
    }
     

// decode alarms and stuff



if (strncmp(buffx,"DO01",4) == 0) {
  strcpy(buff1,"Door Lab    ");
  if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();
}
     
if (strncmp(buffx,"DO02",4) == 0) {
  strcpy(buff1,"Door Ktcn   ");
  if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();
}
 
 
if (strncmp(buffx,"DO03",4) == 0) {
  strcpy(buff1,"Door Corrid ");
      if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();
}
 
if (strncmp(buffx,"DO04",4) == 0) {
  strcpy(buff1,"Door Upstrs ");
  if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm(); 
}
 
if (strncmp(buffx,"DO05",4) == 0)
  strcpy(buff1,"Door Wintr2 ");

 

if (strncmp(buffx,"MO02",4) == 0)  {
  strcpy(buff1,"Motn Tenne  ");   
   if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();
}
     
if (strncmp(buffx,"MO03",4) == 0) {
  strcpy(buff1,"Motn Stairs ");     
    if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();
}
 
if (strncmp(buffx,"MO04",4) == 0)
  strcpy(buff1,"Motn Living ");
 
 
if (strncmp(buffx,"MO05",4) == 0)  {
  strcpy(buff1,"Motn Upstrs ");   
    if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm(); 
     
}
 
if (strncmp(buffx,"MO06",4) == 0) {
  strcpy(buff1,"Motn Keller ");
  if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm(); 

     
     
if (strncmp(buffx,"MO07",4) == 0){
  strcpy(buff1,"Motn Safe   ");   
    if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm(); 

}
if (strncmp(buffx,"MO08",4) == 0) {
  strcpy(buff1,"Motn Wrkshp ");   
    if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm(); 
}

if (strncmp(buffx,"MO09",4) == 0)  {
  strcpy(buff1,"Motn 09     ");   
    if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();

}

if (strncmp(buffx,"FR01",4) == 0) {
  strcpy(buff1,"Fire Worksh ");   
    if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();
}

if (strncmp(buffx,"FR02",4) == 0) {
  strcpy(buff1,"Fire Upstrs ");   
    if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();
     
}
if (strncmp(buffx,"FR03",4) == 0) {
  strcpy(buff1,"Fire Kitchn ");   
    if (digitalRead(NIGHTMODEPIN) == HIGH)
     soundAlarm();     
}
 
if (strncmp(buffx,"EN01",4) == 0){ // received signal to enable sms sending
    strcpy(buff1,"Enable SMS  ");   
  digitalWrite(3,HIGH);//sms enabled
  smsen = 1;}

if (strncmp(buffx,"EN00",4) == 0){ // received signal to disable sms sending
  strcpy(buff1,"Disable SMS ");   
  digitalWrite(3,LOW);//sms disabled 
  smsen = 2;} // set to 2, trick to send sms that sms sending has been disabled

if (smsen > 0 ) {   //send sms
 
  mySerial.println("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(500);
 
  mySerial.println("AT+CMGS=\"+41000000000\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(500);

  mySerial.println(buff1);//the content of the message
  delay(500);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  mySerial.println();
  Serial.println("sms");
 
  delay(500);
  if (smsen == 2)
  smsen = 0; // now set smsen flag to 0 after having sent the sms signalling the disabling of sms sending
 
}


sprintf(tme,"%02d:%02d:%02d",hour(),minute(),second());


if (strncmp(buffx,buffw,4) != 0) // if alarms comes from a different sensor, scroll and update display, else only update timestamp

{
strcpy(line4,line3);
strcpy(line3,line2);
strcpy(line2,line1);
strcpy(line1,buff1);

strcpy(tme4,tme3);
strcpy(tme3,tme2);
strcpy(tme2,tme1);
strcpy(tme1,tme);

strcpy(buffw,buffx);
}
else
{
strcpy(line1,buff1);
strcpy(tme1,tme);
}
lcd.backlight(); // when first alarm comes turns on display backlight

// update display writing all 4 lines
 lcd.setCursor(0,0);
 lcd.print(line4);
 lcd.setCursor(12,0);
 lcd.print(tme4);
 lcd.setCursor(0,1);
 lcd.print(line3);
  lcd.setCursor(12,1);
 lcd.print(tme3);
 lcd.setCursor(0,2);
 lcd.print(line2);
  lcd.setCursor(12,2);
 lcd.print(tme2);
 lcd.setCursor(0,3);
 lcd.print(line1);
  lcd.setCursor(12,3);
 lcd.print(tme1);


  }
 
// reset display
if (digitalRead(15) == LOW) {
  lcd.noBacklight(); // turn off backlight
  lcd.clear();// clear display
// clear display variables
 
  memset(line1,0,sizeof(line1));
  memset(line2,0,sizeof(line2));
  memset(line3,0,sizeof(line3));
  memset(line4,0,sizeof(line4));
  memset(tme1,0,sizeof(tme1));
  memset(tme2,0,sizeof(tme2));
  memset(tme3,0,sizeof(tme3));
  memset(tme4,0,sizeof(tme4));
  memset(buff1,0,sizeof(buff1));
  memset(buffx,0,sizeof(buffx));
  memset(buffw,0,sizeof(buffw));
 
}
 
 
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}

//void soundAlarm() { // this is the function to activate a sound alarm when in night mode
//    tone(4,2000,100);
//  delay(200);
//    tone(4,2000,100);
//  delay(200);
//    tone(4,2000,100);
//  delay(200);
//    tone(4,2000,100);
//  delay(200);
//    tone(4,2000,100);
//    delay(200);
//    tone(4,2000,100);
//  delay(200);
//    tone(4,2000,100);
//  delay(200);
//    tone(4,2000,100);
//  delay(200);
//    tone(4,2000,100);
//} 

void soundAlarm() { // this is the function to activate a sound alarm when in night mode
if (hour() > 0) {
  if(hour() < 7) {
   for (int i=0; i <= 9; i++){
         digitalWrite(4,HIGH);
         delay(100);
         digitalWrite(4,LOW);
         delay(200);
         }
       }
     }   
}


Title: Re: Thank you Felix - Moteino motion sensors stopped real burglars!
Post by: gianmarko on September 28, 2018, 06:18:28 AM
if anyone is interested, i have designed a 3d printable enclosure for the moteino + pir sensor for the motion sensors, will fit a pir sensor, moteino e one 4xaaa battery holder, which will be good for at least 1 year
pir sensors snap in place and need no screwes,
i have several of the enclosures made by Felix for the motion sensors but i was never able to get one to accomodate all components...really a tight fit,  plus they are quite fragile if they fall and my kids and wife broke several of them

it has holes to access the pir settings