433Mhz remote gate opener with Raspberry Pi



  • I say "gate opener" because that's what I use it for but the process should work for most domestic devices controlled by RF in the ISM band.

    Note of caution: Please do check the legality of transmitting on the ISM (Industrial, Scientific, Medical https://en.wikipedia.org/wiki/ISM_radio_band) - commonly known as "433" - bands in your country before venturing off into the murky world of radio transmission. There will be legal controls on output power at the very least, although that's not going to be a problem with the tiny wattage the Pi can generate without amplification and some antenna engineering.

    The goal

    I have a gate at the end of the drive (sounds much grander than it is) which is electrically opened and closed and is triggered via a run-of-the-mill RF keyfob operating around 433Mhz (433.92 to be precise). I wanted to be able to open the gate not just electronically, but in a way which allowed me to control it programatically - once I could trigger it by running a script, the world would be my oyster - I am currently adding ANPR (ALPR for US residents I believe) to the system using a small camera on the gate which will allow me, with some clumsy Python wrestling, to open the gate when one of our cars approaches, automatically. I have lots of other things planned like parcel recognition (Amazon helpfully drop parcels over the gate so that when it opens it crushes them...) and even making sure the gate doesn't open when the dogs are in the driveway - again using open source image recognition on the Pi.

    Where was I? Oh - yes:

    The goal was to open the gate via a 433Mhz radio transmission from a Raspberry Pi.

    The solution

    Luckily, as is often the case in the wonderful open source community, much of the work had been done for me - in fact the majority of the difficult bits. Central to the whole thing is the wonderful RPITX project (https://github.com/F5OEO/rpitx) by Evariste Courjaud.

    RPITX brings with it a wealth of handy RF tools - and you really don't need anything else, software wise, to complete this project. However, if you're interested in going a little deeper I would suggest checking out RTL-433 (https://github.com/merbanan/rtl_433) and if you get really obsessed, like I did, then the HackRF One is the Rolls-Royce of (vaguely affordable) tools (https://greatscottgadgets.com/hackrf/one/).

    The requirements for this project, though, are simple. You need a Raspberry Pi (2 onwards, or a Zero /W) and a cheap RTL-SDR dongle. Oh and a small length of wire to form an antenna.

    The RTL-SDR dongle I used is this one https://www.amazon.co.uk/Nooelec-NESDR-SMArt-SDR-R820T2-Based/dp/B01HA642SW/ref=pd_sbs_4/260-0177488-6401721?pd_rd_w=Cv1vi&pf_rd_p=a3a7088f-4aec-4dbd-97cc-9a059581fe7b&pf_rd_r=A9S6GRN27R83HP0ZZQP9&pd_rd_r=0bf5d82c-3f75-473c-a222-67709a9169e9&pd_rd_wg=jKFDX&pd_rd_i=B01HA642SW&psc=1 but there are dozens to choose from. The whole story of RTL-SDR is fascinating, and I won't go into it here, but there are thousands of amazing projects based on the fact that the original Realtek DVB-TV chipset and driver was easily hackable to receive more than TV transmissions. Lots and lots of information here: https://www.rtl-sdr.com/

    The steps

    Install and update the Rpi OS - I used RaspiOS light but all versions will work. Go here https://thepi.io/how-to-install-raspbian-on-the-raspberry-pi/ if you're unfamiliar with the Pi to get detailed instructions on creating and updating an OS image for it.

    Using the guide on the RPITX Github site (as above), install RPITX. This has been made super easy by the author of RPITX by way of a Python PIP installation which also handles all dependencies.

    Still referring to the excellent instructions on the RPITX site, test your installation and then use the rtlmenu.sh script to record the signal from the 433Mhz remote control you wish to clone. Test it worked by using the play function of rtlmenu.sh to replay the file (recorded in .iq format) you just captured and whatever your remote control was supposed to do when you pressed the button, your Pi should now have intiated! (of course, make sure you take the Pi within range of the thing you're trying to control!)

    If everything worked, you now have a capture of the signal you need to transmit (saved by default as record.iq on your Pi in the RPITX folder).

    In order to transmit the file outside of the rtlmenu.sh script, we need to find out how rtlmenu.sh is achieving this - which is simple enough by examining the sh script with cat or the editor of your choice.

    Under the hood, rtlmenu.sh is using the sendiq function, as you will see when you examine rtlmenu.sh.

    sendiq is well documented and has a good --help function. You'll see that many parameters can be changed such as transmit frequency, sample rate, gain etc. However - if just using the "play" function from rtlmenu.sh worked for you, then you can leave the settings for the sendiq command as they are in the rtlmenu.sh script. Create your own sh script by copying the sendiq command from rtlmenu.sh. In my case, I ended up with a shell script called gate.sh (imaginative I know) which looks like this:

    sudo /usr/bin/sendiq -s 250000 -f 433920000 e6 -t u8 -i /home/pi/rpitx/gate.iq >/dev/null 2>/dev/null &

    You'll note that I also copied the default record.iq file from RPITX to a new file called gate.iq for convenience. Quick note here - if you want to examine the IQ file, Audacity (https://www.audacityteam.org/download/) can open it (import it as raw format), and for even more fun, use the amazing Universal Radio Hacker (URH) from Dr. Johannes Pohl, available from here https://github.com/jopohl/urh - if I were to describe all the stuff you can do with URH this would be a very long article - but it's an amazing project and worth checking out for more fun stuff to do with your RTL-SDR dongle.

    OK, so, now we have a standalone script (gate.sh) which when executed, will transmit the IQ file we recorded with rtlmenu.sh. We can open our gate / do our other random 433 remote thing by running a script! Which means we're at the point where TRIGGERcmd comes in:

    Now, I could just use a home-made website (which would be awful to look at in my case), to execute the script when I pressed a button on a webpage, but finding TRIGGERcmd was a Godsend for me because it allows me to link to IFTTT without having to mess around with webhooks etc. One of the main things it has enabled, and with minimal fuss, is the creation of an Alexa skill to open the gate when I say, you guessed it, "Alexa, open the gate"... Of course you will have your own ideas and requirements for automation and integration, I've mentioned some of my work in progress on this front above, but being able to trigger my gate.sh file remotely via TRIGGERcmd opens up a world of possibilities for me.

    I was new to TRIGGERcmd and stumbled over a couple of issues which familiarity would no doubt have helped me avoid (also thanks very much to @Russ for his help!). FWIW, however, my stumbling blocks were fixed by:

    • running the command as "background", and reflecting as such in my commands.json file

    • making sure to use the full path to the sendiq binary (as reflected in my final script above)

    Other than that, it was pretty plain sailing. The entry for the gate.sh command looks like this in my commands.json file:

    {"trigger":"Open Gate","command":"sh /root/gate.sh","ground":"background","voice":"Open Gate","allowParams": "false"},

    I'm very much an RF novice but I've been spending a lot of time digging around in radio related acronyms these last few weeks and doing a LOT of reading (it's a whole new world to me - and it's a big world!) - so if I can help with your project I certainly will.



  • @Wholepunch dude I love your ideas.



  • @Russ Thanks :-) Not all of them come to fruition, but hey.. that's all part of the fun, right? TRIGGERcmd is really helping me out here, so thank you.



  • @Wholepunch, you're welcome. Thank you for the post.


Log in to reply