Basic Security IoT Basic Security IoT

Instructables Instructables

    Check some projects published on Instructables website

Basic Security with ESP8266

Temperature Monitor with ESP8266

Illuminance Monitor with ESP8266


More details here...

   Motion IoT

The Basics of IoT with a Simple Security System

        This project is a mini security system based on a passive infrared (PIR) motion detector.



Project   Security System
Time to build  1 hour
Cost $30
Arduino Code download
Cloud Device Code download
Mobile App Code download



        We have created this project with the purpose of demonstrating the capabilities of the IC2Cloud platform. This is not a complex project and even a beginner can do it fairly easy. But if you are totally unfamiliar with the platforms we use (Arduino, App Inventor) we recommend you to start by getting some basic knowledge about them on their specific websites.

       Before we go to the project let's do a bit of theory. The general concept in an IoT is that we have distributed devices connected using the internet. The components of an IoT system using IC2Cloud platform are:

  • Hardware Device - This is a hardware component that contains the actuators and the sensor and some logic. In our example there is a switch to set the system ON or OFF (this is the actuator) and an infrared motion detector (this is the sensor). The logic allows to talk to the outside world using the internet.
  • Cloud Device - This is a software component running in the cloud that has the role to execute a certain logic specific to the overall functionality you desire
  • Wiring Cloud - This is a component created to mediate the communication between the hardware devices
  • Mobile Application - This is another software component but running on a mobile device.

        Any of these components are not mandatory but you have to have at least two communicating over internet to "qualify" as IoT.

        Enough theory let's get back to the project. The goal of this project is to provide a usable security system that has next capabilities:

  • Detect motion
  • Send an email if motion is detected
  • Can be turned ON/OFF from a cell phone
  • Provide feedback on the cell phone if the system is ON or OFF and if motion was detected or not

        There is a secondary goal of this project. We want to introduce you to some of the most important platforms we use:

  • Arduino - For hardware components we prefer Arduino because it is easy to use, it can easily interface with other hardware, it has tons of support from community, etc. More details at
  • Wiring Cloud - This is the component we offer. It's role is to mediate the connection of devices over the internet without dealing with special network issues. Basically you can set a value and store it online from a device and access it from another device. The simplest form is:

Example: Set "Temperature" from device  "111-222-333"

Example: Get the "Temperature" provided by the device  "111-222-333"

Observation: the http requests will not work because they need authentication.

  • App Builder - This is the tool we use to create mobile applications that connect with other devices using the Wiring Cloud. More details at
  • Device Builder -This is the tool that allows you to create the cloud device.
  • Device Cloud - This is where the cloud devices you build with the device Builder will run.


        Here you have the list of components required to build the hardware. We assume you have a computer, a router and a network cable. If you purchase the Arduino board from the specified source it comes with the USB cable. Otherwise you might need to provide a USB cable. You can find better options for hardware. Be careful what components you buy. For Ethernet boards there are many versions with different chip sets but only the standard Arduino Shield or equivalent works with the software provided here. The prices are just a guide. This is what we found when we created this project.

Picture Name Price Source

Arduino Uno

 $13 Link
Arduino Ethernet Shield $10 Link
Motion Detector Sensor $3 Link
Single Port Female to Female Jumper Wires $3 Link
Single Port Male to Male Jumper Wires $2 Link


        We recommend you to buy an Arduino board with a smaller USB connector (mini or micro USB) because the Ethernet Shield will not insert properly most of the time if you do not use original Arduino boards.

        Here you have a picture with the components we used:




       This section shows the pinout of the components or provide a link to the specifications of the component.


Component Name Pins
Arduino Uno See:
Arduino Ethernet See:
Motion Detector Sensor
Pin Description
Gnd Ground

3.3 V if motion is detected

0 V if no motion is detected

V+ 5V



        This section shows you how to connect the components together. First you have a pin-out connection and below there are pictures showing how it's done on the real boards.


Motion Detector Sensor Pin ArduinoUno
V+ +5V (Vin)
Out D8


Arduino Ethernet ArduinoUno
Just insert the Ethernet Shield into Arduino Uno

       Here you have pictures with the wiring





        The schematic is




        To run the system you need three software components. One is the software to run the hardware (Arduino Software), the other one is the mobile App (Mobile App) and the last one is to create the rules (Cloud Device).


Arduino Software

       To run the software you need the Arduino development environment. You have to load the software provided here and configure it. There are only one value you need to change in the code.


Field Description

