Project tutorial

Portable Warehouse/Control Shed/Greenhouse Monitoring © Apache-2.0

A prototype for Industrial IoT system to enhance warehouse/greenhouse monitoring using MKR GSM1400 and Hologram.

  • 997 views
  • 0 comments
  • 7 respects

Components and supplies

Apps and online services

About this project

Background

Humidity and temperature monitoring is a very important factor in salt/dairy warehouses, greenhouses, as well as in homes. Instead of taking manual readings from digital meters, I plan to make a device which will automatically stream real-time statistics of warehouses (temperature/humidity) to the Hologram Cloud and ThingSpeak Cloud using Arduino MKR GSM 1400. By this way, we can get real-time result anywhere any time and take decisions on time to save products from damage.

I am also adding one more feature in this system that is gas/smoke monitoring, light level, and environment monitoring which is good with respect to safety and health environment. In case of any fire or smoke, you can get the alert on your system, or if there is any pollution impact we can take measures to make our environment clean.

Theme

Arduino MKR GSM 1400 will receive the data from all sensors and modules, and send it to hologram Cloud via Hologram SIM card. After that, we will send the data from hologram to ThingSpeak channel for graphic visualization and for further process.

Hardware Setup

Please collect thee above mentioned hardware. Below is the picture of all components that we required in this project.

Follow the project Fritizing diagram and connect the modules with MKR GSM 1400 as the diagram below demonstrates.

DHT11 Module-> 1

LDR ->A1

MQ2 Module->A2

MQ135 Module->A3

After connections, the breadboard will look like this. It looks like difficult no problem, which is why I uploaded the Fritizing design diagram. :-)

Arduino IDE Setup for Arduino MKR GSM 1400

Before you upload the code to MKR GSM 1400, we need to make some setup to prepare our Arduino IDE for MKR GSM 1400. Firstly, we need to install MKR GSM 1400 board.

Navigate in Arduino IDE to Tools->Boards->Boards Manager Type MKR in Search box and you will get "Arduino SAMD Boards(32-bits ARM Cortex-M0+) By Arduino" Click on Install button.

After board Installation, we need MKR GSM Library for our project. Navigate to Sketch->Include Library->Manage Libraries and type MKRGSM in Search.

Arduino IDE is ready to upload code to board. But before this, we need to take some information from the Hologram Dashboard and also from ThingSpeak API Tab, so follow Hologram and ThingSpeak setup for further.

Hologram Setup

Code require device ID for SIM Authentication at Hologram Cloud. Log in to Hologram Dashboard https://dashboard.hologram.io/. If you are new to Hologram please follow this link to activate your SIM card https://hologram.io/docs/guide/connect/connect-device/.

After login, you will see the list of devices click on on device that is for MKR GSM 1400.

After that, click on Device Key, which is marked by the black box in picture. If you have not generated this, then generate it and copy the device key and paste in code.

Below is the code section snippet where you need to place your Device Key in HOLOGRAM_DEVICE_KEY and you can assign any name in HOLOGRAM_TOPIC I am going to use MKR GSM 1400 as topic.

Upload the code to MKR GSM 1400 after all configuration and the status from serial monitor which will show you either your MKR GSM board is connected with Hologram or not. If connected, you can see the values in your Jologram dashboard.

Click on "All Activity" to view your sensors values.

Below is the image that is demonstrating your sensor values and topic.

ThingSpeak Setup

Hologram will show us raw data like in JSON format that is very difficult to process so I plan to send all my MKR data from Hologram to ThingSpeak. For this, we need to set up Hologram routes that will be discussed in the next session, which will send our data to ThingSpeak cloud.

Log in to https://thingspeak.com/. After login, click on New Channel button.

Fill the channel name and fields, and then click on Save button.

After that, you will see your channel. But currently it's not showing the data because we still did not set up the bridge between Hologram and ThingSpeak, which will be discussed in next step.

Now after setting up the channel, we need to take Write API Key of ThingSpeak. Click on API Keys.

Place the Write API Key in the Arduino code and upload the sketch to board.

Set Up Hologram Route

To transfer the data from Hologram to ThingSpeak cloud, we need to set up a route. Click on Route link.

Click on Add Your First Route link.

Write route nickname and select topic. In out section, choose advance web hooks.

Enter: https://api.thingspeak.com/update?<<decdata>> in destination URL, and after that save the route.

Now Hologram is sending the data to our ThingSpeak channel.

Packing Into Box

