Click here to Skip to main content
15,867,961 members
Articles / Internet of Things

IoT based Home Automation And Security with Intel Edison and Node-Red

,
Rate me:
Please Sign up or sign in to vote.
4.91/5 (5 votes)
6 Aug 2016CPOL18 min read 44.7K   334   9   6
A complete Node-Red based suite for home automation, remote IoT based home control and Security System
This project shows how to build a smart home prototype quickly using Intel Edison board, Node-Red (the visual programming language for IoT) and Android phone by integrating Security, Monitoring and Controlling.

Overview

Smart Home is arguably one of the most commonly heard buzzwords in IoT. Connecting home devices with cloud to bring out better capabilities of the devices is one of the areas which has evolved from the desks of DiY hobbyists to serious commercial products. Devices that can respond to gestures, voices, mobile commands, devices that can sense and take decisions, devices that are connected with the user's social accounts are increasingly becoming popular.

Smart Home is commonly referred to a home where the devices are connected to cloud. It can be seen as a system which uses smart phones, PCs to control, monitor, instruct or interact with the appliances at home. It eases human work.

In this project, we are going to show you how to build a smart home prototype quickly using Intel Edison board, Node-Red (the visual programming language for IoT) and Android phone. We are going to integrate three important aspects of the smart home system: Security, Monitoring and Controlling.

The basic idea about the project is to build a home prototype where user can control the lighting of the home using his mobiles, the lighting in turn should respond to ambient light. The system monitors room temperature and generates fire alarm. It is integrated to user's gmail and Twitter account. So, any notification is published to these accounts which can be further channelized to multiple accounts using gateways like IFTTT.

User can monitor the electronic devices at home by sitting anywhere. This system gives security to the user by sending notification. If the user is not at home and an intruder comes home, then sound sensor recognizes there is an intruder and notifies the particular user. Also, if there is a fire in the home in the absence of anyone, then the user gets the notification. These notifications are mitigated through MQTT protocol. This system is developed by using the Intel Edison. The system receives commands from mobile, analyzes data from Light, Temperature and Sound sensors and based on threshold values from the sensors takes appropriate switching decisions and sends the notification to the user. The system is connected to internet through WiFi.

IBM's Watson is becoming increasingly popular due to its services like machine learning, pattern recognition and so on. Node-Red is a visual programming language which is built on Node.js. You can use ready blocks in Node-red to build a prototype in absolutely no time. To add to it, you can always add a pinch of your own Node.js script. Because Node-Red projects can be directly deployed on IBM Bluemix and because you can program from literally any device, this is becoming very popular for quick IoT projects.

Before you start with the article, we would advice you to please check out these two Youtube video tutorials on Intel Edison with Node-Red:

Chapter 1

1. Introduction

IoT is basically a cloud of interconnected devices. In very simple terms, devices like microcontrollers, microprocessors are connected to internet in such a way that each of these devices can communicate with every other device. We call this entire infrastructure as Internet of Things. IOT is set of devices which are connected to the internet through specific protocols like MQTT, web sockets, https in such a way that this device can send information not only to a server or cloud server or can intercommunicate with each other.

For example, your mobile is connected to the internet. A mobile can communicate back with another mobile. A mobile can send some data to cloud and can also receive data from cloud. Would you call a mobile a mobile an IOT device? Technically, no, that’s because by definition IOT is not only an interconnection of devices over a network but the devices that can also communicate with the physical world. So when we elaborate the IOT discussion, IOT is defined as an infrastructure where the devices that can communicate with the physical world can intercommunicate with each other.

The basic meaning of the physical world is any physical device like light, fan, and any sensors. Whereas mobile cannot control a light directly or cannot control a relay directly or cannot sense an agricultural data or water data directly, we do not really categorize mobiles as IOT devices. But because as definition, IOT is interconnection of the physical world connecting devices in a cloud and mobile can get connected with the cloud. Mobiles, just like PCs, form the client side of IOT mechanism which means that mobile can put data into the cloud which is connecting the IOT devices and it can gather data from the cloud which is a cloud of connecting devices. For example, Raspberry pi, Intel Edison, are considered to be most common IOT devices.

These devices more or less run certain version of Linux and they can get connected with the internet, they can exchange messages with web services, they can call web services, they can respond to a web service, they can get connected with common IOT protocols like MQTT by means of which two machines can interact data amongst them. They can take commands from mobile; they can send some data back into the mobile. Now this is what IOT infrastructure is. So if you have to imagine an IOT infrastructure, a number of IOT devices like Intel Edison are connected with relays sensors, and with each other putting data back into the cloud. This data can be processed by tremendous processing ability at the cloud. The result of processing can be further integrated to a machine learning or data visualization framework and can then be made available to the users either in mobiles or in PCs.

