Arduino Based Automatic Fan Speed controller using LM35 temperature sensor

Thread Starter

OCJ Authentic

Joined Apr 30, 2023
This project is a temperature monitoring and fan control system. It uses an LM35 temperature sensor to measure the ambient temperature, and an Arduino microcontroller to read the sensor data and control three 12V fans. The system has three LEDs that light up in different colors depending on the temperature, and a buzzer that sounds an alarm if the temperature goes above a certain threshold. The system is powered by a 12V power supply for the fans, and a separate power source for the Arduino. The LCD screen displays the current temperature in Celsius. The fan speed is controlled using a Pulse-Width Modulation (PWM) signal generated by the Arduino, which varies the duty cycle of the signal to adjust the fan speed. Overall, this project is a simple and effective way to monitor temperature and control fan speed in a given environment.

Materials Used:

  • Arduino board
  • LM35 temperature sensor
  • Three 12V fans
  • 12V power supply
  • Red, yellow, and green LEDs
  • Buzzer
  • Jumper wires
  • Breadboard or PCB board
  • Resistors (if needed for LEDs or other components)
  • Liquid crystal display (LCD) screen
  • I2C interface module for the LCD screen (if using an I2C LCD)
  • IN4007 diode
  • 10uF Capacitor
  • 2222A Transistor


The setup for the fan only power one fan instead of the 3x 12v fan and I use a 12 power supply cord to power it. What should I do in order to power up the 3 fans.


Thread Starter

OCJ Authentic

Joined Apr 30, 2023
Mod: please use Code quotes, under Inset Menu.

const int LM35_PIN = A0; // LM35 temperature sensor pin

const float VOLTAGE_REFERENCE = 5.0; // voltage reference for analog input

const float TEMP_COEFFICIENT = 100.0; // 10 mV per degree Celsius

int fan1Pin = 3;  // Pin for fan 1

int fan2Pin = 5;  // Pin for fan 2

int fan3Pin = 6;  // Pin for fan 3

#define RED_LED 11    // red LED pin

#define YELLOW_LED 12 // yellow LED pin

#define GREEN_LED 13  // green LED pin

#define BUZZER 9      // buzzer pin

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // set up LCD screen

void setup() {


  pinMode(RED_LED, OUTPUT);



  pinMode(BUZZER, OUTPUT);

  pinMode(fan1Pin, OUTPUT);

  pinMode(fan2Pin, OUTPUT);

  pinMode(fan3Pin, OUTPUT);

  lcd.init(); // initialize LCD screen

  lcd.backlight(); // turn on backlight

  lcd.clear(); // clear screen


void loop() {

  int sensorValue = analogRead(LM35_PIN); // read voltage from LM35

  float voltage = (sensorValue * VOLTAGE_REFERENCE) / 1024.0; // convert to voltage

  float temperature = voltage * TEMP_COEFFICIENT; // convert to temperature

  Serial.print("Temperature: ");


  Serial.println(" °C");

  lcd.setCursor(0, 0);

  lcd.print("Temp: ");


  lcd.print(" C");

  if (temperature >= 70.0) {

    digitalWrite(RED_LED, HIGH);   // turn on red LED

    digitalWrite(YELLOW_LED, LOW);

    digitalWrite(GREEN_LED, LOW);

    tone(BUZZER, 1000);            // turn on buzzer

    analogWrite(fan1Pin, 255);     // set fan 1 speed to maximum

    analogWrite(fan2Pin, 255);     // set fan 2 speed to maximum

    analogWrite(fan3Pin, 255);     // set fan 3 speed to maximum

    lcd.setCursor(0, 1);           // set cursor to second row of LCD

    lcd.print("Fans: On ");         // display fan status on LCD

  } else if (temperature >= 50.0 && temperature < 70.0) {

    digitalWrite(YELLOW_LED, HIGH);   // turn on yellow LED

    digitalWrite(RED_LED, LOW);

    digitalWrite(GREEN_LED, LOW);

    noTone(BUZZER);                   // turn off buzzer

    analogWrite(fan1Pin, 128);        // set fan 1 speed to 50%

    analogWrite(fan2Pin, 128);        // set fan 2 speed to 50%

    analogWrite(fan3Pin, 128);        // set fan 3 speed to 50%

    lcd.setCursor(0, 1);

    lcd.print("Fans: On ");

  } else {

    digitalWrite(GREEN_LED, HIGH);   // turn on green LED

    digitalWrite(RED_LED, LOW);

    digitalWrite(YELLOW_LED, LOW);

    noTone(BUZZER); // turn off buzzer

    analogWrite(fan1Pin, 0); // turn off fan 1

    analogWrite(fan2Pin, 0); // turn off fan 2

    analogWrite(fan3Pin, 0); // turn off fan 3

    lcd.setCursor(0, 1);

    lcd.print("Fans: Off");


delay(1000); // wait for a second

Last edited by a moderator:


Joined Sep 9, 2010
Divide and conquer. Follow the logic all the way through. Verify the signals from the LM35, check the outputs from the Arduino. The fan not spinning could be a fault in the power circuit, or a because the Arduino is not telling it to spin. You need to diagnose which it is. It's impossible for us to guess from just your photos. As noted, a schematic would help.