“Oh God! … It seems like I have forgotten the door lock open, again” … the normal saying whenever I am in hurry to go out!
Have you encountered this problem before? It always confuses me since I may even think that I have left the door lock opened, and once I go back, I find it closed! … Crazy!!
So, I got this idea of connecting the door lock to the Internet through an MQTT broker”server”. Then, I can remotely control the lock from outside my home, using just my smartphone.
Hence, with this Arduino Door Lock project lies behind my door, it has become easy to just get my phone and see if I have closed the door lock or not, and close it. Just anywhere, anytime!
Therefore, here I am with another IoT tutorial using Arduino with 1Sheeld and just a smartphone. In previous tutorials, I have gone through connecting light and fan to an MQTT broker and controlling them using my smartphone.
Today, I am going to do the same, but for an Arduino Door Lock. So, let’s get through it 😉
In this Arduino Door Lock tutorial, I am going to connect 2 devices to an online MQTT server “broker”, the door lock, which is just an Arduino with a servo motor-based door lock and the smartphone. The phone will publish a message “open” or “close” on a certain topic. The Arduino will subscribe to the same topic. Hence, once it gets “open” message, it will move the servo motor to a certain angle and opens the door. And the “close” message will turn the servo motor back to its previous angle which will close the door lock, indeed.
Since the broker is online, then you need to connect the Arduino to the Internet, then connect it to the broker.
But Arduino alone can’t do that, so I will use the IoT Shield from 1Sheeld+ board that will be plugged into the Arduino and connect it to the online MQTT broker.
Also, you will need an iPhone “since IoT Shield works with iOS only” to be connected to the 1Sheeld via Bluetooth. And another one “iPhone or Android” that will act as the controller device where you will use it to publish “close” and “open” message through an IoT app.
You will find all the software and Apps required for this tutorial linked in the software components section.
If this is your first time to deal with 1Sheeld or you want to learn more about it, then I recommend checking this quick and easy getting started tutorial.
Furthermore, if this your first time reading about MQTT broker, then I recommend you go through this MQTT before going into this tutorial.
Now, after you’ve become a little bit familiar with 1Sheeld and MQTT broker, let’s start!
Step 1: Hardware components:
Arduino USB cable.
Servo Motor “its size depends on the door lock size”
Male-to-male jumper wires.
iOS phone with 1Sheeld App installed on it.
Android/iOS phone with the IoT MQTT Panel Pro installed on it.
Connect the servo motor with the Arduino as illustrated below:
Switch the 1Sheeld power to operate on 5v (Not the 3.3v):
1Sheeld have 2 modes: Uploading mode and Operating mode. You can switch between them using the switch close to the Digital pins and is called “UART SWITCH” on 1Sheeld and “SERIAL SWITCH” on 1Sheeld+.
Firstly, you slide the switch towards the “SWITCH” notation which turns the 1Sheeld board into the Uploading mode to let you upload the Arduino code.
Then, after you finish uploading the code, slide the switch towards the “UART” notation (or “SERIAL” at 1Sheeld+ board) which turns the 1Sheeld board into the Operating mode to communicate with your smartphone 1Sheeld App.
Finally, connect the Arduino via your PC using Arduino USB cable.
Step 4: Code:
I would recommend checking the Arduino IoT Shield documentation to know more about the Arduino IoT Shield functionalities and how to use them.
to your own broker instance credentials you got after you have created it on CloudMQTT website.
If you don’t know how to get your own CloudMQTT broker instance, please check this MQTT blog.
Then, Switch the 1Sheeld board to the Operating mode then open the 1Sheeld app and connect it to the 1Sheeld board via Bluetooth.
Step 5: Configure it:
Firstly, let’s configure the phone and connect it to the broker.
Open the IoT MQTT Panel App and create a connection to the CloudMQTT broker. Again, all these MQTT broker stuff are explained in the MQTT blog.
After that, you will add a panel with a type “switch”.
Then write any name for the panel, like “Door Locker”. Then make its topic as “door/operate”. That’s the topic which this switch will publish on.
Hence, we need to publish this message “open” or the other one “close”. So, write “open” in the “Payload on” section and “close” in the “Payload off” section. A payload is just another name for the message.
Also, you can specify an icon and colors to the switch for more pretty visual polish ^_^
When finished, press “CREATE”.
Step 6: Run the Arduino Door Lock:
First of all, you will open the CloudMQTT website from here and navigate to the Websocket UI to monitor what’s going on on the broker.
Then on the App, press on the upper right cloud-shaped button to connect the phone to the broker.
Once connected, the cloud-shaped button will change its color to be orange.
Finally, press on the reset button on the Arduino and monitor the CloudMqtt WebSocket UI panel.
And again, you will see something like this on the WebSocket UI!
That’s because once the Arduino connects to the broker, it publishes a message “ready” on the topic “door/state”. Just an indication that the Arduino has just connected to the broker. Great!
And once you press the switch on the App, the servo will move to some degrees and pulls the door lock arm to open it and vice versa for another press.
You can easily monitor all the publishing and subscribing operations on the broker from the Websocket UI console. It will be something like that:
And here is the project working 🙂
That’s it for the Arduino Door Lock, guys.
If you are interested in this IoT Blog Series, stay tuned for the next IoT tutorial which will be about getting sensor readings to the phone through an MQTT broker, too.
Arduino keeps standing out from the crowd of all-around development boards due too its ease of use and budget price. As a result, this has enabled almost anyone to get his own idea into life no matter how crazy or even useless to the whole world it was, except for its maker! Also, it has …
Arduino robots are always funny and definitely more enjoyable when combined with robotic arm! And today, I will walk you through the making of a simple Arduino Robot Arm that’s made of cardboard and how you can attach it over your Arduino Bluetooth RC Car / Robot that you have made so far through this series. …
Arduino Line Following Robot is one of the easiest and most well-known projects that anyone can make to learn the basics of programming, electronics, and mechanics all in one project. It’s known that this project is common for most of the makers and tech students and today I am going to give it a revisit …
Back again with another Arduino Bluetooth RC Car tutorial but with an advanced feature that makes your car autonomous by adding ultrasonic sensors to the RC Car you have made before!. Yeah, I know that you may have seen other tutorials using ultrasonic to make the car/robot avoid obstacles ahead, but I am going to …
Cardboard crafts are one of the most popular and easy to make DIY stuff. Mixing this with the unmatchable enjoyment of RC Cars and the ease of using Arduino, I am going to show you how to make a Cardboard Arduino Bluetooth RC car that you can control via Bluetooth from your smartphone. …
Arduino Security Camera Have you ever wanted to check your home in real time? Afraid that maybe someone has stormed in, don’t remember if you shut the door or not or maybe wanna check if your Hyper-energetic dog has broken any of your dishes AGAIN!! 🙂 Then this is the perfect place for you cause today …