Muhammad Afzal
Published © GPL3+

WareHouse/Control Shed/GreenHouse Monitoring

A Prototype for Industrial IOT to enhance Warehouses/Green house Monitoring using Sparkfun & Cayenne IOT Cloud.

IntermediateFull instructions provided20 hours3,694

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
DHT22 Temperature & Humidity Sensor
×2
MQ-2 Smoke Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
5V Mobile Charger Compitable with Boards
×2

Software apps and online services

Arduino IDE
Arduino IDE
Cayenne
myDevices Cayenne

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer Generic

Story

Read more

Custom parts and enclosures

Outdoor Device Cover Front-Side

Outdoor Device Cover Back-Side

Indoor Device Cover Front-Side

Indoor Device Cover Back-Side

Schematics

Out Door Nodemcu ESP8266 Breadboard design

Indoor SparkFun ESP8266 Breadboard Design

Code

Outdoor.ino

Arduino
/*
 *  Indoor Warehouse Montring using Sparkfun ESP8266 Thing Dev Board
 *  Create By: Muhammad Afzal
 *  Made with Love From Pakistan
 *  Freely avilable to modify/use in your projects.
 *  http://hackster.io/mafzal/
 */
 
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

// WiFi network info.
char ssid[] = "--Change it--";
char wifiPassword[] = "--Change it--";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "--Change it--";
char password[] = "--Change it--";
char clientID[] = "--Change it--";


#define DHTPIN            4         // Pin which is connected to the DHT sensor.
#define DHTTYPE           DHT22     // DHT 22 (AM2302)

DHT_Unified dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
	Cayenne.loop();
  delay(10000);

  sensors_event_t event;  
  //Get Temperature
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println("Error reading temperature!");
    
  }
  else {
    Serial.print("Temperature: ");
    Serial.print(event.temperature);
    Serial.println("*C");
    Cayenne.celsiusWrite(0, event.temperature);
  }
  
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    Serial.println("Error reading humidity!");
  }
  else {
    Serial.print("Humidity: ");
    Serial.print(event.relative_humidity);
    Serial.println("%");
    Cayenne.virtualWrite(1,event.relative_humidity);
  }

}

//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
}

InDoor.ino

Arduino
/*
 *  Indoor Warehouse Montring using Sparkfun ESP8266 Thing Dev Board
 *  Create By: Muhammad Afzal
 *  Made with Love From Pakistan
 *  Freely avilable to modify/use in your projects.
 *  http://hackster.io/mafzal/
 */
 
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

// WiFi network info.
char ssid[] = "--Change This--";
char wifiPassword[] = "--Change This--";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "--Change This--";
char password[] = "--Change This--";
char clientID[] = "--Change This--";



#define GasModulePin      A0           //MQ-2 Gas Sensor Pin 
#define DHTPIN            2         // Pin which is connected to the DHT sensor.
#define DHTTYPE           DHT22     // DHT 22 (AM2302)
int GasLevel=0;

DHT_Unified dht(DHTPIN, DHTTYPE);

void setup() {
	Serial.begin(9600);
 dht.begin();
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
	Cayenne.loop();
  delay(600000);

  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println("Error reading temperature!");
  }
  else {
    Serial.print("Temperature: ");
    Serial.print(event.temperature);
    Serial.println(" *C");
    Cayenne.celsiusWrite(0, event.temperature);
  }
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    Serial.println("Error reading humidity!");
  }
  else {
    Serial.print("Humidity: ");
    Serial.print(event.relative_humidity);
    Serial.println("%");
    Cayenne.virtualWrite(1,event.relative_humidity);
  }

  //Read MQ-2 Gas Sensor Level
  GasLevel=analogRead(GasModulePin);
  if(GasLevel>0){
    Serial.println("Gas Level=");
    Serial.print(GasLevel);
    Cayenne.virtualWrite(2,GasLevel);
  }else{
    Serial.println("Gas Level=");
    Serial.print(GasLevel);
    Serial.println("Unable to Take Gas Level Readings");
  }
  
}

//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
	//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

Credits

Muhammad Afzal

Muhammad Afzal

25 projects • 117 followers
I am Software Eng having 13+ Years of experience. Hackster.io & Cayenne Mydevices Ambassador in Pakistan.

Comments