Project by David191372; LoRa P2P Wireless Gate Alarm

I have just shared a new project: “LoRa P2P Wireless Gate Alarm”



IntroductionMy front gate is a long way from the house at around 300m. I don’t want people wandering around my property without knowing about it.  This project uses two Raspberry Pi Pico’s and two LoRa modules. One standard Pico is …

Read more

2 Likes

Hey David,

What an awesome project! I love that you are also logging when the gate is opened and closed, its an awesome idea for someone like me that is extremely forgetful when it comes to gates (Had a cow in my front yard once from this unfortunate attribute). Just to double check without having to physically get up and look. I just might have to build a similar set up for myself in future!

Cheers,
Blayden

2 Likes

Hi Blayden,
I’m glad you like it. I had fun making it.
The electronic side of things is very simple, It just clips together mostly, all the magic is in the software.
I’m about to release a new version of the the code that adds more details to the web page so you can easily see historic details plus huge savings in power usage on the gate module from about 6 hours to something like 72 hours. Currently the house plays a configurable number of “beeps” then stops. I could make it beep continuously until the gate is closed. Maybe a configurable option for a future update. At the moment It’s more to attract my attention to someone entering.
With a bit of skill understanding the python code it could be morphed into what ever you like. I’m just wrestling with what I think is a memory leak at the moment before I publish the next version. The current version is quite stable for people to start with.

Regards
David

2 Likes

Hi Everyone,
I have made some updates to the software to smooth out a few bugs.
Version 2.0 is now on GitHub.

I created a little video on YouTube with a short description and a demo of the device in operation.

Version 2 includes some more details on the internal web page on the house Pico so it can list the most recent gate events and the available battery voltage at the gate device.
Plus it has a button to test the LED, Play the gate open tone and reset the number of gate open events on the LED and a list of all the possible error conditions.

I added a PicoDev Magnetometer to sense the movement of the gate away from the closed position.
This was way easier than trying to mount the microswitch on a cam that could get bent up by my cattle.
I have added code in V2 for the Mangetometer. If the gate moves more than 5deg from its position when the device starts up (closed position) it detects the gate as being open. This is configurable in the file constants.py. The magnetometer seems to drift 1 or 2 deg so 5 is a safe option to avoid false detections. It’s meant to detect vehicles not pedestrians :slight_smile:

