Saturday, April 27, 2024
HomePythonCreate an Intermittent Fan Controller With Python

Create an Intermittent Fan Controller With Python


This could possibly be you! Click on right here to submit an summary for our Maker Weblog Sequence.


Background

I merely can not sleep with a fan continually blowing on me. My husband cannot sleep with out a fan on him. Initially, I believed we might by no means be capable of discover a completely happy medium, since ceiling followers are designed to be both on or off all night time. I spotted that if I might discover a technique to flip our fan off after 5 minutes after which again on after one other 20 minutes, we’d each be capable of sleep nicely. So, I constructed an adjustable, intermittent fan controller with roughly $30 price of electronics and two Python scripts.

This mission makes use of a Raspberry Pi Zero, a low-pass filter, and about 20 cm of wire to manage a ceiling fan. As well as, a {custom} Python Flask utility permits you to set how lengthy the fan stays on or off. The benefit of an intermittent fan is that it helps stop the room from getting stuffy, with out blowing a lot air that you just get chilly.

Screen Shot 2022 09 26 at 10 41 45 AM

(Left) Flask app for the Raspberry Pi Zero intermittent fan controller. (Proper) Raspberry Pi Zero intermittent fan controller.

WARNING: It would blow your thoughts to appreciate {that a} general-purpose enter/output (GPIO) pin, when toggled from excessive to low actually quick, can create radio frequencies (RF). These RF alerts can in flip be used to energy your fan with out utilizing its distant. Observe that IT IS ILLEGAL to transmit at many frequencies. You will need to use a low-pass filter (a 433MHz low-pass filter will preserve you authorized).

Setup

A Python Flask app served on the Raspberry Pi Zero will probably be used to configure how lengthy the fan stays on/off and to set the fan’s pace. Flask is a Python internet framework that allows the consumer to simply develop internet apps with minimal setup.

Serving a Flask app is so simple as typing python app.py in a terminal. On this internet app, button presses set off an async command on the Raspberry Pi Zero. This command sends an on-off keying (OOK) sign on the fan’s receiving frequency through rpiTX, which turns a GPIO pin 7 on/off. This technique of turning the GPIO pin on/off is what generates the RF sign. The 20 cm of wire acts as an antenna, so the sign can attain the fan’s receiver.

Radio Frequency Instructions

The OOK sign is transmitted at a principal frequency. You will need to work out the frequency at which the fan’s distant controller transmits, and the way that OOK sign is encoded. The 2 principal methods to determine what frequency a distant makes use of is to both measure it or learn the handbook. An affordable technique to measure it’s to make use of a USB TV tuner as demonstrated within the “Hack My Ceiling Fan Radio Sign with a $15 USB TV Tuner” YouTube video. Or, consult with the FCC web site. All transmitters should report what frequency they use. Mine makes use of 304MHz (FCC ID: KUJCE1000)—I measured 304.2MHz, which is shut sufficient. There may be variation from distant to distant; I’ve three Minka Aire remotes, and a few function at the next or decrease frequency than acknowledged on the FCC web site.

Screen Shot 2022 09 26 at 10 42 10 AM

Minka Aire distant: bottom

To determine how the RF sign is encoded, you’ll be able to measure it with a USB TV tuner (see under) or consult with this River’s Academic Channel YouTube video. The desk under lists the OOK codes for Minka Aire followers.

OOK Codes for Minka Aire Followers

Motion

Code

Mild: On

01010

Mild: Off

10010

Fan: Low

00100

Fan: Med

01000

Fan: Excessive

10000

Fan: Off

10100

Fan: Reverse

00010

Fan Distinctive ID

Most remotes have toggle switches on the again, close to the battery. The Minka Aire has two units of 4 toggle switches (eight digits) which might be used to set its distinctive ID, the place up = 1 and down = 0.

Placing It All Collectively

Software program Configurations for the Raspberry Pi Zero

  • Obtain this repo onto your Raspberry Pi Zero.

  • Obtain rpiTX and place it within the ./src folder.

  • Configure the Raspberry Pi Zero to activate its GPIO pins.

  • Join your Raspberry Pi Zero to your Wi-Fi community.
    • To seek out the IP tackle, kind in bash terminal: hostname -I.
  • Replace your library:
  • Set the fan’s distinctive ID within the FanRemote class positioned in fan_controller.py.

