Arduino Projects

Temperature based fan speed controller using Arduino and LM35

Learn how to build an automatic fan speed adjusting controller using LM35 temperature sensor and Arduino.


In this quick tutorial, we are going to show how to make an automatic temperature based fan speed controller by interfacing LM35 temperature sensor with Arduino and monitor the real time temperature and fan speed data on 16X2 LCD display.

Working Principle:

In this example project, first we get the Realtime temperature values from the LM35 temperature sensor and according to those value we are going to adjust the speed of the fan. i.e., when the temperature is high the fan is going to spin at high speed and when the temperature is low, the fan will be stopped. The fan speed will directly proportional to the temperature observed on LM35 temperature sensor. when the temperature observed is more than the max temp a small 5mm LED will glow to indicate as max temp.

User can easily monitor the temperature values in Celsius and fan speed in percentage on the LCD display module connected with Arduino.

You can change the minimum and maximum temperature values in the code according to your requirement so the fan speed adjusts according to them.

Required Components

No’s  Component name
1 Arduino Uno
1 LM35 temperature sensor
1 16X2 LCD display module with I2C adapter
1 12V DC Fan
1 2N2222 NPN Transistor
1 1K ohm resistor
1 1N4007 Diode
1 10uF Electrolytic Capacitor
1 5mm LED
1 12V power supply
Few Connecting wires

Circuit Diagram

Interface all the required components according to the circuit diagram shown below.

Temperature based fan speed controller using Arduino circuit diagram

From the above Schematic diagram you can see the LM35 temperature sensor Signal pin is connected to Arduino to A0 of Arduino and Vin and GND are connected to 5V and GND respectively. LM35 gives analog output voltage which is proportional to temperature and operates for a range of temperatures between -55 to 150 degree Celsius.

A 16X2 I2c LCD display is connected to 5V and GND with Arduino 5V and GND and the I2c pins SDA and SCL of LCD module are connected to A4 and A5 respectively. If you want to connect the LCD display with out I2C refer the below article link.

12V DC fan is connected to pin 11 of Arduino,

Arduino is powered from the 12V external power supply may be from an adapter or a battery to VIN and GND of Arduino. Use the power supply according to the fan power consumption and Arduino consumption.

The 2N2222 NPN transistor acts as a controller switch which controls the speed of the fan by using the signal from the Arduino. The IN4007 Diode acts as a protection for the fan from being damaged.

When the temperature exceeds the max temp the 5mm LED light glows.

Working of the temperature based fan speed controller Circuit

LM35 temperature sensor senses the temperature and send the analog signal to Arduino, then Arduino converts the analog signal to digital signal and display the value on LCD display and calculate the percentage of speed the fan should be spinned.

The calculated percentage is sent to DC fan through the low frequency (PWM)pulse-width modulation signal which adjusts the fan speed by varying its Duty cycle. A cheap and compact 2N2222 or BD139 NPN transistor is used in this circuit as it is efficient because it is used as a switch.

Source code:

After connecting all the components according to the circuit diagram, next step is to upload the code to Arduino by connecting it to pc using an USB cable. Copy and paste the below code in Arduino IDE, Select the correct COM port and Arduino as board and upload the code.

After uploading the code the device works perfectly according to the working principle.

When the temperature is below 30 the fan is turned off and when temp is 60 the fan spins at full speed and when the temperature is above 60 5mm led light glows.


Temperature based fan speed controller using Arduino output

In the same way instead of using the Arduino you can use ESP8266, ESP32 microcontrollers, the only thing to modify is the circuit diagram and the pins in the code.


Air-conditioners, Water-heaters, Snow-melting machines, Ovens, Mixers, Furnaces, Incubators, thermal baths and more.

To build this project for your AC fan you need to interface with other components which we are going to explain in futher articles. stay tuned.

If you find this project helpful please share it with your friends, and if you have any doubts or got any issues regarding this project please feel free to comment below or ask us on Facebook community page “Circuit Schools“. Your interest makes us happy and help to add more projects. Thanks and happy creations.

CircuitSchools Staff

We at CircuitSchools publish on basics of electronics and electric components and everything related to evolution of electrical technology with complete analysis of development boards and modules along with latest projects with innovative ideas.

Related Articles

Leave a Reply

Back to top button