How to Make a Proximity Alarm Using Radar and LoRa

by radicalroundcat in Circuits > Gadgets

72 Views, 2 Favorites, 0 Comments

How to Make a Proximity Alarm Using Radar and LoRa

humandetectorthumb.png
mount.png

Here's how to make a human presence detector that can remotely alert you of someone being nearby a specific location.

Why on earth would you need this?

Well, for one, you might be taking a walk in a nearby park and will want to monitor the position of a pet at home.

Or, you might be committing a crime, like a bank heist, and need something to alert you when law enforcement is approaching.

Inversely, if you are a bank owner, you might want a system that can detect any intruders!

Regardless of your use case, you should make this anyway, 'cause its so cool, featuring a LoRa and Radar module.

Supplies

2x - ESP32-C3 Super Mini

2x - Ebyte E220 LoRa modules

2x - 915MHz Antennas

Note: when selecting a LoRa module, be wary about the certain frequency range it operates on. I live in the US, so its safest to transmit around the 915mhz range.

1x - SSD1306 OLED display

1x - HLK-LD2420 Radar module

2x - Solderless breadboards

1x - USB to TTL Adapter

And some jumper wires

Configuring the LoRa Boards

version.png
1776030265529-g9r66u.png

Before using your LoRa module, you might want to configure some of its properties, such as its baud rate and its channel. This can be done using code, but it's easier to just use the software provided by Ebyte. You can always skip this step if you don't need to change any of the default settings.


https://www.cdebyte.com/download_serch/E22/4

Wiring the Transmitter

transmitterWiring.jpg
FOEL6RRMO3IVPMK.jpg
FICR36NMO3IVPLR.jpg

The transmitter will be the device that uses the radar to sense anyone nearby.

Wiring the it is pretty straightforward. Simply connect the E220's TX and RX to 6 and 7 of the ESP32-C3, and ground its M0 and M1 pins, and make sure to keep its AUX pin floating (I learned that the hard way).

As for the LD2420, its TX (OT1) and RX will be 4 and 5.

Programming the Transmitter

image.png

Create a new Arduino project. I personally use PlatformIO since believe it or not, I don't know how to use the Arduino IDE. Still, the process should be about the same.

Set the board to "ESP32C3 Dev Module", set the monitor speed to 115200, set "USB CDC On Boot" to "Enabled", and "USB Mode" to "Hardware CDC and JTAG"


Then, flash the following code to your esp32c3:

// THIS IS THE TRANSMITTER

#include <Arduino.h>

void setup() {
pinMode(1, INPUT);
Serial.begin(115200);
delay(2000);
Serial.println("dddd");
Serial0.begin(9600, SERIAL_8N1, 6, 7); // Serial0 - E220
Serial1.begin(115200, SERIAL_8N1, 4, 5); // Serial1 - LD2420
}

unsigned long lastTransmitted = millis();
void loop() {
if(Serial1.available() > 0) {
String val;
for(char c: Serial1.readStringUntil('e')) { // this extracts the distance value
if(c != '\n') {
Serial.print(c);
val += c;
} else {
break;
}
}

Serial.println(val);

if(millis() - lastTransmitted >= 2800 && val.toInt() < 167) {
Serial0.println(val); // this sends the distance value to Serial0 for transmission, which is connected to the LoRa module
lastTransmitted = millis(); // delay for 2800 ms so the fcc doesn't kick your door down
}
}
}

Wiring the Receiver

receiver.jpg
r1.jpg
r2.jpg

The wiring for the E220 is mostly the same as the the transmitter counterpart. However, we now have an oled display instead of the Radar, and its SDA will be connected to Pin 8 of the esp32, and its SCL will be Pin 9.

Programming the Receiver

Create another Arduino IDE project, with a mostly similar same configuration as the transmitter's.

For the receiver, I used the Adafruit SSD1306 library


The code is slightly longer but is still relatively simple.

By the way, here's a helpful site for generating drawings for the SSD1306

// THIS IS A RECEIVER

#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>

HardwareSerial E220(1);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

void setup() {
pinMode(5, INPUT_PULLUP);
Serial.begin(115200);
delay(1000);
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
// Serial.println("oled failed");
for(;;);
}

oled.setTextSize(1);
oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0,0);
oled.clearDisplay();
oled.setRotation(2);
oled.println("Receiving!!");
oled.display();

E220.begin(9600, SERIAL_8N1, 6, 7);
// Serial.println("reading");
}

unsigned long buttonCooldown = millis();
unsigned long lastReceived = millis();
void loop() {
if(millis() - lastReceived >= 4000) {
oled.clearDisplay();
oled.display();
}

if(E220.available()) {
oled.clearDisplay();

oled.drawCircle(18, 15, 11, 1);
oled.drawLine(16, 9, 16, 12, 1);
oled.drawLine(23, 12, 23, 15, 1);
oled.drawLine(12, 14, 14, 21, 1);
oled.drawLine(14, 21, 24, 19, 1);
oled.setTextColor(1);
oled.setTextWrap(false);
oled.setCursor(44, 5);
oled.print("Person");
oled.setCursor(44, 15);
oled.print("Detected!!");
oled.display();

oled.setCursor(8, 48);
String val = E220.readStringUntil('\n');
oled.print("Distance: ");
oled.print(val);
oled.display();
lastReceived = millis();
}
}

Modelling an Enclosure in Autodesk Fusion

s1.png
s2.png
s3.png
s4.png
s5.png

I wanted my project to fit on a 400 pin breadboard with the rails on each side of it removed, so I designed an enclosure around those dimensions. I also left a hole for the E220 to protrude from, and a hole on the lid so the display was visible.

You can also convert it into a PCB or something, but that's too hard for me so I'll stick with the breadboard for now.


I'll attach my step files here, conveniently, the same enclosure works for both the transmitter and the receiver.

3D Print the Enclosure

bam.png

Assembly and Testing

weee.jpg
mount.png

Insert everything into the enclosure and put the lid on. It's best to mount the receiver on a wall as shown in one of the pictures above. It'll send the distance between it and any moving object, in centimeters, to the receiver.


If the receiver receives a signal, it'll display "Person Detected!!" and write the distance between the receiver and the subject. However, this will also pickup pets or anything moving that shouldn't be.


The E220 is a very powerful module, and can theoretically reach 5 kilometers in a rural area (or anywhere without significant obstructions), so go outside and test it out!!