{Hardware} Configuration

  • Solder ~20 cm of wire to 1 finish of a 433MHz low move filter.

  • Solder two jumper cables to the opposite finish of the filter: one to the info line and the opposite one to floor. The info line goes to the middle pin.

  • Join the sign/knowledge line to GPIO pin 7 and the bottom line to the Raspberry Pi Zero’s electrical floor.

Components

  • 433MHz low-pass filter ($5.50)

  • ~20 cm of wire

  • Raspberry Pi Zero (~ $25)

  • SD card ($10)

  • good to have USB TV Tuner (~ $30)

Run the Flask App

The Flask app has three principal elements: app.py, index.html, and fan.css. The app.py file is the Python script that serves the Flask app and responds when a consumer presses a button within the internet app. The net app consists of index.html and fan.css information. The fan.css file makes the app look fairly and was modeled after the css file in ESP32_IR Distant repository.

To run the app, go to the ./src folder and kind in a terminal:

python3 app/app.py

It will initialize a Flask app on the Raspberry Pi Zero’s IP tackle on port 5000. Mine was at http://192.168.2.80:5000.

The Flask app imports a fan class into the appliance. When a consumer presses a button within the app, the primary methodology within the Flask app figures out the right way to reply and sends an async command to the fan.

WARNING: Once more, IT IS ILLEGAL to transmit at many frequencies. You will need to use a low-pass filter (a 433MHz low-pass filter will preserve you authorized).

Bonus Materials: Measuring the RF Command

Screen Shot 2022 09 26 at 10 42 39 AM

(Left) Official distant with Raspberry Pi Zero distant. (Proper) First sign is from urgent a button on the distant, and second sign is from the Raspberry Pi Zero. The width distinction attributable to the “official” distant repeating the sign.

Utilizing the USB TV tuner and Common Radio Hacker (URH) software program,* I used to be capable of seize the uncooked RF sign. The fan makes use of OOK and every bit is distributed as 100 or 101: 1 = 101 and 0 = 100. The fan is anticipating a sign at 304MHz, the place the primary eight bits are the fan’s ID and the subsequent 5 are the fan distant command.

*Observe: If you happen to do wish to play with a USB TV tuner and URH software program, I like to recommend making a conda surroundings and putting in the URH inside it. I additionally advocate putting in miniconda on the Raspberry Pi Zero because it has a small processor.

By recording the sign when every button is pressed on the fan’s distant, you’ll be able to then analyze every sign. It will allow you to construct out an OOK codes desk such because the one above. Observe that completely different remotes might use completely different frequencies and encodings.

Screen Shot 2022 09 26 at 10 43 05 AM

RF interpretation

Screen Shot 2022 09 26 at 10 43 27 AM

RF evaluation

There you’ve gotten it! You may create your individual custom-defined distant controller utilizing a Raspberry Pi Zero, some Python code, and a little bit of wire. Observe that in case you are new to working with {hardware} and RF there generally is a steep studying curve. Don’t fear for those who can’t get the mission to work the primary and even the hundredth time; these items take observe.


Evelyn Boettcher based and leads DiDacTex, LLC (a small woman-owned enterprise). Her expertise spans over 20 years within the discipline of electro-optics and distant sensing, with working expertise with electronics, modeling, and algorithm improvement. She obtained an MS in physics from the College of Maryland and a BS in physics from the College of Florida. She has been head writer in revered peer-reviewed journals, introduced findings at worldwide and nationwide conferences, and obtained patents for electro-optical units (# 6,738,536 #; 6,944,372). She enjoys supporting STEM actions for youth in her private time.

Anaconda is amplifying the voices of a few of its most lively and cherished neighborhood members in a month-to-month weblog sequence. If you happen to’re a Maker who has been in search of an opportunity to inform your story, elaborate on a favourite mission, educate your friends, and construct your private model, think about submitting an summary. For extra particulars and to entry a wealth of instructional knowledge science assets and dialogue threads, go to Anaconda Nucleus.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments