Raspberry Temperature Sensing Intelligent Fan
The function of the fan is mainly to reduce the temperature, so we can use the temperature to control the fan on and off. Set a value that represents the maximum comfortable temperature. When the temperature detected is higher than this value, the fan will turn on, and off when the temperature drops below it. At the same time, the temperature value can be displayed on the LCD for monitoring.
Hardware Connection
In this project, the electronic hardware we need to use is as follows:
• Raspberry Pi Pico
• Grove Shield for Pi Pico
• Grove - Mini Fan
• Grove – Temperature & Humidity Sensor
• Grove - 16 x 2 LCD
Use a Grove data cable to connect the Temperature & Humidity Sensor to D16, connect the Mini Fan to D18, and connect the LCD to I2C1.
Write a Program
First of all, import the required libraries and set the pins of the temperature and humidity sensor, LCD and mini fan.
Next, read the value detected by the temperature and humidity sensor — here we only need to read the temperature value — and display the value on the LCD.
Finally, we judge the temperature value through the “if" conditional judgment statement, with 26 as the maximum comfortable value of temperature, and then use the comparison operator “>" to compare the current temperature with the set temperature. When the current temperature is higher than the set temperature, the fan turns on; otherwise, the fan turns off:
The complete program is as follows:
If you are using a DHT20 temperature and humidity sensor, refer to the following program:
Use a USB cable to connect Pico to the computer, and click the “run" button to save the program to any location. Now, you can see the actual running effect of the program.
In addition to controlling the fan through a button and temperature sensing, what other control methods can you think of? Give it a try.