Published © GPL3+

The simplest home alarm system

To make this alarm system all you need is an Edison, some wire and a magnetic switch per door/window.

BeginnerFull instructions provided1,252
The simplest home alarm system

Things used in this project

Hardware components

Intel Edison with Mini-Breakout
×1
Adafruit Black Wire
×1
Adafruit Red Wire
×1
Normally Opened + Normally Closed Magnetic Switch
You can technically used a N.O. or N.C. I will show how to set up either kind. For using only one sensor per GPIO N.C. is better, but for chaining multiple sensors with one GPIO N.O. is easier to use (reverse for a setup where the two components aren't normally touching. This is why I used one that can act as either.
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2
Phone Backup Battery
Anything works as longs as it's 5v 1A
×1
Male Header 40 Position 1 Row (0.1")
Male Header 40 Position 1 Row (0.1")
×1
Pocket Solder- 60/40 Rosin Core 0.031" diameter
Pocket Solder- 60/40 Rosin Core 0.031" diameter
Exact solder doesn't matter of course
×1
Adafruit Perforated Board
You can also use a breadboard, but I have other pins broken out and doing so would cause shorts
×1
Female Header 8 Position 1 Row (0.1")
Female Header 8 Position 1 Row (0.1")
Use more if you are using multiple separate sensor lines or none at all if you dont care about permanace
×1

Software apps and online services

AWS IoT
Amazon Web Services AWS IoT
Intel XDK IoT Edition
Putty
AWS IAM
Amazon Web Services AWS IAM

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Two Node Sensor Network (Configuration B) Example

This is an example of how to assemble configuration B. The perfboard and headers have been omitted for visual simplicity.
N.B. In Fritzing the pins are seemingly mislabeled. This diagram represents the proper physical arrangement, not the arrangement according to Fritzing's labels.

Single Node (Configuration A) Example

This is an example of how to assemble configuration A. The perfboard and headers have been omitted for visual simplicity.
N.B. In Fritzing the pins are seemingly mislabeled. This diagram represents the proper physical arrangement, not the arrangement according to Fritzing's labels.

Node Network (Configuration B) Example

This is an example of how to assemble configuration B. The perfboard and headers have been omitted for visual simplicity.
N.B. In Fritzing the pins on the Edison are seemingly mislabeled. This diagram represents the proper physical arrangement, not the arrangement according to Fritzing's labels.

Node Network (Configuration B) Example

This is an example of how to assemble configuration B. The perfboard and headers have been omitted for visual simplicity.
N.B. In Fritzing the pins are seemingly mislabeled. This diagram represents the proper physical arrangement, not the arrangement according to Fritzing's labels.

Code

package.json

JSON
You need this! Otherwise, node won't know you need to use the AWS sdk.
{
  "name": "mySecuritySystem",
  "description": "Code to run a simple security system. Build tutorial available on Hackster.io.",
  "version": "1.0.0",
  "main": "main.js",
  "engines": {
    "node": ">=0.10.0"
  },
  "dependencies": {
      "aws-iot-device-sdk" : "^1.0.9"
  }
}

main.js

JavaScript
You'll need to change some of the lines if you use more than one GPIO, notes have been made accordingly
"use strict";
//in mraa the equivalent of Arduino pin one/linux 130 is 26, you'll have to calculate any others try http://iotdk.intel.com/docs/master/mraa/edison.html
//node.js deps
// inherits
// mqtt
// minimist

//npm deps
// aws-iot-device-sdk

//use mraa
var mraa = require('mraa'); //require mraa

//copy the next two lines to add more GPIOs, look at line 2 for help
var myDigitalPin1 = new mraa.Gpio(26); //setup digital read on Digital pin 
myDigitalPin1.dir(mraa.DIR_IN); //set the gpio direction to input

periodicActivity(); //call the periodicActivity function

function periodicActivity() //you'll need to edit this if you use more GPIOs
{
  var myDigitalValue =  myDigitalPin1.read(); //read the digital value of the pin
  if(myDigitalValue == 1) //invert if your system normall provides a 1 (digital HIGH)
  {
      //trigger alarm
      send_state(); //send state to aws only if system is triggered to reduce message usage
  }
  setTimeout(periodicActivity,100); //call the indicated function after .1 second (100 milliseconds)
}
//app deps
var thingShadow = require('aws-iot-device-sdk/thing');  


//Define your device name
var Device_Name = 'mySystem1'; //unique device ID


//define AWS certificate path paramenters
var args = {
	privateKey:'/home/root/aws_certs/privateKey.pem',
	clientCert:'/home/root/aws_certs/cert.pem',
	caCert:'/home/root/aws_certs/aws-iot-rootCA.crt',
	clientId:'bb8',
	region:'us-east-1',
	reconnectPeriod:'10'
};


//create global state variable

var reported_state={ systemState: false};

//launch sample app function 

update_state(args);

function update_state(args) {

//create a things Shadows object

var thingShadows = thingShadow({
  keyPath: args.privateKey,
  certPath: args.clientCert,
  caPath: args.caCert,
  clientId: args.clientId,
  region: args.region,
  reconnectPeriod: args.reconnectPeriod,
});

//When Thing Shadows connects to AWS server:


thingShadows
  .on('connect', function() {
    console.log('registering device: '+ Device_Name);

    //register device
    //register device
    thingShadows.register(Device_Name);
    });


// motitor for events in the stream and print to console:

thingShadows 
  .on('close', function() {
    console.log('close');
  });
thingShadows 
  .on('reconnect', function() {
    console.log('reconnect');
  });
thingShadows 
  .on('offline', function() {
    console.log('offline');
  });
thingShadows
  .on('error', function(error) {
    console.log('error', error);
  });
thingShadows
  .on('message', function(topic, payload) {
    console.log('message', topic, payload.toString());
  });

}



//define function for updating thing state:

  function send_state(){


      //define the payload with sensor values

      reported_state = myDigitalPin1.read(); //you'll need to edist this if you have more GPIOs
      
      //create state update payload JSON:
      device_state={state: { reported: reported_state }};

      //send update payload to aws:
      thingShadows.update(Device_Name, device_state );

  }

Credits

Comments