IoT Based Manhole Monitoring System

Components Required

  • NodeMCU
  • SIM800L GSM Module
  • XL6009 Booster Module
  • MQ Gas Sensor
  • KY-017 Mercury Tilt Switch Module
  • JSN SR-04T Waterproof Ultrasonic Sensor
  • 18650 Cell & Cell Holder

 

Manhole Monitoring System Circuit Diagram

The complete schematic for the IoT Based Manhole Monitoring System is given below:

Manhole Monitoring System Circuit Diagram

This circuit isn’t that hard. Here we have used three sensors i.e., Gas Sensor, Ultrasonic Sensor, and Tilt Sensor, one XL6009 Booster Module, SIM800L GSM Module, and 18650 cells. XL6009 Booster Module is used to boost the voltage from 18650 to 5V, Gas sensor is used to detect the presence of Gas. The Ultrasonic Sensor is used to detect the water level and the Tilt sensor is used to detect whether the cover of the manhole is tilted or not. Finally, a SIM800L GSM Module is used to send SMS notifications about these events.

Manhole Monitoring System Code

Now after connecting the components, it’s time to program the NodeMCU to read the sensor data and send the message updates about the changes in sensor readings. The complete code for the same is given at the end of the document. Here we are explaining some important parts of the code.

The code starts by including the SoftwareSerial library and defining the NodeMCU pins connected to the sensor and GSM module.

#include <SoftwareSerial.h>
#define sensor D5
#define ECHOPIN D7
#define TRIGPIN D6
int sensorPin = A0;
SoftwareSerial mySerial(D3, D2);

Then inside the setup() function, define the trigger pin as an output, the echo pin of ultrasonic sensor, and signal pin of tilt sensor as an Input and also start the serial communication at 9600 for showing the results on the serial monitor.

Serial.begin(9600);
pinMode(sensor, INPUT);
pinMode(ECHOPIN,INPUT_PULLUP);
pinMode(TRIGPIN, OUTPUT);
digitalWrite(ECHOPIN, HIGH);
mySerial.begin(9600);

In the loop, first, we are reading the Tilt sensor and Gas sensor readings using digitalRead() and analogRead() functions and then to measure the distance using ultrasonic sensor, first set trigger pin to LOW State for 2 µs to make sure that the trigger pin is clear. Then set the trigger pin high for 15 us to send an ultrasonic wave. We will use the pulseIn() function to read the travel time and store that value into the variable “duration”. In the end, we will print the value of the distance on the Serial Monitor.

int readings = digitalRead(sensor);
int val = analogRead(A0);
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(15);
digitalWrite(TRIGPIN, LOW);
int distance1 = pulseIn(ECHOPIN, HIGH, 26000);
int distance=distance1/58;
Serial.println(distance);
Serial.println("   cm");
delay(500);

Then in last, we are comparing these readings and if the readings exceed a predefined value, then we will use the GSM module to send the SMS notifications. The AT commands to send messages are explained below:

AT+CMGF=1 – Used to select message format as text. By default, the format is Protocol Data Unit (PDU)

AT+CMGS=+ZZxxxxxxxxxx – This command with the phone number specified sends an SMS message to a GSM phone.

mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CMGS=\"+919829559608\"");
updateSerial();
mySerial.print("Tilt Detected"); //text content
updateSerial();
mySerial.write(26);

 

Building the Circuit on Perf-board

After testing the circuit on the breadboard and making sure that everything works fine, I proceeded with building the circuit on perf-board to make it more application friendly. The soldered board looks like below:

Manhole Monitoring Device

 

Testing the Manhole Monitoring System

Now as everything is ready, let's test the setup. For testing, I filled the bucket with water and used the sunboard as a cover for the bucket. Then I mounted the hardware on the cover as shown below:

 

Initially, the bucket is empty and the cover is perfectly balanced but when we tilt the cover, the tilt sensor detects the movement and sends a message. Similarly, we tested the Gas sensor and Water level and it worked as expected.