Abusing Raspberry Pi GPIO pins as a radio transmitter to control my ceiling fan

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Previously, in part 1 of this project, I showed  how I used a cheap USB TV tuner to eavesdrop   on and decode my ceiling fan’s wireless  commands. Now that I have that knowledge,   part 2 is all about sending those  same commands using a Raspberry Pi.   This isn’t just plugging some  expensive radio into the Pi.   The Pi itself, believe it or not, can transmit  radio signals on a huge range of frequencies. Obviously it has a radio for Wi-Fi and Bluetooth,  but that’s way off from the frequency I need to   transmit. What it also has that most computers  don’t have are GPIO pins that you can easily   control. If we can toggle one of these GPIO  pins back-and-forth between zero and one,   we generate electromagnetic  radiation in the form of radio waves. Luckily for us, there already is a  tool to do this on the Raspberry Pi.   It’s called rpitx, and you can find it on Github.   It can generate all sorts of radio signals in  a huge frequency range using GPIO pin number 4. This works without us connecting  anything to the pin at all, because   a wire that’s disconnected on one end  can still have current and voltage.   This disconnected pin is basically  an antenna - a very small antenna. It’s actually a little too small, because the  radio signal only goes about 10cm. I want to   control my ceiling fan, but I’m not going to  tape the Pi to my ceiling to make it happen.   However, if I connect a longer wire to  this pin, then I can extend the range. Here I’ve cut a length of  wire about 20cm long. Again,   it’s not connected to anything. If I transmit  using this, the signal can go tens of meters. A signal on a specific frequency  is like this - it’s a sine wave. [monotone hum] But with the Pi’s GPIO, we’re working with  binary data, ones and zeros. If we toggle   between one and zero at the same frequency,  we get a square wave instead of a sine wave. [rough monotone hum] In reality, it actually looks  more like this due to physics. If we compare the two, here’s the  difference. Isolating this difference,   it’s equivalent to more  sine waves stacked together. Basically, anything that’s not a sine wave is  some combination of sine waves at different   frequencies. That means transmitting our square  wave transmits on multiple frequencies at once. For a square wave, it’s very simple  to calculate these frequencies.   A square wave at, say, 100 MHz contains not only a  signal at 100 MHz, AKA the fundamental frequency,   but also at 3x the fundamental, 5x, 7x,  and so on. We call these the “harmonics.” So the bad news is that any time we try to  transmit on a specific frequency with the Pi,   we’re also simultaneously transmitting  on many other frequencies.   There are a lot of frequencies that are illegal  to transmit on without a license, for good reason.   You don’t want your cellphone to drop calls  because your neighbor’s using a remote control. The good news is that this is a  common and well-understood problem.   We can send our signal through what’s  called a low-pass filter, which blocks   signals above a certain frequency while letting  signals below that frequency pass through. They’re not complicated and it’s very  possible to build your own with the   right resistor and capacitor, but I was able  to find suitable filters on eBay for only 7   US dollars. Shipping was pretty slow, but  that’s the price you pay for cheap electronics. For aesthetics I’m adding in an antenna  and a connector for the other end, and   all this stuff adds up to about $15. Back to the software side. Rpitx comes  with a bunch of example programs,   one of which is exactly what we need. We know  that this remote uses on-off-keying - basically   morse code - and there just happens to  be an included program called “sendook”. We just need to tell sendook exactly what we want  to send, including frequency and timing, and … [keyboard typing] holy **** it worked That was proof that I can control my  ceiling fan and light with my Raspberry Pi.   I can even throw together a quick web page on my  Pi as proof that I can control it with my phone. The webserver simply runs the `sendook` program   with the right arguments whenever you  push one of the buttons on the page. [keyboard typing] At this point, it’s just a proof-of-concept  - in the future I’ll integrate this into Home   Assistant so that these controls are centralized  and integrated with all of the other smart-home   hardware in my house. If you’re using other  systems like Alexa, I’m sure there’s a way   to set up custom actions as well - they just  need to tell your Pi to run the right command. As always, I appreciate all of your comments  and likes! If you want to see more of my videos   on tech, automation, or whatever else  I find interesting, please subscribe.   Thanks for watching!
Info
Channel: River's Educational Channel
Views: 30,550
Rating: undefined out of 5
Keywords:
Id: 3lGU7PjJM7k
Channel Id: undefined
Length: 5min 0sec (300 seconds)
Published: Sun Mar 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.