Intruder Alarm

In this project, we create a simple intruder alert, using an IR Proximity Sensor. You can use the same technology to check on open doors or windows, or automate some manufacturing process.

LED Widget

The first step is to add the LED widget to your dashboard:

Change the pin of the LED widget to associate it with an available Virtual Pin, say V0.

You can also change its color to make it red, as in a Red Flag.

Otherwise, it is just a passive monitor of messages from the ESP32 board.

Pick a place for it on the dashboard and leave it there. You can resize it to be more obvious.

Connecting the IR Proximity Sensor

List of Parts

For this project you will need the following electronics from your kit beside the ESP32:

Connect

First, get your breadboard ready:

It is upside-down on purpose. I want Row 1 to be on the bottom.

Now, you need to attach the ESP32 to the breadboard.

Be VERY CAREFUL not to damage the pins when you do this:

Next, use a Female-to-Male jumper wire to connect the 3v3 (top left pin) from the ESP32 to the '+' column of the breadboard on the right hand side.

Then, use a Male-to-Male wire to connect the GND (top right pin) from the ESP32 to the '-' column on the right hand side.

The '+' may be the outermost column or the one just next to it. Or there may be no markings. Just pick one of those 2 outermost columns as (+) and one as (-) and connect as shown.

The wire colors are not important.

Now, use the female-to-male connectors to connect as follows:

IR Sensor ESP32 / Breadboard
VCC '+' column
GND '-' column
OUT GPIO PIN 15 (G15)

This completes our Smart Doorbell circuit. Use the short USB wire to connect the ESP32 to your laptop to power it up.

Coding

Start with Blynk Blink code

Open the Arduino application.

We need to create an LED Widget variable that will be tied to the Virtual Pin V0 and control the Blynk app's LED we created in the dashboard.

WidgetLED led(V0);

We will use Pin 15 to monitor the IR Sensor. We need to do this on a recurring schedule, so we will need to create a timer as well.

BlynkTimer timer;

And we will need to set it to kickoff with our IR check code every so often:

  timer.setInterval(500L, blinkLedWidget);

This is the final code you will need:

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxx";

// The timer for checking the IR state
BlynkTimer timer;

// Control the LED widget via Virtual V0 from this variable
WidgetLED led(V0);

// This is the function we will call from our timer every so often
// It checks the state of GPIO Pin 15 (G15).
void blinkLedWidget() {

  // If the IR Sensor line is HIGH, it means there is nothing in front of it
  if (digitalRead(15)) {
    led.off();
  }
  else {
    led.on();
    delay(2000);  // Wait 2 seconds, so the user gets a clear signal
  }
}

void setup() { 
  // Set G15 as INPUT
  pinMode(15, INPUT);

  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, "a9i.sg", 8081);

  // Setup the timer to go off twice a second (every 500ms) 
  timer.setInterval(500L, blinkLedWidget);
}

void loop() {
  Blynk.run();
  timer.run();
}

That's it! All you have to do is compile and upload these changes.

Compile & Upload

See instructions here

Test

After a successful upload you can test by activating the IR Sensor by placing an object in front of it.

It should cause the LED on your dashboard to light up for 2 seconds.

If it doesn't, you can ask for help.

Challenges & Showcases