icon

IoT Door Monitoring with M5Stamp and Qubitro

In this post, I'll show you how to build a DIY IoT Door Lock Monitoring System using a small M5Stamp PICO controller and Qubitro.

projectImage

Hey, what's up, Guys! Akarsh here from CETech.

 

Some weird stuff is going on with me Nowadays. Every now and then, I put some snacks in the fridge to eat later, but they are all gone when I go back to eat them. I also feel that someone entered my room in my absence, played around with the stuff, and left. So I put on my thinking cap and after some brainstorming, I came to the conclusion that it might be my cute little cousin, and to catch him red-handed I made this project.

 

I have made a DIY IoT Door Lock Monitoring System using a small M5Stamp PICO controller and Qubitro and today I am going to tell you how can make one for yourself and catch anyone sneaking into your rooms in your absence. This door lock monitoring system senses the state of the door i.e. it is open or closed and records that data on the Qubitro portal which you can check for later reference. We have also attached a buzzer to it for now which makes a sound whenever the door is opened. 

 

It's a simple and fun project and can also be used as a safety device to check if someone opened your door in your absence. So let's see how it's made.

 

Components used in this project:-

1. M5Stamp PICO

2. IR Sensor

3. Piezo Buzzer

4. Some wires

 

Get PCBs for Your Projects Manufactured

projectImage

You must check out PCBWAY for ordering PCBs online for cheap!

 

You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop.

 

What Is Qubitro?

projectImage

Qubitro is a great platform to perform your IoT Operations with a continuously growing partner network to offer the fastest go-to-market time in the most cost-efficient way. A number of companies that are working in the field of IoT are partners of Qubitro. Some of them are RAK Wireless, M5Stack, TheThingsNetwork, etc.

 

It offers Quick and real-time business insights from a single control center for your projects by Automagically querying, visualizing, and understanding your metrics no matter where they are coming from. It efficiently stores sequences of measurements for real-time analytics or long-term storage natively and integrates with best in breed services all managed and scaled.

 

It also offers fully managed APIs with the help of which, we can complete a number of tasks without writing a single line of code. The APIs are designed for scalability and follow The OpenAPI Specification to support language-agnostic development. Another perk of using this platform is that it offers a Pay-as-you-connect model which requires no upfront cost and does not require any credit card details before usage. So this platform can prove to be an easy to use and good solution for your IoT needs and you can give it a try.

 

Hardware Connections

projectImage

We are going to use an M5Stamp module and to it, we will connect a Line Sensor and a piezo buzzer. The line sensor will continuously send data to the M5Stack which will upload the data to the Qubitro portal. if the door is opened, the Buzzer will make a sound. To make the connections, you need to follow the below steps:-

 

Connect the GND pin of the IR Sensor to the GND pin of the M5Stamp and the Vcc pin of the IR Sensor to the 5V pin of the M5Stamp.

Connect the output pin of the IR Sensor to the G26 pin of the M5Stamp.

Connect the Positive pin of the piezo buzzer to the G18 pin of the M5Stamp and the GND pin or negative pin to the GND pin of the M5Stamp.

projectImage

This will complete the Hardware connections of this project. Now you need to connect the M5Stamp to your computer and program it using Arduino IDE which we will be doing in the next step.

 

Coding the Project

projectImage

The Hardware Connections are done. Now you need to configure the code for this project by making some small changes and uploading that code to the M5Stamp module. You can copy the code from the Github repository of this project which you can access from here. In this repository, You will see a file named "​Qubitro_IoT_Door_Lock_Monitoring". It is the code for this project.

projectImage

Once you have pasted the code in your Arduino IDE. You need to change the network credentials mentioned in the code according to your Wifi. The fields named SSID and Password are the ones to be changed.

projectImage

After updating the network credentials, you need to change the Device ID and Device Token in order to match them with your Qubitro cloud. But to get your Device ID and Device Token, you first need to create an account on the Qubitro Portal. Once you have your account, You need to create a new project using MQTT Connection. Once the project is created, you will get your Device ID and Device Token which you need to paste into the code. Once this is done, you can compile the script and upload that to your M5Stamp module and as soon as the code gets uploaded, your project setup is done and you are ready to operate it.

