Introduction: Motion Detector With Blynk Notifications (WeMos D1 Mini + HC-SR04)

About: Technology geek, love discovering new possibilities...

Please VOTE for this project in the Wireless Contest. Thank you!

Update no.2 - Few tweaks (version 2.2), you can setup you sensor (range and name) right in the definition. Also, it sometimes happened that the sensor read wrong values and sent notification, so I added and "if" where the values must be within the range twice in a row. If you still have troubles with it, you can adjust it for reading 3,4,....x times before the notification is sent.

String location = "Garage";
int rangeMin = 0;
int rangeMax = 50;


Update no.1 - I'm still discovering the secrets behind Blynk...this comes with cleaner code (version 2.1), proper loop, etc. Enjoy and let me know how this project works for you....thanks!

I wanted to make a motion detector that would notify me every time my garage door is opened. I was playing with PIR sensor for a while but after having some setup issues (sensitivity x time) I decided to use the HC-SR04 sensor instead...and it works like a charm. The idea is simple: you setup the detector so when the door (or window - depends on how you want to use it) is opened, it gets in the way of the sensor so the measured distance is changed. The advantage using the UltraSonic sensor instead of PIR huge. It can't be triggered with light or mosquitoes which was the main reason I didn't want to use the PIR.

What you will need:

  • WeMos D1 mini board - eBay - USD 3.47 (other boards are possible - just note that e.g. NodeMCU ESP-12E V1.0 gives out only 3.3V and the HC-SR04 sensor needs 5V)
  • HC-SR04+ Ultrasonic sensor - eBay - USD 1.06 (using "+" as it can operate on 3.3V)
  • Blynk app(if you are new to Blynk and using iOS device, you will need to borrow an Android phone for setting up the notifications)
  • Breadboard or soldering iron
  • Wires
  • Computer with Arduino IDE installed

Step 1: Getting the Parts Together

I heard about people having issues when powering the HC-SR04 sensor from the board. It works fine for me, but the safest way to prevent this is to use HC-SR04P (or "+"), which has an input range of 3 - 5.5v

Connections (see the diagram)

WeMos D1 --> HC-SR04(P)

5V --> VCC

G --> GND

D6 --> Echo

D7 --> Trig

Step 2: Blynk Setup

For those who don't know what Blynk is, it is a Platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet. It's a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets.

Let's start on Andorid device:

  • Download the Blynk app
  • Sign up or login (if you already have an account)
  • Tap "+" to create New Project
  • Give the project a name and select device you are using (in our case it is ESP8266) and tap "Create"
  • You will receive an Authentication token in you mail box, we are going to need it later
  • On the Blynk Project page tap "+" to add notification widget (if this is your first Blynk project, you should have enough energy to buy it) and set it up as you wish. I use settings as displayed on the screenshot.
  • In the project settings (nut icon on the top) "Send app connected command" to ON.
  • Close the settings and hit the Play button

Now you can login to Blynk app on your iOS device as well and you should see the project with the notification widget.

Step 3: The Code

Now it is time to upload the code to our board.

  • Open the *.ino file in Arduino IDE
  • Connect the WeMos board to your computer
  • In Tools select the WeMos D1 R2 & mini board
  • Adjust the following:

char auth[] = "Your authentication token from your mail box goes here";
char ssid[] = "Your WiFi name";
char pass[] = "Your WiFi password";

  • Also, you can change the range, where you want to be notified (default is set to 1 - 49cm)

if (0 < distance && distance < 50) {

  • Hit Upload

Congratulations! If everything was set right, you should now receive your first notification!

Step 4: Summary

There are three notifications you will be receiving now. The first is telling you, that the Detector was successfully connected to your WiFi, the second notification you will be receiving is when something gets within your setup range. And the third when your Detector is disconnected due to connection or power supply issues.

The modifications you can make to this project are endless. You can setup more notifications for different ranges (Just be aware that Blynk allows notifications after 15s at least). Use different sensors, etc.

I hope you like this project, if you do, please vote for me and leave a comment/suggestion...I will be happy to get some insight from the others!

Have FUN!

Wireless Contest

Participated in the
Wireless Contest