Things used in this project

Hardware components:
Intel Edison
11026 02
Jumper wires (generic)
Sharp microelectronics gp2y0a41sk0f image
Proximity Sensor


Semantics of Counter using PIR sensor
2 PIR sensors, Intel Edison board and Amazon AWS IoT and SNS platform combined in one project to implement a counter.


The code is well documented.
 * No More Allowed!
 * No copyright claims. Some lines of this code are taken from maraca.js which is published in Amazon AWS.
 * Link-    
 * This code demonstrates how to monitor PIR proximity sensor (PPIR sensor) data from an Edison via AWS IoT Service. 
 * Authors: Team Pluto
 * Date: 12/10/2016
//RequPired Libraries
var five = requPire("johnny-five")
var Edison = requPire("edison-io")
var awsIoT = requPire('aws-iot-device-sdk');
var sleep = requPire("sleep")

 * To set your AWS credentials, export them to your envPironment variables.
 * Run the following from the Edison command line:
// AWS IoT Variables
var mqttPort = 8883;
var rootPath = '/home/root/awscerts/';
var awsRootCACert = "root-CA.crt";
var awsClientCert = "pluto.cert.pem";
var awsClientPrivateKey = "pluto.private.key";
var topicName = "plutoTopic";
var awsClientId = "pluto";
var REGION = "us-east-1";

var LED = 3 // D3 on the Grove shield for fPirst LED
var LEDG=6 //D6 on the Grove shield for second LED

var PARTITION_KEY = "xyz"; // DO NOT CHANGE | Your partition key.
var DEVICE = "edison"; // DO NOT CHANGE | Your device type.
var DEVICE_ID = "pluto"; // CHANGE | Your device id / team name.
var THRESHOLD = 50; // OPTIONAL | The amount of change that is requPired for the accelerometer to be "shaking"
var INTERVAL = 1000; // OPTIONAL | 1000 milliseconds, or one second. 

 * Instance AWS variables for use in the application for
 * AWS IoT Certificates for secure connection.
var privateKeyPath = rootPath + awsClientPrivateKey;
var clientCertPath = rootPath + awsClientCert;
var rootCAPath = rootPath + awsRootCACert;

*Initializing Device Communication for AWS IoT
var device = awsIoT.device({
    keyPath: privateKeyPath,
    certPath: clientCertPath,
    caPath: rootCAPath,
    clientId: awsClientId,
    region: REGION
console.log("AWS IoT Device object initialized");

var flag1=0;
var flag2=0;
var count=0;

 * Initializing the Edison board with the Johnny-Five node library.

var board = new five.Board({
	io: new Edison()
 * Once the board is ready to go, run the code!


	//fPirst proximity sensor on A0 pin
	var proximity = new five.Proximity({
		controller: "GP2Y0A21YK",
		pin: "A0"


	//Two Leds are initialized

	var led = new five.Led(LED);
	var led1 = new five.Led(LEDG);

device.on('connect', function (){
      console.log("Connecting to AWS IoT....");

device.on('error', function (error) {
        console.log('error', error);
//Sensor 1 is placed outside the door entrance and sensor 2 is placed inside the door entrance.We have to give a threshold for distance value measured by the PIR sensors. 
//If the distance is less than the threshold, it means that a person is crossing the door.
//When sensor-1 crosses the threshold (from high value to low value), it indicates the arrival of a person. 
//Because it is understood that sensor-2 will trigger (high to low) almost certainly after sensor-1.
// So, we ignore the trigger the sensor for 1 sec, assuming that a person takes 
//On the other hand, when a person exits, the sensor-2 will trigger (high to low) first. 
// And thus we detect that a person exits the room.
		if (>15){ 
			// The distance threshold is 15 inch
			flag1 = 0;
		if (<=15){
			if (flag1==0){
				// This means that a person entered the room.
				count = count+1;
				console.log("proximity enter: ");
				console.log(" in :",;
				console.log("count: ",count);
				//A delay of 1 sec is the time, a person takes to enter the room.
			flag1 = 1;

	//The second sensor is used to check when a person exits.
	var proximity1 = new five.Proximity({
		controller: "GP2Y0A21YK",
		pin: "A1"
		//The distance threshold is 15 inch
		if (>15){
			flag2 = 0;
		if (<=15){
			if (flag2==0){
				if (count>0){
					// This indicates that a person exits the room.
					count = count-1;
				console.log("proximity exit: ");
				console.log(" in :",;				
				console.log("count: ",count);
				// It takes 1 sec for a person to exit the room.
			flag2 = 1;
		//The time of 50 ms is the time interval between two successive sensing cycle. 
		//It means the sensors are off for 50ms. This is done to reduce the sensitivity of the sensor.
	// sendData packages the JSON string and sends it to SNS with the Node.JS AWS SDK.
    function sendData() {
        var json = {
            default: "Enter default message here",
            count: count


        device.publish(topicName, JSON.stringify(json));
        console.log("JSON Msg Published to AWS IoT Topic. Payload:" + JSON.stringify(json));



Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Similar projects you might like

Developing a Low-Cost Microcentrifuge Using E-Waste
  • 56
  • 3

Work in progress

Quality microcentrifuges are generally too expensive for most people to afford. This project aims to provide a low-cost alternative.

Flightduino 101
  • 340
  • 7

Full instructions

A drone project that uses the Neural Pattern Recognition Module and other aspects of the Curie Module to advantage for creating a cool drone

Arduino 101 BLE App
  • 1,819
  • 23

Work in progress

I want to show you how to make an application and connect it with the Arduino 101 platform for Internet of things applications.

SMART CUBE: A New Way to Control Your Home
  • 385
  • 5

Full instructions

Discover a new way to interact with your smart home thanks to Arduino 101: tilt and shake the cube to control your devices via Bluetooth!

Connected Koozie with Intel tinyTILE and Octoblu
  • 342
  • 6

Full instructions

The Connected Koozie will send a message to Meshblu whenever a sip is detected from the tinyTILE's built in accelerometer.

Bluetooth smart home
  • 325
  • 5

Full instructions

A concept showing smart home control and automation with Arduino 101, accompanied by a custom Android application.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project