After completing everything, it's time to pack our breadboard components into the box. So, I am going to solder the female header on vero board and put all the sensors in a box. Additionally, I solder two more groups of female headers 1 for 5V and other for ground as I am going to connect four sensors so every sensor need 5V and Ground.

Thanks for reading my project. if you have any query please feel free to comment on this project. i will try my best to answer your query.

Code

code.inoArduino
/*
 * 
 * Factory/Warehouse/Green House Tempeature, Humidity & Environment Montiring
 * Arduino MKR GSM 1400 + Hologram Cloud + ThingSpeak
 * LDR+DHT11 Module+ MQ2 Module + MQ135 Module
 *
*/

// libraries
#include <MKRGSM.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

// Define Sensors Pins
#define DHTPIN            1         
#define LDR               A1
#define MQ2               A2
#define MQ135             A3

//Thing Speak Write Key
String ThingSpeakWriteKey="-----ThingSpeakWriteKey----------";

#define DHTTYPE           DHT11    

DHT_Unified dht(DHTPIN, DHTTYPE);

uint32_t delayMS;
String Values;
String MQ2_Val,MQ135_Val,LDR_Val;

const char PINNUMBER[] = " ";
// APN data
const char GPRS_APN[] = "hologram";
const char GPRS_LOGIN[] = " ";
const char GPRS_PASSWORD[] = " ";

//Hologram Config
String HOLOGRAM_DEVICE_KEY = "----Hologram Deveice Key--------";
String HOLOGRAM_TOPIC = "MKR1400";

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// Hologram's Embedded API (https://hologram.io/docs/reference/cloud/embedded/) URL and port
char server[] = "cloudsocket.hologram.io";
int port = 9999;

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  dht.begin();
  
  Serial.println("Starting Arduino web client.");
  // connection state
  boolean connected = false;

  // After starting the modem with GSM.begin()
  // attach to the GPRS network with the APN, login and password
  while (!connected) {
     Serial.println("Begin GSM Access");
    if ((gsmAccess.begin() == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
      Serial.println("GSM Access Success");
    } 
    else {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  delay(5000);
}

void loop() {
    Values="api_key="+ThingSpeakWriteKey+"&";
    //Values="";
    delay(delayMS);
    // Get temperature event and print its value.
    sensors_event_t event;  
    dht.temperature().getEvent(&event);
    if (isnan(event.temperature)) {
      Serial.println("Error reading temperature!");
      Values+="field2=0&";
    }
    else {
      Serial.print("Temperature: ");
      Serial.print(event.temperature);
      Serial.println(" *C");
      Values+="field2="+String(event.temperature)+"&";
    }
  
    
    // Get humidity event and print its value.
    dht.humidity().getEvent(&event);
    if (isnan(event.relative_humidity)) {
      Serial.println("Error reading humidity!");
      Values+="field3=0&";
    }
    else {
      Serial.print("Humidity: ");
      Serial.print(event.relative_humidity);
      Serial.println("%");
      Values+="field3="+String(event.relative_humidity)+"&";
    }
  
    //Get Light Level
    Serial.print("Light Level: ");
    LDR_Val=String(analogRead(LDR));
    Serial.println(LDR_Val);
    Values+="field1="+LDR_Val+"&";
    
    //Get Smoke Level
    MQ2_Val=String(analogRead(MQ2));
    Serial.print("MQ2-Gas Level: ");
    Serial.println(MQ2_Val);
    Values+="field4="+MQ2_Val+"&";
    
    //Get Environment Level
    MQ135_Val=String(analogRead(MQ135));
    Serial.print("MQ135-Env Level: ");
    Serial.println(MQ135_Val);
    Values+="field5="+MQ135_Val;

    
    //Send the Data to Hologram Network
    if (client.connect(server, port)) {
      Serial.println("connected");
      // Send a Message request:
      client.println("{\"k\":\"" + HOLOGRAM_DEVICE_KEY +"\",\"d\":\""+ Values+ "\",\"t\":\""+HOLOGRAM_TOPIC+"\"}");
    } else {
      // if you didn't get a connection to the server:
      Serial.println("connection failed");
    }
    client.stop();
    delay(10000);
}

Schematics

design_bb_SEzfP3xDd2.jpg
Design bb sezfp3xdd2

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 454,931 views
  • 42 comments
  • 239 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,487 views
  • 95 comments
  • 671 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 229,313 views
  • 38 comments
  • 236 respects

OpenCat

Project in progress by Team Petoi

  • 195,894 views
  • 154 comments
  • 1,361 respects
Add projectSign up / Login