A program that turns any normal fan into a smart fan which automatically turns on/off based on the temperature of the current environment.
- Raspberry Pi
- DHT11/DHT22 Temperature Sensor
- Note, you must have the DHT output pin in PIN 4 in the Raspberry Pi board
- TP-Link Smart Plug that is compatible with python-kasa
- If you use a TP-Link Smart Plug that is not in the link above, you may have some features missing
- DHT11/DHT22 Temperature Sensor driver
pip3 install adafruit-circuitpython-dht
- Kasa Smart TP-Link HS100 driver
pip install python-kasa --pre
To run the program we need to run the following bash script located in the src directory:
#!/bin/bash
# Script to run the smart fan python script
# Will take an argument $1 and pass it to the python script
SF_PATH = '~/Documents/SmartFan/smart_fan.py'
python3 $SF_PATH "$1"
To run this script in the terminal we enter the following command:
./smart_fan.sh <args>
where <args> is the temperature in Fahrenheit where the fan will turn on. If there is no parameter passed, then the default temperature threshold will be set to 80 degrees Fahrenheit.
You could replace ~/Documents/SmartFan/smart_fan.py
to a directory where the python script is located.
You must change the executable permission to run the script in your Raspberry Pi. To do this we enter the following command in the terminal:
chmod 755 smart_fan.sh
- Make a bin directory in your home directory
mkdir bin
- Copy the shell script in the bin directory
cp ~/Documents/SmartFan/src/smart_fan.sh ~/bin/
- [Optional] Remove
.sh
to run script assmart_fan
like the ssh example belowmv ~/bin/smart_fan.sh ~/bin/smart_fan
Instead of having to directly connect to your Raspberry Pi, you could remote connect and run the script with your personal computer. Just make sure you look up what is the address of your Raspberry Pi.
For more Raspberry Pi Remote access click here
To stop the program we simply need to use a keyboard interrupt which is ctrl + c
TP Link Smart WiFI Plug drivers
Adafruit DHT22 Temperature and Humidity drivers
This section is a more technical overview of what the program is capable of and describes the design and implementation steps that occurred for this project.
We created a program automatically turns on and off a typical fan based on the temperature.
The fan is connected to a WiFi enabled plug which is controlled by a Raspberry Pi.
The Raspberry Pi has a temperature sensor connected to the board and will automatically turn on the fan when a certain
temperature is reached. When the temperature drops below a certain temperature, the fan is turned off by the
Raspberry Pi. The temperature limit that turns on the fan is entered by the user.
Above is a high level overview of our design of the automatic fan.
The Raspberry Pi is what connects all of our components together and allows them to work with each other.
The temperature sensor we used connects directly to the Raspberry Pi and allows for easy access to temperature data we
need. Next, we needed our Raspberry Pi to be able to turn the fan on and off.
To accomplish this, we used a WiFi enabled plug to connect the fan to an outlet.
The Raspberry Pi is able to communicate with the plug via WiFi as long as they are on the same network.
We decided to use ssh via terminal in order to send and receive data from the Raspberry Pi and this terminal window
acted as our display.
In the process of implementing our Automated Smart Fan, we needed to accomplish several tasks:
- Set up the Raspberry Pi
- Install the necessary drivers
- Install temperature sensor(DHT22) drivers
- Install SmartPlug(Kasa Smart TP-Link HS100) drivers
- Implement Python code to control our device
- The Python script job is to:
- store a set temperature from the user
- display the current temperature every 5 seconds
- turn on the fan if the current temperature exceeds the set temperature
- The Python script job is to:
Testing for our project occurred throughout our implementation process. The first initial test was to see if the Raspberry Pi was set up properly. After installing the driver for the DHT22 temperature sensor, a simple test was performed to see if the temperature was being read properly and if the sensor was correctly attached to the raspberry pi. Another test was done to see if we could control the WiFi plug from the Raspberry Pi after installing the driver for the TP-link HS100 WiFi smart plug. This was to ensure that both the WiFi plug and Raspberry Pi were connected to the same network. After these tests succeeded, it was time to test the Python script to ensure it was working as intended.
- Amiel Nava: Design, Implementation, and README
- Jeremy Epinosa: Design and README/Documentation
- Kenny Nguyen: Testing and Implementation
- DHT setup guide
- Kasa setup guide
- Raspberry Pi Remote access guide