Designing the device agent of the WSO2 IoT plugin Building Visualizer

Internet of Things better known as IoT, is an automated system where everything is interrelated to each other. Not only computers but also other electronic devices such as home appliances, industrial machines and even people are connected and interrelated according to the concept of IoT.

In this blog we are going to make a small IoT device to monitor the temperature, humidity, light level and motion of a place.

To make this device agent you need the following components, which you can buy from an electronic shop or order online.

  • ESP 8266 12E WiFi module
  • DHT11 temperature, humidity sensor
  • PIR SR501 motion sensor
  • LM393

Additionally you may need:

  • Jumper wires
  • A breadboard

If you are making a PCB you may also want to have the following.

  • Copper board
  • An iron
  • Ferric Chloride or any other etching solution
  • A hand driller or an electric driller
  • Soldering iron (Bouth)
  • Soldering wire
  • Headers (If you are not directly soldering the sensors to the copper board)

After you have taken the components, connect them to the breadboard using jumper wires according to the breadboard design and schematic diagram given below.


Breadboard circuit for the device agent
Schematic design for the circuit

Then download Arduino IDE, select the board as NodeMCU 1.0 (ESP 12E) from Tools -> Board and select the port (Tools -> Port) you have connected the ESP to the computer. Download the DHT sensor library and include the library by selecting Sketch -> Include library.

Compile and upload the following code to the board.

#include "DHT.h"
#define PIR_OUT D5
#define ANALOG_SENSOR_PIN A0
#define DHTPIN D3 // what digital pin we're connected to
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int isMoving = 0;
char device_id[100] ;
void setup() {
Serial.begin(115200);
Serial.println("DHT11 test!");
dht.begin();
pinMode(PIR_OUT, INPUT);
snprintf (device_id, 100, "%i", ESP.getChipId());

}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
int light = analogRead(ANALOG_SENSOR_PIN);
int isMovingTemp = digitalRead(PIR_OUT);
if (isMovingTemp == 1) {
isMoving = 1;
}
Serial.print("Device id : ");
Serial.print(device_id);
Serial.print("\t");
Serial.print("Motion : ");
Serial.print(isMoving);
Serial.print("\t");
Serial.print("Light: ");
Serial.print(light);
Serial.print("\t");
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");;
delay(2000);
isMoving = 0;
}

Open the serial monitor of the Arduino IDE and select the baud rate as 115200 and you can observe the sensor readings as follows.

Sensor readings

Although you can observe the readings of the sensors in this way, you cannot know where the sensors are situated nor store them nor visualize them in a meaningful way. To achieve that task, after making and testing this device, you can enroll it to the building visualizer plugin in WSO2 IoT server and monitor the data in a user-friendly way.

Note: Upload this code instead of the earlier code to the board, to get sensor data and to send them to the WSO2 IoT server.

My blog on WSO2 IoTS Plugin: Building Visualizer explains how to do the enrollment and monitoring.


If you want to make a PCB instead of using the breadboard circuit, you can make a PCB circuit and route like the below figure. For this, you can use a professional software like OrCAD or a user friendly software like Fritzing.

PCB design for the circuit

To print the PCB you can get the mirror image of the circuit and get screen printing done from a shop or you can simply make it at your home.

To print the PCB at home, first you have to print the PCB circuit (not the mirror image) on a photo paper or a sticker paper. Then keep the paper on a copper board and iron it very hard using a high temperature. You can use a normal iron for this process.

Note: Make sure the copper board is shiny and not scratched. If not, use brasso cleaner liquid to clean the copper board.

After printing the circuit on the board, you have to etch it. You can use ferric chloride or any other etching solution for that. After the board is etched properly, wash it, drill the holes and solder the components into the PCB.

Components fixed to the PCB

Further, if you want to make an enclosure for your device, you can get a project box from an electronic shop and drill and fix your components to it as below.

Components fixed to the project box

Now you are ready with your small IoT device agent and happy moitoring.


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.