I have also included a reset button on the gate Pico. It just connects the RUN pin (#30) to ground.
No software changes are required for this button to work.
This causes the device to restart, primarily to set the current gate position as the closed position but it also has the effect of clearing out the debug log. The storage on the device fills up quickly with the debug level set anything higher than 1. If your not trying to solve a problem just set the debug level to 0 on both devices.
Let me know if you build one of these!

4 Likes

Hey David,

That’s awesome! This is a great project, hopeful you’ll start to see some completed versions soon.

I especially like the idea of using the magnetometer to sense the gate movement.

Brilliant work :slight_smile:

Cheers,
Sophia

1 Like

Hi, Sophia,
Well it’s kind of finished.
Although is software ever finished. :cowboy_hat_face:
Further testing has reviled when the gate is fully open the antenna is partly shielded behind the wooden board I mounted the device on. It could also be shielded partially by the vehicle parked in front of the gate while leaving.
My solution is to include two new fields in the json string that gets transmitted between the two devices
One for an Acknowledgment flag.
After a message is sent the sender waits for an acknowledgement
If it doesn’t get one the message can be resent.
Another field for “Time To Live” or TTL. After X number of retries the message is abandoned.
I have also toyed with the idea of “over the hill” messages and these kind of fields would be required to use a relay device in the middle. But I have no need for one of those at the moment.
I think the programming power of these little Pico’s is hugely underrated.
I used to dream about stuff like this in the mid 1980’s.
I now have a friend asking me to build a remote monitor for his electric community barbecue that lives in a local park :cowboy_hat_face:

2 Likes

Hi David.
The wooden board should not affect the antenna much if at all. More likely parts of the gate in line with transmission path, particularly vertical bits (I noted your antenna is vertical). If you could mount it so the antenna is above the top rail (assuming it is metal) you might improve things quite a bit.
Cheers Bob

Hi Bob,
You could be right about the steel of the gate.
It’s below the horizontal bar but the vertical bar in the centre may just line up.
When I was first testing the range I did a ping test where the devices simply sent the word “ping” to each other. If I held the device in front of me it worked but if I stood in the way it failed. So the line of site thing is kind of important.
That piece of wood is only about 20mm thick (3/4”) but it’s a lot thicker when on the diagonal. If you watched the video you can see who I have to content with so I need to keep it fairly robust. It will take a beating if one of those girls decides to scratch her arse on it. As I said to Sophia the retransmit thing will probably solve it. Aka software solution not hardware solution.
I’ll post again when I solve it.
David

Hi David
The wood could be a problem if it takes on any moisture but I reckon your main problem would be the vertical bits of the gate mesh and even the hooks on the back.of which one would be pretty close to the antenna. Anything metallic with a resonant length at the frequencies involved will be problematic.The PVC box has flanges on it so you might be able to dispense with the wood and fashion some non metallic bracketry to fit that box above the top of the gate. I don’t know what effect the gate metal has on the magnetometer but there is a chance it might work better too. I assume it is inside the box somewhere.

By the way those yellow cable ties might not last very long in the sun. Black would be vastly better.
Cheers Bob

@David191372 what a great upgrade with the magnetometer :smiley: It’s always gratifying to see the creative uses people will put our hardware to. I’ll be curious to see the long-term performance, but it sounds like the system will be more or less self-correcting/self-calibrating since you’re only looking for a difference of 5°. Very nice :clap:

Hi David,

This has piqued my interest as I am in a similar situation.

My gate is about 700m from the house and neither is visible from the other. I’ve had issues in the past with people entering my property to steal firewood, or the usual religious groups who turn up unannounced and uninvited (mind you, a couple once walked the full driveway in 40+ degree heat only to be turned around!).

For a number of reasons, I am unable to close the gate and I like your solution, but I’d like to substitute one of those microwave units to detect vehicles entering and notify me by an alert in the house or SMS, which would give me a chance to check the cameras.

The block is quite heavily treed with no clear line of sight.

Do you think your type of setup would work in this environment?

Cheers,
Alan

1 Like

Hi @Alan37799 - sounds like a worthy cause for some making.

LoRa is quite line-of-sight so geographical obstructions could be a killer here. It’s totally dependent on the unique properties of your setup and your geography.

It’s possible you will be able to transmit that far, but requires experimentation.

Meshtastic is all the talk at the office - we’ve got a few fanboys in the office (@Blayden , @Jaryd , myself)… it’s possible you can even set up a multi-node network to route around or over obstructions… but that’s a bigger project entirely :sweat_smile:

If you have good reception on the block then a SMS notification / MQTT could be the simplest hardware deployment - we have an entire cellular category of hardware.

Power management becomes a major (and often trickiest) part of a remote project. I don’t suppose you have power at the gate? If not we have this really nice looking solar charge controller, also available in a more sophisticated version

Hi Alan,
I think it would be possible. It would depend on how many steps/jumps it would take to leapfrog back to your house. Don’t forget you don’t have to go along your driveway. If there is a point on a hill that you can see both from your gate and your house you could put the repeater there.
I’ve included station names in my code even though I didn’t need them in my solution. It wouldn’t take much to implement retransmitting a signal between stations. I’ve run into a problem with mine where when the gate is open the mesh of the gate interrupts the signal. I’ve just about finished implementing an acknowledgement signal back to the sender so if the message is not acknowledged it can send the message again a few seconds later. If your not sensing movement of the gate then that’s not a problem for you. I have also included a time to live counter so the message can be discarded instead of flattening the battery. The solar panel easily charges the little battery with only an hour or two of bright day light. I have included the current voltage in the message so I can monitor the voltage. It never seems to go below 60%. As for sensing intruders when your gate is left open I’m sure there are a lot of options. You can get range finders that measure the distance between objects for example. Just point it at your other gate post.
Check the distance every couple of seconds and the distance changes something is in the way. (Or someone has stolen the other post :cowboy_hat_face:)
You might need a slightly larger battery as checking the post frequently may use more power. Just some ideas for you to go on with.
Let us know if you head down this path. You would probably be able to set up a demo with two units for around $100 in round figures.
When testing mine I just sent the word “ping” from one unit.
When the second unit received it, the LED would toggle. So I could walk around testing the range. I think the ping code is still in the software archive Test folder. If not I could find it for you.
Good Luck
David

Great project David.

BTW I’ve been watching a few of your other vids, it seems that we are very similar, IE interested in machining, blacksmithing, embedded electronics, living in the bush etc :grin:

Anyway I need something similar for my gate (400m from the house).

1 Like

Hi Rob,
It’s great to hear from other like minded people. I get so few comments on YouTube it sometimes seems like no one is interested. My most popular videos are fixing my chainsaw, mower and tape measure! People watch, get the golden nugget and leave. Barely a thumbs up. It’s ok I’m glad to share what I know and I enjoy doing it.
This LoRa project is by far the most complex. 400m is doable. It will go huge distances if you can see the other end. I have two more of those little LoRa modules for another project. Monitoring a starter battery on a community gas Barbie.
I can see hills in a state forest near my house. I’m tempted to do a ping test. I reckon one is about 5km away and the other about 15km. The hard part will be explaining to the wife where I’m going and why :cowboy_hat_face:. Not even sure if there any roads / tracks around there.
Remember these things are also able to talk to a LoRa wan router and therefore gain access to the Internet of things. Not something I have played with yet. I’m just using them peer to peer. Last time I priced a LoRa Wan router it was about $500. If you bought one you would still have to position the remote devices within range of it. The idea being that you share the routers so anyone in range can use it. There are maps around where you can find publicly available LoRa wan routers. Not that popular in Australia yet.
For my little project the next big challenge will be for devices to share messages with each other like a mesh, or Dynamic Routing if you like.
David

2 Likes

Hey David,

I like the Project and love the idea of what you are looking to do to improve it. As @Michael mentioned, we are big into the Meshtastic network currently and I have been doing some testing myself as a personal project. If you are looking at introducing a mesh network or you are looking at longer ranges, Meshtastic is the ultimate experience. The range record at this point for peer to peer communication is 254km currently and with the addition of nodes, you can get some incredible distances even around obstacles.

Currently we are using a mix of the LilyGo Lora T3S3 as a handheld device and a Pico supported setup with the Waveshare Lora Module for Pico which is reasonably cost effective ($33.40) for setting up repeater nodes. I am specifically trying to figure out a repeater setup that is solar powered to sit on a chosen site basically indefinitely.

Currently Meshtastic is still in development, though its got an incredible use case with the way that it is going. It is definitely a rabbit hole though, so make sure you have some time set aside for the deep dive that is inevitable with something like this.

Cheers,
Blayden

1 Like

Hi Blayden,

Wow that sounds amazing. I’m guessing there were some exceptional conditions to manage 254Km.

I’ll certainly check them out if I find the need for another project in this area.

David

1 Like

Hey David,

Looks like it was across the Canadian/United States border to reach that far, with one Transceiver at the top of a mountain range, so a pretty great condition for line of site. In practical use cases though, its possible to reach some insane distances as long as line of sight is present and with a 7 hop limit currently, this can be used to make a pretty incredible communication protocol.

Would love to see it used more widely as we have all seen a pretty incredible use case for it for a bunch of different project types.

Cheers,
Blayden

Hi Blayden

It is a bit surprising actually. The best place I know for this would be Mt Kaputar, West of Narrabri. In the Kaputar National Park. This point is 4900’ ASL (I will use feet here as it is easier) and Narrabri is 600’ASL so if we can assume the plains to the west maintain somewhere near that altitude the Radio Horizon (using 4/3 earth curvature) is only about 93Miles or 148kM. somewhat closer that one might imagine. So at 254 kM you would need a pretty high structure or another mountain to get a decent altitude ASL for anything “Line of Sight”. The free space attenuation at 93Mi and 1GHz is about 136db which you would need a bit of radiated power to achieve any sort of decent signal. All of this does not consider freznel clearance which makes things a little bit worse.

Of course a lot depends on what level signal and fading conditions you can tolerate. What is OK for one application might be impossible for another.
Cheers Bob

If you want to check for line of site try this

https://www.scadacore.com/tools/rf-path/rf-line-of-sight/

I’ve been using it to see what I can do from the top of the hill on my property. Dunno of it allows for curvature though, so far I just want comms in my immediate area so I’ve not looked into that.

1 Like