In this tutorial we will see how to make a motion detector system, with a PIR sensor, a relay module, to connect a 110V/220V focus, an esp32 that will connect to our Wifi network and send alert notifications, by messages through the telegram messaging service, when the PIR sensor detects a movement.
You may be interested in projects in Arduino, pic, robotics, telecommunications, subscribe http://www.youtube.com/user/carlosvolt?sub_confirmation=1 videos with full source code and diagrams
Circuit
Electronic components
Cables dupont
ESP32
Features of the ESP32-T module
Connectivity
The ESP32 module has all the wiFi variants:
- 802.11 b/g/n/e/i/n
- Wi-Fi Direct (P2P), P2P Discovery, P2P Group Owner mode and P2P Power Management
This new version includes low-power Bluethoot connectivity
- Bluetooth v4.2 BR/EDR and BLE
- BLE Beacon
In addition, you can communicate using SPI, I2C, UART, MAC Ethernet, Host SD protocols
Microcontroller features
The CPU consists of a Tensilica LX6 Model SoC with the following features and memory
- Dual 32-bit core with 160MHz speed
- 448 kBytes ROM
- 520kByteS SRAM
Have 48 Pins
- 18 12-bit ADC
- 2 8-bit DAC
- 10 pin contact sensors
- 16 PWM
- 20 Digital inputs/outputs
Power and consumption modes
For proper operation of the ESP32 it is necessary to supply a voltage between 2.8V and 3.6V. The energy you consume depends on the mode of operation. It contains a mode, the Ultra Low Power Solution (ULP),in which basic tasks (ADC, PSTN…) continue to be performed in Sleep mode.
A focus
Sensor PIR
Calibration When the pir sensor is energized requires a preparation time to start operating properly. This is because adaptation to the conditions of operation of the environment where it was installed has to occur. During this moment the sensor learns to recognize the state of rest or non-movement of the environment. The duration of this calibration can be between 10 and 60 seconds and the absence of people in the sensor neighborhood while calibrating is highly recommended.
Features:
- Infrared sensor with control circuit board.
- Sensitivity and retention time can be adjusted.
- Small and light, it is easy to use.
- Detection distance is up to 6 meters.
- Suitable for security field, toy, control automation, etc.
PIR ROBOX IR sensor features
March | Robox |
Model | RTHW |
Color | White + Green |
Material | PCB + Plastic board |
Features | Static power: 50uA; Detection distance: 7m; Detection angle: 110 degrees; Wide voltage range: DC 4.5 20V |
Application | Detect motion |
Weight: 0.25 oz (7 g)
Pines macho
Socket
Relay Module
TECHNICAL SPECIFICATIONS
- Operating Voltage: 5V DC
- Control Signal: TTL (3.3V or 5V)
- Number of Relays (channels): 1 CH
- Max capacity: 10A/250VAC, 10A/30VDC
- Max current: 10A (NO), 5A (NC)
- Action time: 10 ms / 5 ms
- To activate output NO: 0 Volts
Printed Circuit
Gerber file
Source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#include <WiFi.h> #include <WiFiClientSecure.h> #include <UniversalTelegramBot.h> #include <ArduinoJson.h> // Reemplazar con los datos de tu red wifi const char* ssid = "Tu_red_wifi"; const char* password = "Tu_clave"; //Token de Telegram BOT se obtenienen desde Botfather en telegram #define token_Bot "Tu_token" // El ID se obtiene de (IDBot) en telegram no olvidar hacer click en iniciar #define ID_Chat "Tu_chat_ID" WiFiClientSecure client; UniversalTelegramBot bot(token_Bot, client); const int sensorPIR = 23; // Pin donde está conectada la entrada del sensor PIR const int luz = 13;// Pin para luz de 110 o 220 V( Con módulo relay) int conteo = 0; String mensaje = ""; String conteoString = ""; int PIR = 0; ////Setup//// void setup() { Serial.begin(115200); // Activamos el resistor de PULLUP para la entrada sensor PIR pinMode(sensorPIR, INPUT_PULLUP); pinMode(luz, OUTPUT); // Intenta conectarse a la red Wifi: Serial.print("Conectando a la red wifi... "); Serial.println(ssid); //Seteo de la red Wifi WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(""); Serial.println("Conectado a la red wifi!!!"); Serial.print("Dirección ip: "); Serial.println(WiFi.localIP());//Imprimimos la direción ip local bot.sendMessage(ID_Chat, "Sistema preparado!!!", "");//Enviamos un mensaje a telegram para informar que el sistema está listo } /////loop////// void loop() { PIR = digitalRead(sensorPIR);//Leemos el estado del del sensor PIR //Si es igual a "1" se cumple la condición if(PIR == 1){ digitalWrite(luz, HIGH);//Encendemos la luz Serial.println("Luz Encendida!"); conteo = conteo + 1;//Incremento en el contador de movimientos detectados conteoString = String(conteo);//Lo convertimos a una cadena mensaje = "Movimiento detectados: " + conteoString;//Concatenamos ambas cadenas bot.sendMessage(ID_Chat, mensaje, "");//Enviamos el mensaje a Telegram delay(5000);//mantensmos la luz encendida este tiempo digitalWrite(luz, LOW);//Luego la apagamos Serial.println("Luz apagada!"); PIR = 0;//Asignamos el valor "0" a la variable PIR para que deje de cumplirse la condición } } |
Download Library –> Universal-Arduino-Telegram-Bot-master
Create Bot on Telegram
In telegram we look for BotFather
We write /start and something similar to this will appear to us
Escribimos /newbot
I will see the name of the bot, and we invent a name for our bot, it must be in the format «usuario_bot»
We’ll get a token that we’re going to use in the source code
Now we’ll look for IDBot, and we’ll start it
We write /getid and it will give us user_id that we should place in the source code
SUBSCRIBE TO OUR NEWSLETTERS, RECEIVE IN YOUR EMAIL THE MOST OUTSTANDING NEWS, JUST BY ENTERING YOUR EMAIL
[wysija_form id=”1″]
RECOMMENDED PROJECT