Skip to content

4.1.4. Temperature Triggered Cooling Fan

Description Students build real-world experience in sensor bus integration, actuation logic, and fault-tolerant system design.
Use case This project connects to real-world industrial and IoT applications such as this project provides essential master-level engineering skills for real-world IoT, safety, and control systems.

Components (Things You will need)

Arduino Uno Arduino USB Cable Bread Board Jumper Wires RGB Module Resistor LED Servo Motor DC Motor Motor Driver Temperature Sensor Fan Blades

Building the circuit

Things Needed:

  • Arduino Uno = 1
  • Arduino USB cable = 1
  • Servo motor = 1
  • Jumper Wires
  • Temperature Sensor
  • DC Motor
  • Motor Drivers
  • Bread Board
  • RGB Module
  • Resistor
  • LED
  • Motor Driver
  • Fan Blades

Mounting the component on the breadboard and wiring the circuit

Step 1: Connect the DS18B20 Temperature Sensor

Connect the DATA pin of the DS18B20 temperature sensor to Digital Pin D2, the VCC pin to 5V, and the GND pin to GND using jumper wires. Connect a 4.7 kΩ pull-up resistor between the DATA pin and the 5V power supply.

Step 2: Connect the L298N Motor Driver

Connect IN1 to Digital Pin D8, IN2 to Digital Pin D9, and ENA to PWM Pin D10 on the Arduino Uno board using jumper wires. Then, connect the 5V pin of the L298N motor driver to 5V and the GND pin to GND.

Step 3: Connect the DC Motor

Connect the two terminals of the DC motor to the OUT1 and OUT2 output terminals of the L298N motor driver using jumper wires.

Step 4: Connect the RGB LED

Connect the Red, Green, and Blue pins of the RGB LED to PWM Pins D3, D5, and D6 through 220 Ω current-limiting resistors. Connect the common pin to GND if using a common-cathode RGB LED or to 5V if using a common-anode RGB LED.

Step 5: Perform a Final Check

Check all power, signal, and ground connections against the Circuit Connections table and wiring diagram. Ensure that all 5V connections are connected to the correct power supply and that all components share a common ground before powering the circuit.

Components on breadboard

Make sure to connect the Arduino USB cable to the Arduino board.

PROGRAMMING

Step 1: Open your Arduino IDE. See how to set up here: Getting Started.

Step 2: Write the complete program implementing the system logic with appropriate pin definitions, setup configuration, and the main control loop.


#include <OneWire.h>
#include <DallasTemperature.h>

// ---------------- Pin Definitions ----------------
#define ONE_WIRE_BUS 2

const int ENA = 10;
const int IN1 = 8;
const int IN2 = 9;

const int RED_LED = 3;
const int GREEN_LED = 5;
const int BLUE_LED = 6;

// ---------------- Temperature Sensor ----------------
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// Temperature Threshold
const float TEMP_THRESHOLD = 30.0;

void setup()
{
  Serial.begin(9600);

  sensors.begin();

  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(BLUE_LED, OUTPUT);

  stopMotor();
  setLED(0,255,0);

  Serial.println("Project 65: Temperature-Triggered Cooling Fan");
  Serial.println("--------------------------------------------");
}

void loop()
{
  sensors.requestTemperatures();

  float temperature = sensors.getTempCByIndex(0);

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  if(temperature >= TEMP_THRESHOLD)
  {
      runMotor();

      // Red LED
      setLED(255,0,0);

      Serial.println("Cooling Fan ON");
  }
  else
  {
      stopMotor();

      // Green LED
      setLED(0,255,0);

      Serial.println("Cooling Fan OFF");
  }

  delay(1000);
}

//---------------- Functions ----------------//

void runMotor()
{
    digitalWrite(IN1,HIGH);
    digitalWrite(IN2,LOW);
    analogWrite(ENA,255);
}

void stopMotor()
{
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,LOW);
    analogWrite(ENA,0);
}

void setLED(int red,int green,int blue)
{
    analogWrite(RED_LED,red);
    analogWrite(GREEN_LED,green);
    analogWrite(BLUE_LED,blue);
}

Step 3: Save your code. See the Getting Started section

Step 4: Select the arduino board and port See the Getting Started section:Selecting Arduino Board Type and Uploading your code.

Step 5: Upload your code. See the Getting Started section:Selecting Arduino Board Type and Uploading your code

CONCLUSION

The system responds dynamically when physical conditions cross pre-programmed setpoints, driving output devices reliably.