-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmwradarupload.ino
84 lines (69 loc) · 2.07 KB
/
mwradarupload.ino
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* MM Wave Radar alarm
* Roni Bandini bandini.medium.com @ronibandini
* May 2023
* MIT License
* Parts: DFRobot ESP32-C3, DFRobot SEN0395 MM Wave Radar,
*/
#include <DFRobot_mmWave_Radar.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#define BOT_TOKEN ":"
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
String chat_id="";
String test_photo_url = "https://www.comersus.com/images/mmwavealarm.png";
WiFiClientSecure secured_client;
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
bool Start = false;
HardwareSerial mySerial(1);
DFRobot_mmWave_Radar sensor(&mySerial);
int LED_BLINK = 10;
int howManyMeters=2; // until 9
int loopDelay=100;
int alarmDelay=10000;
int lastStateWasClear=1;
void setup() {
Serial.begin(115200);
mySerial.begin(115200, SERIAL_8N1, 5, 7); //RX,TX
sensor.factoryReset();
sensor.DetRangeCfg(0, howManyMeters);
sensor.OutputLatency(0, 0);
delay(2500);
Serial.println("MMWave Radar Alarm started");
Serial.println("Roni Bandini, May 2023");
pinMode(LED_BLINK, OUTPUT);
// attempt to connect to Wifi network:
Serial.print("Connecting to Wifi SSID ");
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.print("\nWiFi connected. IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
int val = sensor.readPresenceDetection();
if (val==1){
digitalWrite(LED_BLINK, 1);
Serial.println("--Person or animal nearby");
if (lastStateWasClear==1){
bot.sendPhoto(chat_id, test_photo_url, "Alarm");
bot.sendMessage(chat_id, "There is someone behind the door - Powered by DFRobot MM Wave sensor");
}
lastStateWasClear=0;
delay(alarmDelay);
}
else
{
Serial.println("All clear");
digitalWrite(LED_BLINK, 0);
lastStateWasClear=1;
}
delay(loopDelay);
}