Questions And Answers

More Tutorials

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.


In this page (written and validated by ) you learned about Raspberry Temperature Sensing Intelligent Fan . What's Next? If you are interested in completing Raspberry tutorial, your next topic will be learning about: Raspberry Intelligent Light.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.