by Ayush Dawar(30862)
Microcontrollers have spread everywhere sometimes even without us realizing that. Fridges, kettles, toys, smart sockets and switches, automatic gates — all of them are operated with the help of microcontrollers. That to for a good reason. They can reduce the cost and size of the system by integrating most of the functions on a single chip. They can be programmed and reused for different applications, making them flexible and versatile. They can operate with low power and heat consumption, making them suitable for battery-powered or energy-efficient devices. They can interface with various sensors, actuators, and communication modules, making them capable of performing complex tasks. In this project we are going to creating a DIY intrusion detection system. One might ask why they need a system like that. Here are some reason that might make you interested in this project :
The ESP32-CAM is a versatile and powerful camera module that can be used for a variety of applications. It is small, low-power, and easy to use. The ESP32-CAM is a great choice for anyone looking for a wireless camera module for their IoT project. Here are some of the key features of the ESP32-CAM:
A passive infrared (PIR) sensor is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors. PIR sensors are commonly used in security alarms and automatic lighting applications. PIR sensors work by detecting changes in infrared radiation. When an object moves in front of a PIR sensor, it blocks some of the infrared radiation that is being emitted by the object. This change in infrared radiation is detected by the PIR sensor and is used to trigger an alarm or turn on a light. PIR sensors are a type of passive sensor, which means that they do not emit any radiation. This makes them ideal for security applications, as they cannot be detected by intruders. PIR sensors are also relatively inexpensive and easy to use.
UartSBee v5 is a USB to serial adapter that is compatible with FTDI cables. It has a 20-pin 2.0mm BEE socket and an integrated FT232RL chip. The FT232RL chip can be used for programming or communicating with MCUs. UartSBee can also be used to connect a PC to various wireless applications via a Bee compatible module. In addition, UartSBee provides breakouts for the bit-bang mode pins of the FT232RL chip. These bit-bang mode pins (8 I/O pins) can be used as a replacement for applications that involve the PC parallel port, which is becoming increasingly rare. Usb cable The usb cable is need to connect the programmer to the PC when the ESP32 cam is connected to flash the code. Later on, it is also used to power the ESP32 cam and the whole circuit.
A breadboard is a prototyping tool that allows you to build electronic circuits without soldering. It is a rectangular board with a grid of holes that are connected together electrically. The holes are typically arranged in rows of five, and each row is connected to a common bus. This allows you to easily connect components together without having to solder them.
These are used to connect components with each other.
The scenario we would like to implement is as follows:
I would be using Arduino IDE for this project to flash the code
Download the code from the following link https://github.com/flespi-software/ESP32-CAM
First we would install the board for the ESP32-Cam in Arduino. ^^
Fig.3: Board Manager Arduino |
To make the code work you need to specify your personalized data for some parameters:
const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD";
const char* mqtt_server = "mqtt.flespi.io"; const int mqtt_port = 1883; const char* mqtt_user = "YOUR_FLESPI_TOKEN"; const char* mqtt_password = "";
My mqtt server settings looked something like this : ^^
Fig.4: MQTT Server Settings |
The ESP32-CAM can work in two modes in the code one is the periodic photo capture every N seconds or motion- triggered photo capture with help of the PIR sensor connected. In our case, we would prefer the capturing of photo triggered due to the PIR. In the code you have to change the value to 0 in the following code line.
#define SLEEP_DELAY 60000 //Delay for 60 Sec
Once we make the following changes we can start uploading the code to the ESP32-Cam by connecting it to the UartSBee using the connections given below.
UartSBee | ESP32 Cam |
---|---|
5V | VCC(5V) |
UOR | TX |
UOT | RX |
GND | GND |
GPIO 0 to GND |
After successfully flashing the ESP32-CAM we can start by making the circuit as per the given below circuit diagram :
The circuit looked something like this after following the circuit diagram:
If the all the connections are right. The image with timestamp captured due to triggering of PIR sensor can be found in dashboard of your relevant MQTT broker:
To the get the notification on the phone. The following procedure is needed:
First is to download the Telegram app on your phone and then the install the application Node-Red. You would need to create a bot on the Telegram app and install the following libraries in the Node-Red as shown in the image.
Once the nodes are installed we make connections with the following nodes :
The JSON file for Node-RED can be found below :
[{"id":"c28d1213.3a847","type":"mqtt in","z":"01e310afdf513967","name":"Gate Movement","topic":"gate/motion/state","qos":"0","datatype":"auto","broker":"e50612ee.93d158","nl":false,"rap":false,"inputs":0,"x":360,"y":140,"wires":[["b6291d0.4869e6"]]},{"id":"e50612ee.93d158","type":"mqtt-broker","name":"MQTT_Broker","broker":"mosquitto","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":"","credentials":{}}]
The telegram bot and MQTT needs to configured in Node-RED.
The ESP32-CAM is a powerful microcontroller which can be used for DIY projects. This project is just one showcase how it can be used. It can be used in a variety of different projects. Here are some possible use cases:
And in many other appliances
Possible problems that might occur:
To conclude microcontroller are amazing devices which most people can afford. If one decides automize things in his life. They are an essential tool in toolbox.