Controlling several MinkaAire ceiling fan/lights with a Raspberry Pi
MinkaAire remote
Disassembled the MinkaAire remove control. The buttons are effectively pushed when the two contacts are shorted by a springy contact. A relay will make the connection between the two contacts.
The remote is powered by a 12 V battery.
These is no feedback from the fan to the remote, so we can enable remote control functions but there is no direct way to know if the fan received and acted upon the command.
Picture of MinkaAire remote circuit board front
Picture of MinkaAire remote circuit board back
Picture of MinkaAire remote circuit board front with button pad
Relays
Using a 5V relay module similar to this one. The important fact to note is that the Vcc is common and the pins must be set to ground in order to activate the relay.
Raspberry Pi
Powered by 5V
Install useful tools and update raspbian
sudo apt update
sudo apt upgrade
sudo apt autoremove
sudo apt install screen
GPIO configuration
Using a Raspberry Pi 2. The python gpiozero library and pinouts are found here: https://gpiozero.readthedocs.io/en/stable/recipes.html
the pi itself can be powered off the 2 and 6 pins, instead of the micro usb port.
python configuration
Install ipython3 for testing
sudo apt install ipython3
using relays with gpiozero
https://gist.github.com/johnwargo/ea5edc8516b24e0658784ae116628277
Install and configure flask for server
Flask was already present as part of python3. Flask app must be run with sudo
Use GPIO with Flask
The code here creates a basic flask application that serves a ceiling fan remote control.
http://mattrichardson.com/Raspberry-Pi-Flask/
https://randomnerdtutorials.com/raspberry-pi-web-server-using-flask-to-control-gpios/
Flask with Multithreading
In addition to the simple remote control functions, we would like to be able to run programs with the fan. For example, cycle the fan on and off periodically, or have the lights come on add off using a schedule.
This scheduled programming should run in a separate thread on the Raspberry Pi from the Flask app so that they don’t block.
Here are some interesting resources:
https://github.com/johndavidsimmons/xmas_lights
mechanical drawing
Official Raspberry Pi drawings
Picture of Raspberry Pi 3B+ from Adafruit
Power supply
The MinkaAire remote wants 12V and the Rasperry Pi wants a 5V power supply. A PSU with a Molex connector will provide both. A molex to SATA adaptor provides a covenient breakout connector for both voltages.
- https://www.amazon.com/110v-Power-Supply-Molex-5000mA/dp/B002TJNDU4/ref=sr_1_3?dchild=1&keywords=molex+psu&qid=1593887918&s=electronics&sr=1-3
- https://en.wikipedia.org/wiki/Molex_connector
From Wikipedia these are the pinouts.
- Pin 1 Yellow +12 V
- Pin 2 Black Ground
- Pin 3 Black Ground
- Pin 4 Red +5 V
As measured, I get 12.3V and 5.1V
Prototype setup on desktop
Here’s a photo of the prototype setup on the work bench:
Related projects
https://www.youtube.com/watch?v=3lGU7PjJM7k&ab_channel=River%27sEducationalChannel https://www.youtube.com/watch?v=3lGU7PjJM7k&t=0s
References
there is a reddit thread here: https://www.reddit.com/r/raspberry_pi/comments/5pu96x/rf_remote_dip_switches/