My first tryst with IoT - Part I

With all the hype doing the rounds on IoT, I was certainly raring to get a hands-on experience with IoT. I must admit the experience was a great eye opener. Quite convinced that IoT is poised to be the greatest industry wide paradigm shifts radically changing our life & work.

This blog provides a quick look at using a 'Induino/Arduino' board along with hardware sensors and capturing the sensor data. The next blog shall extend this further with an additional GSM board allowing the data to be pushed on to a cloud hosted service.

1) The sensors on the sensor board include:


T – Temperature Sensor
L – Light Dependent Resistor (LDR)
R – Magnetically operated Reed Switch
H – Humidity Sensor
P – Power Switch based on Optocoupler
X – PIR(Passive Infrared Sensor)

2) Connecting  the Induino board to the sensor board


A2 – Analog input pin for the output pin (T) of Temperature sensor
A4 – Analog input pin for the output pin (H) of Humidity sensor
A5 – Analog input pin for the output pin (L) of Light sensor (LDR)
5 – Digital input pin for the output pin (R) of – Reed switch
6 – Digital input pin for the output pin (P) of – Power switch
7 – Digital input pin for the output pin (X) of – PIR sensor


3) Application code

#include <dht11.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(8,9,10,11,12,13);
int R=5;        // REED SWITCH
int P=6;
int X=7;        // POWER
int T= A2;         // TEMPERATURE - A2 has already been defined as Analog Pin 2 in arduino lib
int H=A4;        //HUMIDITY
int L=A5;        //LIGHT
float CELSIUS, HUM, LIGHT;
dht11 DHT11;


void setup()
    {

      lcd.begin(16,2);
      pinMode(P, INPUT);
      pinMode(R, INPUT);
      pinMode(X, INPUT);

    }

    void TEMPERATURE()
    {
      lcd.clear();
      int value_temp=analogRead(T);
      delay(10);
     value_temp=analogRead(T);
      delay(10);
      float millivolts_temp=(value_temp/1023.0)*5000;
      CELSIUS=millivolts_temp/10;
      lcd.setCursor(0,0);
      lcd.print("T:");
      lcd.print(CELSIUS);
    }


    void HUMIDITY()
    {
      int chk = DHT11.read(H);
      float HUM=DHT11.humidity;
      lcd.setCursor(8,0);
      lcd.print("H:");
      lcd.print(HUM);
    }


    void LIG()
    {
      int value_lig=analogRead(L);
      delay(10);
       value_lig =analogRead(L);
      delay(10);
      float millivolts_lig =(value_lig /1023.0)*5000;
      LIGHT=millivolts_lig /10;
      lcd.setCursor(0,1);
      lcd.print("L:");
      lcd.print(LIGHT);
      delay(2000);
      lcd.clear();
    }


void POWER()
    {
      if(digitalRead(P)==LOW)
       {
        lcd.setCursor(0,0);
        lcd.print("P:OFF");
      }
      else{
        lcd.setCursor(0,0);
        lcd.print("P:ON ");
      }
    } 


    void PIR()
    {
      if(digitalRead(X)==LOW)
       {
        lcd.setCursor(0,1);
        lcd.print("X:PIR(NO )");
      }
      else{
        lcd.setCursor(0,1);
        lcd.print("X:PIR(YES)");
      }
    } 


void REED()
    {
      if(digitalRead(R)==LOW)
           {
        lcd.setCursor(6,0);
        lcd.print("R:OPEN");
      }
      else
      {
        lcd.setCursor(6,0);
        lcd.print("R:CLOSE");
      }
       delay(2000);
    }


    void loop()
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Axetla Systems");
      delay(1000);
      lcd.clear();
      while(1)
      {
        TEMPERATURE();
        HUMIDITY();
        LIG();
        POWER();
        PIR();
        REED();
        }
    }


4) Saving and uploading the application code through Arduino