Muhammad Afzal
Published © Apache-2.0

Portable Warehouse/Control Shed/Greenhouse Monitoring

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

IntermediateFull instructions provided11 hours1,319
Portable Warehouse/Control Shed/Greenhouse Monitoring

Things used in this project

Hardware components

Arduino MKR GSM 1400
Arduino MKR GSM 1400
×1
Hologram Global IoT SIM Card
Hologram Global IoT SIM Card
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Grove - Gas Sensor(MQ2)
Seeed Grove - Gas Sensor(MQ2)
×1
MQ135 Gas Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Hologram Data Router
Hologram Data Router
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

design_bb_SEzfP3xDd2.jpg

Design bb sezfp3xdd2

Code

code.ino

Arduino
/*
 * 
 * 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);
}

Credits

Muhammad Afzal

Muhammad Afzal

9 projects • 49 followers
I am Software Eng having 6+ Years of experience and now a days i am working in IOT Field using Arduino, Raspberry PI.

Comments

Add projectSign up / Login