CODE
#include <QubitroMqttClient.h>
#include <WiFi.h>
// WiFi Client
WiFiClient wifiClient;
// Qubitro Client
QubitroMqttClient mqttClient(wifiClient);
// Device Parameters
char deviceID[] = "62f53d7f-6f53-474a-897f-24c808629df9";
char deviceToken[] = "ardE7DqQFct2j3SrO2ApKbii1Dx6NkNx8EClSgKT";
// WiFi Parameters
const char* ssid = "ELDRADO";
const char* password = "amazon123";
int ledPin = 18; // choose pin for the LED/BUZ
int inputPin = 26; // choose input pin (for Infrared sensor)
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare Infrared sensor as input
// Initialize the serial port
serial_init();
// Initialize wireless connectivity
wifi_init();
// Initialize Qubitro
qubitro_init();
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH)
{ // check if the input is HIGH
digitalWrite(ledPin, LOW); // turn LED OFF
String Status = "Open";
int Rate = 100;
// Send telemetry
String payload = "{\"status\": \"" + Status + "\", \"Rate\": " + String(Rate) + "}";
mqttClient.poll();
mqttClient.beginMessage(deviceID);
mqttClient.print(payload);
mqttClient.endMessage();
Serial.println(payload);
}
else
{
digitalWrite(ledPin, HIGH); // turn LED ON
String Status = "Close";
int Rate = 0;
// Send telemetry
String payload = "{\"status\": \"" + Status + "\", \"Rate\": " + String(Rate) + "}";
mqttClient.poll();
mqttClient.beginMessage(deviceID);
mqttClient.print(payload);
mqttClient.endMessage();
Serial.println(payload);
}
delay(2000);
}
// Initialization code
void serial_init() {
// Initiate serial port connection
Serial.begin(115200);
// Delay for stabilization
delay(200);
}
void wifi_init() {
// Set WiFi mode
WiFi.mode(WIFI_STA);
// Disconnect WiFi
WiFi.disconnect();
delay(100);
// Initiate WiFi connection
WiFi.begin(ssid, password);
// Print connectivity status to the terminal
Serial.print("Connecting to WiFi...");
while (true)
{
delay(1000);
Serial.print(".");
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("");
Serial.println("WiFi Connected.");
Serial.print("Local IP: ");
Serial.println(WiFi.localIP());
Serial.print("RSSI: ");
Serial.println(WiFi.RSSI());
break;
}
}
}
void qubitro_init() {
char host[] = "broker.qubitro.com";
int port = 1883;
mqttClient.setId(deviceID);
mqttClient.setDeviceIdToken(deviceID, deviceToken);
Serial.println("Connecting to Qubitro...");
if (!mqttClient.connect(host, port))
{
Serial.print("Connection failed. Error code: ");
Serial.println(mqttClient.connectError());
Serial.println("Visit docs.qubitro.com or create a new issue on github.com/qubitro");
}
Serial.println("Connected to Qubitro.");
mqttClient.subscribe(deviceID);
}

Testing the Project

projectImage

As the setup of the project is done, Now you are ready to test the project. First of all, you can open the Serial Monitor of your Arduino IDe and you will see the data that the M5Stamp module is sending to the Qubitro Cloud. We will also go to the Qubitro portal and monitor the data but before that, you need to test if the buzzer System is working fine or not. For that, you need to paste the setup on your door in such a manner that the LEDs of the IR Sensor come in front of the door frame. Now open the door and you will observe that the Circuit will trigger and the buzzer will start making Sound. It will go off Once you close the door.

projectImage

Now as the setup is working fine, You need to check if the data is getting logged into the Qubitro Cloud correctly or not. For that, Go to the Qubitro portal and open the Monitoring tab. In that tab, you will see a graph. In this graph, you will observe that the graph generally moves like a horizontal flat line at a value of 100 but at some places goes down to 0. These fluctuations show the status of the door. When the door is closed, the value will remain at 100 and once it is opened, the value will move down to 0 and again move up to 100 when the door is closed. This shows that the system is working completely fine.

projectImage

So in this way, you can keep track of your doors. You can check at what times they were opened and for how much time. Hope you liked this project. We will be back soon with another fun project.

License
All Rights
Reserved
licensBg
0