Home / Projects / ESP8266 Projects / Ultrasonic Door Lock with WiFi Control
ultrasonic door lock wiring diagram

Ultrasonic Door Lock with WiFi Control

For this project, I am using an HC-SR04 ultrasonic sensor for opening a solenoid door lock. Basically, the ultrasonic sensor acts as a proximity detector. A solenoid lock triggers when an object blocks the sensor at a given distance. In addition, a web app can act as WiFi remote control for the lock.

Materials

Wiring Diagram

ultrasonic door lock wiring diagram

About the Project

The HC-SR04 produces an ultrasonic signal which bounces back to it when there’s an object in front. The distance of the object from the sensor is known through the time difference between sending the signal (trigger) and receiving back the signal (echo) then multiplying by half of the speed of sound.

In the equation above, 0.034 is the speed of sound in centimeters (CM).

I set the trigger distance to 10 CM, i.e., the solenoid triggers every time an object is within 10 CM from the sensor. Solenoid locks require a high current to trigger and may produce unwanted flyback. Thus, the solenoid and the microcontroller must be isolated.

A MOSFET is used to drive the solenoid which requires 9-12 VDC and 1 A of current. The higher voltage is converted to 5 VDC using the LM2596 DC-DC converter. The MOSFET is, in turn, driven by a relay module by shorting its gate to the 5 VDC source. The MOSFET and relay combination ensures that the microcontroller is properly isolated from the solenoid. A buzzer is added to indicate that the lock has been released.

WiFi App

If a WeMos D1 Mini is used instead of the Arduino Pro Mini, the lock can be triggered remotely using WiFi. This is done through the MQTT protocol. I created a simple web app that sends a command to the MQTT broker when a button is pushed. The broker, in turn, publishes the command to a topic where the WeMos D1 Mini is listening to. Here’s a screenshot of the web app, viewed from a smartphone:

solenoid wifi remote control app

The Arduino sketch and code for the web app (remote trigger) are found in this repository.

How to Get Parts

For those living in the US or Europe who would like to clone this project, I strongly recommend getting the parts at UTSource. They support almost all global payment options and shipping and they have refurbished parts that are very much cheaper compared to new ones. For example, their refurbished original Arduino UNO is:

In comparison, here’s the price for the board from other stores:

I've experienced using refurbished Arduino's before and I can say it still performs like a new one.

Kindly share this project with others if you find it to be useful. Thanks for reading!

Check Also

NodeMCU IoT Environment Monitor

Project Overview This NodeMCU IoT project is a simple demonstration on how to send sensor …

Leave a Reply

Your email address will not be published. Required fields are marked *