Whenever we talk about IoT, IoT gives this kind of infrastructure so the devices now can get connected with the cloud services, can exchange data, can put the data into data gathering services, that data can be analyzed by machine learning services, the data can be visualized by visualizing services. Because it is utilizing a cloud, no matter however number of devices increase, you don’t have to worry about the underneath infrastructure of what’s been going on. As you keep on increasing the devices, the cloud takes care of the entire load and as well as it ensures that performance of all the devices are extremely up to the mark.

Project Description

Smart home system is an automation of home appliances such as light and fan. If there is a fire and there is nobody in the house, then this system notifies the user by sending a message. Also, if there is an intruder in the house, it notifies the user through message. So the user can take appropriate action.

Problem Statement

To build a smart home system where I can control light and fan based on my mobile, to implement a system which notifies me in my absence, if there is an intruder at home also to implement a fire alarm system such that in my absence, it can notify me if there is a fire in my home. In that case, I can build a controller which I can control through mobile. I can have a fire alarm system that can put buzzle but I cannot combine both of them into a single internet architecture with the present system.

Many devices can communicate with the internet. Currently, we can control things through the internet but there is no interconnectivity.

Objective

The main objective is to implement a system which will automate home appliances such as light and fan. Smart home can be controlled and monitored remotely over the cloud. And it provides the security when the user is not at home.

Scope of the Study

Basically, we are doing a physical world system with light, a security system with fire, and intruder. We are going to control them by our mobile interface.

Summary of Methodology Used

  • At first, sensors such as temperature sensors, human presence sensors, and light control sensors are all connected with the Intel Edison. This device is put on the Intel Arduino kit.
  • The device will push all the sensor data on to the cloud.
  • This device is connected with the mobile by using MQTT (Message Queuing telemetry transport) protocol.
  • This device will be connected with a Relay unit that will be driving electrical appliances.
  • Now from the mobile interface, the user can generate command that will control to the MCU device. Based on the Control signal, MCU device will control the relay unit.
  • Automation of appliances such as light / fan by mobile interface. If there is any one at home when the person is away, the MCU will generate notification which will be put on to the cloud. This notification can be mitigated to public channels like Gmail/Twitter.

Tools and Technologies

Tools

  • Node.js
  • Intel Edison
  • Sensors

Node.js

It is a server side web application. In this, basic modules are written in JavaScript. It is mainly used to develop network applications. It has a single thread and looping of events. The request is handled unlimitedly. There is no limit as in other servers, gives service to large number of requests.

Intel Edison

This device is developed for some industrial work, health care center, business process, etc. This is an Intel device which is based on Linux Operating System. It is a small Computer-on-module which is used for Internet of Things. This is an open source system which supports Bluetooth and Wi-Fi. This device is placed on the Intel Arduino kit, which are in turn connected with the several types of sensors. This device is used for development of hardware and software.

Sensors

Sensor is a object which takes input such as temperature, gas, light and finds events and then generates appropriate outputs. It provides numerous outputs but generally it takes electrical signals. Sensors are nowadays used almost everywhere, like in mobile, calculator, robotics, health care centers, cars, etc.

Technologies

  • Wi-Fi
  • MqTT
  • oAuth
  • Social and SMTP

IoT

Internet of Things is a connection of several devices which use internet. Internet of things is used almost everywhere such as in hospitals, in agriculture, in home, in business, etc. In this, the data is stored on cloud. IoT is a growing technology; it allows connection of two or more devices into a single architecture.

In this, microcontroller and microprocessors are connected with other devices so that they can communicate with each other. Through specific protocols, devices can communicate with each other using internet. It also uses protocols such as web socket, http. In IoT devices which can communicate with physical devices can also communicate with each other.

Mqtt

It is an acronym for Message Queuing Telemetry Transport Protocol. This is used to send message to the device in queue in the form of command such as On/Off, Lock/Unlock, etc. It is used for messaging by publishing or by subscribing. With the small code, it can communicate with other devices in remote locations within a network. Connection can be performed when the server establishes a connection. The TCP/IP disconnects the connection only when the user completes his work.

Hardware and Software Requirements