This is a unique id you have to create for your hardware device to identify it from others in the cloud. Use this to generate GUID (Global Unique ID)

String devId      = "b5ebf7a7-e63a-4660-8f83-cf1e5d39cf5b";

This is the authentication string required for basic authentication of the http requests. Create a string from <email_address>:<API_Password> and encode it base64. The sample here "dXNlcjpwYXNzd29yZA==" is the encoding for "user:password"

String auth    = "dXNlcjpwYXNzd29yZA==";


       And here you have the sketch (download)


#include <SPI.h>
#include <Ethernet.h>

// Network settings
byte mac[]     = { 0xDE, 0xED, 0xDD, 0xDD, 0xFE, 0xED };
EthernetClient eth;

char server[]  = "";       // Wiring Cloud host name
int port       = 80;
String devId   = "111-222-333";          // Device ID. CREATE YOUR OWN GUID; Use this
String auth    = "dXNlcjpwYXNzd29yZA=="; // Authentication credentials Create a string from <email_address>:<API_Password> and encode it base64
                                         // The sample here "dXNlcjpwYXNzd29yZA==" is the encoding for "user:password"

int motionStatus;    // cache current motion state
int motionPin = 8;   // pin used to read the PIR sensor

void setup() {
  // start serial monitoring
  // set-up pins
  pinMode(motionPin, INPUT);

  // start network communication
  // intialize status to "NO MOTION"
  motionStatus = 0;

void loop() {
  int newStatus = digitalRead(motionPin);
  // send the data to server only if the motion state changes
  if(newStatus != motionStatus) {
    Serial.println("Status changed...");
    motionStatus = newStatus;  // cache new value for motion state

void sendEvent() {
  if(motionStatus == 1) {
    if (eth.connect(server, port)) {  // connect to server
      eth.println("GET http://" + String(server) + ":" + String(port) + "/Wire/connector/set?id=" + devId + "&MOTION=YES HTTP/1.1");  // send state to server
      eth.println("Authorization: Basic " + auth);
      eth.println("Connection: close");
      Serial.println("Event Sent...");
    else {
      Serial.println("Connection Error");

String readResponse()
  while (eth.connected() && !eth.available()) delay(1);          // wait for data

  String buff = "";                                              // read data in the variable buff
  while (eth.connected() || eth.available()) {
    char c =;
    buff += c;
  return buff;


Mobile App


        The mobile application to control the security system is built with the App Builder. If you just want to import the code file you can download it here. Otherwise you have to create next components.


Component Name Description
Button OnBttn A button used to set the security system ON.
Button OffBttn A button used to set the security system OFF.
Label MotionMsg A text that shows if motion was detected or not.
Label AlarmMsg A text that shows if security system is ON or OFF.
Clock Timer A timer that will send regular requests to detect the state of the system.
Web setAlarmON

The HTTP request that will be sent to set the security system ON. Set URL to:<device_id>&ALARM=ON

don't forget to put the device_id you set in the Arduino Code

Web setAlarmOFF

The HTTP request that will be sent to set the security system OFF. Set URL to:<device_id>&ALARM=OFF

don't forget to put the device_id you set in the Arduino Code

Web getMotion

The HTTP request that will be sent to find if motion was detected or not. Set URL to:<device_id>&MOTION

don't forget to put the device_id you set in the Arduino Code

Web getAlarm

The HTTP request that will be sent to find see if the security system is on or OFF. Set URL to:<device_id>&ALARM

don't forget to put the device_id you set in the Arduino Code

Web resetMotion

The HTTP request that will be sent to reset the motion detection. Set URL to:<device_id>&MOTION=OFF

don't forget to put the device_id you set in the Arduino Code


        In the code you have to set a proper authentication string. Replace the string "Basic dXNlcjpwYXNzd29yZA==" with your authentication string. Create a string from <email_address>:<API_Password> and encode it base64. The sample here "dXNlcjpwYXNzd29yZA==" is the encoding for "user:password". Make sure you append "Basic " at the beginning of it.

        And this is the logic you have to create in with the App Builder. Don't forget to set the authentication string properly. Once that is done you just build the APK and install it on your Android phone.



Cloud Device


        In order to trigger notification when alarm is ON and motion was detected you need a cloud device to execute this rule. Here you have the code you need to create in Device Builder and run in Device Manager.

        And here you have the code (download).

        Don't forget to replace 111-222-333 with your own device_id value and the email addresses with your own email addresses.


Final Product

       Here you have a picture of the "final" product, hardware and screenshots from App.