Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Temperature-Based Fan Speed Control with LCD Display and LED Alert

Image of Arduino UNO Temperature-Based Fan Speed Control with LCD Display and LED Alert

Circuit Documentation

Summary

This circuit is a temperature-based fan speed control and monitoring system. It reads the temperature from an LM35 sensor and adjusts the speed of a fan accordingly. The temperature and fan speed are displayed on a 16x2 LCD. If the temperature exceeds a maximum threshold, an LED is turned on.

Component List

  1. 9V Battery

    • Description: Provides power to the circuit.
    • Pins: -, +
  2. Arduino UNO

    • Description: Microcontroller used to control the circuit.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  3. Diode

    • Description: Ensures current flows in one direction.
    • Pins: cathode, anode
  4. 40 Fan 12v

    • Description: Fan used to cool the system.
    • Pins: +12V, -12V
  5. 16X2 LCD

    • Description: Displays temperature and fan speed.
    • Pins: VSS, VDD, V0, RS, RW, E, D1, D0, D2, D3, D4, D6, D5, D7, A, K
  6. Resistor (1k Ohms)

    • Description: Limits current in the circuit.
    • Pins: pin1, pin2
  7. Electrolytic Capacitor (10uF)

    • Description: Stores electrical energy.
    • Pins: -, +
  8. LED: Two Pin (red)

    • Description: Indicates when the temperature exceeds the maximum threshold.
    • Pins: cathode, anode
  9. NPN Transistor (EBC)

    • Description: Amplifies current.
    • Pins: emitter, base, collector
  10. Temperature Sensor (LM35)

    • Description: Measures temperature.
    • Pins: +Vs, Vout, GND

Wiring Details

9V Battery

  • -: Connected to GND of Arduino UNO, VSS, K, V0, RW of 16X2 LCD, anode of LED, GND of Temperature Sensor (LM35)
  • +: Connected to 5V of Arduino UNO, VDD, A of 16X2 LCD, +Vs of Temperature Sensor (LM35)

Arduino UNO

  • GND: Connected to - of 9V Battery, VSS, K, V0, RW of 16X2 LCD, anode of LED, GND of Temperature Sensor (LM35), emitter of NPN Transistor, - of Electrolytic Capacitor
  • 5V: Connected to + of 9V Battery, VDD, A of 16X2 LCD, +Vs of Temperature Sensor (LM35)
  • Vin: Not connected
  • A0: Connected to Vout of Temperature Sensor (LM35)
  • D11: Connected to pin1 of Resistor
  • D8: Connected to pin1 of Resistor
  • D7: Connected to D7 of 16X2 LCD
  • D6: Connected to D6 of 16X2 LCD
  • D5: Connected to D5 of 16X2 LCD
  • D4: Connected to D4 of 16X2 LCD
  • D3: Connected to E of 16X2 LCD
  • D2: Connected to RS of 16X2 LCD

Diode

  • cathode: Connected to +12V of 40 Fan 12v
  • anode: Connected to collector of NPN Transistor, -12V of 40 Fan 12v

40 Fan 12v

  • +12V: Connected to cathode of Diode
  • -12V: Connected to anode of Diode, collector of NPN Transistor

16X2 LCD

  • VSS: Connected to GND of Arduino UNO, - of 9V Battery
  • VDD: Connected to 5V of Arduino UNO, + of 9V Battery
  • V0: Connected to GND of Arduino UNO, - of 9V Battery
  • RS: Connected to D2 of Arduino UNO
  • RW: Connected to GND of Arduino UNO, - of 9V Battery
  • E: Connected to D3 of Arduino UNO
  • D4: Connected to D4 of Arduino UNO
  • D5: Connected to D5 of Arduino UNO
  • D6: Connected to D6 of Arduino UNO
  • D7: Connected to D7 of Arduino UNO
  • A: Connected to 5V of Arduino UNO, + of 9V Battery
  • K: Connected to GND of Arduino UNO, - of 9V Battery

Resistor (1k Ohms)

  • pin1: Connected to D11 of Arduino UNO, D8 of Arduino UNO
  • pin2: Connected to base of NPN Transistor, cathode of LED

Electrolytic Capacitor (10uF)

  • -: Connected to GND of Arduino UNO, emitter of NPN Transistor
  • +: Connected to base of NPN Transistor

LED: Two Pin (red)

  • cathode: Connected to pin2 of Resistor
  • anode: Connected to GND of Arduino UNO, - of 9V Battery

NPN Transistor (EBC)

  • emitter: Connected to GND of Arduino UNO, - of Electrolytic Capacitor
  • base: Connected to pin2 of Resistor, + of Electrolytic Capacitor
  • collector: Connected to anode of Diode, -12V of 40 Fan 12v

Temperature Sensor (LM35)

  • +Vs: Connected to 5V of Arduino UNO, + of 9V Battery
  • Vout: Connected to A0 of Arduino UNO
  • GND: Connected to GND of Arduino UNO, - of 9V Battery

Code Documentation

/*
 * Temperature Based Fan Speed Control & Monitoring
 * This code reads the temperature from an LM35 sensor and adjusts the speed of a
 * fan accordingly. It also displays the temperature and fan speed on a 16x2 LCD.
 * If the temperature exceeds a maximum threshold, an LED is turned on.
 */

#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int tempPin = A0; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int temp;
int tempMin = 30; // the temperature to start the fan 0%
int tempMax = 60; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;

void setup() {
  pinMode(fan, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(tempPin, INPUT);
  lcd.begin(16, 2);
  Serial.begin(9600);
}

void loop() {
  temp = readTemp(); // get the temperature
  Serial.print(temp);
  if (temp < tempMin) { // if temp is lower than minimum temp
    fanSpeed = 0; // fan is not spinning
    analogWrite(fan, fanSpeed);
    fanLCD = 0;
    digitalWrite(fan, LOW);
  } else if (temp <= tempMax) { // if temperature is higher than minimum temp
    fanSpeed = temp; // map temperature to PWM range
    fanSpeed = 1.5 * fanSpeed;
    fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
    analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
  } else { // if temp is higher than tempMax
    digitalWrite(led, HIGH); // turn on led
  }

  if (temp <= tempMax) {
    digitalWrite(led, LOW); // turn off led if temp is not higher than tempMax
  }

  lcd.print("TEMP: ");
  lcd.print(temp); // display the temperature
  lcd.print("C ");
  lcd.setCursor(0, 1); // move cursor to next line
  lcd.print("FANS: ");
  lcd.print(fanLCD); // display the fan speed
  lcd.print("%");
  delay(200);
  lcd.clear();
}

int readTemp() { // get the temperature and convert it to celsius
  temp = analogRead(tempPin);
  return temp * 0.48828125;
}