Hardware Requirement

  • Intel Edison
  • Arduino Compatible board for Intel Edison
  • Sensors
  • Android Mobile
  • 9v External power supply or Mobile Power Bank
  • Intel Processor

Software Requirement

  • Operating System: Windows 7 and above
  • Language: Java Script
  • IoT Gateway: ThingSpeak
  • IoT Protocols: MQTT, Web Socket

System Design

The design of smart home system is based on what all devices we want to automate. Smart home includes automation of light, bulb, fan, refrigerator, geyser and security of home by means of fire notify, presence monitor, etc.

Once the user needs are recorded, it is easy to design the system. Based on this, what type of protocols to be used and what sensors are required is calculated. The basic requirement in a smart home system is the combination of certain hardware and software. The interface and the communication protocol between the hardware and software to send notification to the user.

System Perspective

Image 1

Fig Block diagram

We are developing a smart home system where we can control the light and fan based on my mobile also I want to implement a fire alarm system such that in my absence, it can notify me if there is a fire in my home. In that case, I can build a controller which I can control through mobile. I can have a fire alarm system which can put some buzzle but I cannot combine them into single internet architecture with present system.

Therefore, we are proposing an IoT based smart home system. We are going to connect one light and one fan with this device to start it. We should be able to control both the lights and fan through our mobile. This whole thing should have a location awareness that means when we come closer to our home, we could turn on the light and when we go away from home, the light could be turned off.

We are going to put a security system, for example, we are going to put a fire alarm system whenever there is a fire at home, it is going to respond to our mobile. In case our mobile numbers are in silent mode if there is a fire at home, we are not always going to see the alarms. Through IoT system, we are going to put the same data to our Gmail account and Twitter account so that even if we are not aware that our home has a fire, some of our friends or someone from Twitter followers would be aware that there is a fire and could take appropriate action.

Basically, we are doing a security system with fire, a physical world system with light and bulb control. A security system if there is an intruder at home. We are also going to control them with mobile interface. We are also going to control them through our location awareness.

Modules

  • LCD Display

    This module takes the input from the sensor and displays the message on the screen.

  • Fire Notifier

    It takes the input from the temperature sensors and checks if the temperature is higher than normal, it notifies the user by sending the alert message.

  • Presence Monitor

    This module checks whether there is any intruder at home, it checks the mike value by a sound sensor. If the mike value is higher than normal, then it generates the alert message to the user and also it displays on the LCD screen.

  • Light/ Bulb Control

    This module is based on the commands given by the user. The light gets turned on when the user gives the ON command and gets turned off when given an OFF command. The commands are given in the form of message by using the MQTT protocol.

  • Sensors

    Sensor takes input from the environmental changes such as temperature sensors, light sensor, sound sensor, etc. After taking the input, it sends the data to the LCD screen and to the Intel device.

Context Diagram

Level: 0

Image 2

Fig Level zero DFD
Level: 1

Image 3

Figure Level One DFD
Level: 2

Image 4

Figure: Level Two DFD

Use Case Diagrams

Image 5

Figure: Use Case Diagram

Sequence Diagrams

Image 6

Figure Sequence Diagram

Collaboration Diagrams

Image 7

Figure Collaboration Diagram
Activity Diagrams

Image 8

Figure: Activity Diagram

Implementation

Connections

Mount the Grove shield with Intel Edison and power up the board with external adapter.

  • Connect Temperature Sensor with A0
  • Light Sensor with A1
  • Mic/Sound Sensor with A2
  • LCD with I2C port
  • A Relay with D3 ( for controlling Bulb)
  • LED with D7 ( Simulation of Locking and Unlocking of home)
  • Buzzer with D2

Node RED Interface

You can install Node-red in Edison simply by using npm.

npm install node-red

Then just go to node red directory from your Edison shell and type:

node red.js

This starts a node red server. You can access the programming environment by going to edison_ip:port_number. Where port number is displayed on the screen(default 1880) when you start the node-red server.

Image 9

Figure: Node RED Interface

Shows the visual base interface. We can drag and drop the blocks. Then we can code the block. The first block is sensor block, we have taken temperature sensor, light sensor and mike value is read. Sensor block reads all the values and sends it to its output device.

Sensor Process Block

Image 10

Figure: Sensor Process Block

The above figure shows that the sensor process block which is connected with the sensor block, is also connected with the MQTT block. In node.js, one node sends a message to another node through packets. The actual data is stored in the field called payload.

Coding

This block receives several packets, different topics and different payloads. It extracts the topic inside the variable called topic. Temperature is sent with the topic called temperature, light is sent with topic light. Payload is where actual values are coming. It converts the reading to strings.

C#
var topic=msg.topic;
var payload=msg.payload;
var inHome=false;
// All the checking up
//console.log("Input="+msg.topic+"-"+msg.payload)
if(topic=='rupam/smarthome')
{
console.log(msg.topic+":"+msg.payload)
msg.topic="CONTROL";
if(payload=='ON')
{
msg.payload=1;
}
if(payload=='OFF')
{
msg.payload=2;
}

The above code specifies the processing block checks whether the topic is rupam /smarthome or not. It means that the data is coming from MQTT. Then the message is a control topic because actually we are controlling fan and light. If it is on, then msg.payload= 1, if it is off, then msg.payload=2.

C#
if(payload=='LOCK')
{
msg.payload=3;
inHome=false;
}
if(payload=='UNLOCK')
{
msg.payload=4;
inHome=true;
}
if(payload=='STOP')
{
msg.payload=6;
}
}
else
{
if(msg.topic=='Light')
{
// console.log(inHome);
var val=parseInt(msg.payload.trim());
val=(val*100/1023);
console.log("light Intensity="+val+" %");
msg.payload=""+val;
/*
if(val<300)
{
msg.payload='1';
console.log('Bulb on Based on Sensor');
}
else
{
msg.payload='2';
console.log('Bulb Off');
}
*/

The above code depicts that, if the topic= light, then we are calculating the light value in %. The maximum light intensity value is 1023. It is getting message from MQTT for on 1 and for off 2.

C#
if(msg.topic=='Mic')
{
var val=parseInt(msg.payload.trim());
if(val>800)
{
msg.payload='5';
console.log('Person At Home');
}}
if(msg.topic=='Temperature')
{
var a=parseInt(msg.payload.trim());
var B=3975;
C#
var temperature=1/(Math.log(resistance/10000.0)/B+1/298.15)
           -273.15;//convert to temperature via datashee
temperature=Math.floor(temperature * 100) / 100;
//setTimeout(Loop,1000);
console.log("temparature="+temperature);
msg.payload=""+temperature;
}
// msg.topic="Sensors";
// msg.payload=topic+":"+payload;
return msg;

Here, it is parsing the light intensity value if it is light, if it is mike then mike value, if there is person at home who is shouting in my absence if the value is greater than 800, then we are getting a message person at home. Here, we are also calculating temperature value. Here, the temperature is in analog but we want it in degrees. So using the formula, we have calculated the temperature in degree Celsius. Now the message is returned to its output block.

This figure is the hardware control module. It shows the bulb, and buzzer is connected to which pin numbers.

C#
var mraa=require('mraa'); 
var bulbPin=new mraa.Gpio(3); 
var lockPin=new mraa.Gpio(7); 
var buzzPin=new mraa.Gpio(2); 
lockPin.dir(mraa.DIR_OUT); bulbPin.dir(mraa.DIR_OUT); 
buzzPin.dir(mraa.DIR_OUT);
 var lockSensePin=new mraa.Aio(3); 
node.on("input", function(msg)
{

In this, the entire control is provided. It shows that the bulb is connected with which pin numbers; the buzzer is connected to which pin number that is pin number 2. All of these pins have output directions to control them.

JavaScript
if(msg.payload=='1')
{
var lv=parseInt(lockSensePin.read());
bulbPin.write(1);
console.log("Bulb on");
}
if(msg.payload=='2')
{
bulbPin.write(0);
console.log("Bulb Off");
}
if(msg.payload=='4')
{
lockPin.write(1);
console.log("Door Lock");
}
if(msg.payload=='3')
{
lockPin.write(0);
console.log("Door UnLock");
}
if(msg.payload=='5')
{
node.send({topic: "Tweet", 
payload: "Intruder At Home[Sample Project]"+(new Date())})
buzzPin.write(1);
}
if(msg.payload=='6')
{
buzzPin.write(0);
}
if(msg.topic=="Temperature")
{
var val=Number(msg.payload);
}

Whenever the mike value is high, that is, there is somebody at home, the payload is set to 5. Whenever the payload is 5, it should tweet that there is an intruder at home and the buzzer pin will be activated. The Stop command is given to stop the buzzer. Then the buzzer pin will be deactivated.

MQTT Block

Image 11

Figure: MQTT block

Asynchronously, it keeps on checking whether you are releasing any data or not. That’s how we switch on light and switch off. And this is connected with the output block. The MQTT block keeps reading the data. It receives payload and different topics.

LCD BLOCK

Image 12

Figure: LCD Block

Results

Once the user is logged in, he can execute in PuTTy. The above figure shows that the temperature value and the light intensity value is varying. The temperature increases as if there is a fire at home.

Intel Edison with Arduino Board

Image 13

Figure: Intel Edison Arduino Compatible board.

The above figure depicts that Intel Edison is placed on Arduino compatible board. There are different types of sensors which are connected to the board. There is a relay which is also connected with the board. We can see green lights on the board that means the device is on.

Connection Establishment

Image 14

Figure: Connection establishment

After the Execution

Image 15

Figure Switching on Bulb through Mqtt

Image 16

Figure: Gmail Notification

Image 17

Figure: Tweet Generated for Intruder Alert

This figure depicts that light is on and the LED is also on. On LED, we can see Smart Home. The light gets on when we give command from MQTT. From the Android mobile, the ON message is sent so the light is ON.

To execute the code, give with this article:

  • Unzip the folder
  • Upload to Intel Edison root director
  • cd /home/root SmarHome
  • chmod 755 SmartHome.sh
  • ./SmarHome.sh

The shell script will automatically deploy the code in your Intel Edison and run the server.
(Note: If your LCD is not connected, the server will crash due to I2C fatal error.)

Conclusion

Smart Home System has been one of the popular areas of automation and embedded electronics, over past several decades, we have used various different techniques for generating alarm, security and automating the home devices. It includes usage of radio technology such as IR devices, RC devices, etc.

Smart Home System also has several other components like safety and security, many safety devices like fire alarm device and automatic fire extinguisher is been proposed in the past. Most of the existing alarm systems are based on GSM and GPRS based techniques which are slow in latency as well as quite expensive as the messages and voice mail are not free, in this work, we have proposed a novel architecture to offer safety, and automation of the home over IoT architecture.

The proposed system can alert the user in case home catches fire or in case there is an intruder at home, when he is absent. The system also allows the user to operate his home devices purely through his mobile. The entire control and notification system is based on IoT infrastructure, MQTT as well as Gmail and Twitter are free sites and it can operate over the Wi-Fi data. This significantly reduces cost as SMS and GPRS are not used over here.

The result shows that the proposed system meets the objective and can respond to fire, intruder with bare minimum latency and can mitigate the alert to multiple channels simultaneously.

This work can be further improved by incorporating other home automation concepts such as home security through face recognition and other advanced machine learning techniques. The framework can also be improved by incorporating the control of other home devices such as air conditioner, washing machine, etc.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Integrated Ideas
India India
gasshopper.iics is a group of like minded programmers and learners in codeproject. The basic objective is to keep in touch and be notified while a member contributes an article, to check out with technology and share what we know. We are the "students" of codeproject.

This group is managed by Rupam Das, an active author here. Other Notable members include Ranjan who extends his helping hands to invaluable number of authors in their articles and writes some great articles himself.

Rupam Das is mentor of Grasshopper Network,founder and CEO of Integrated Ideas Consultancy Services, a research consultancy firm in India. He has been part of projects in several technologies including Matlab, C#, Android, OpenCV, Drupal, Omnet++, legacy C, vb, gcc, NS-2, Arduino, Raspberry-PI. Off late he has made peace with the fact that he loves C# more than anything else but is still struck in legacy style of coding.
Rupam loves algorithm and prefers Image processing, Artificial Intelligence and Bio-medical Engineering over other technologies.

He is frustrated with his poor writing and "grammer" skills but happy that coding polishes these frustrations.
This is a Organisation

115 members

Written By
Software Developer Integrated Ideas
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
PraiseSounds great. Waiting on Images Pin
Mike Baldini4-Aug-16 7:56
professionalMike Baldini4-Aug-16 7:56 
GeneralRe: Sounds great. Waiting on Images Pin
Moumita Das4-Aug-16 19:26
Moumita Das4-Aug-16 19:26 
QuestionImages Pin
Nelek4-Aug-16 4:07
protectorNelek4-Aug-16 4:07 
AnswerRe: Images Pin
Moumita Das4-Aug-16 4:55
Moumita Das4-Aug-16 4:55 
AnswerRe: Images Pin
Moumita Das4-Aug-16 19:27
Moumita Das4-Aug-16 19:27 
GeneralRe: Images Pin
Nelek4-Aug-16 22:12
protectorNelek4-Aug-16 22:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.