Temperature-Activated Smart Fan Using DC Motor

by dmcits in Circuits > Sensors

6 Views, 0 Favorites, 0 Comments

Temperature-Activated Smart Fan Using DC Motor

Temperature-Activated Smart Fan .png

This project uses an Arduino Uno to monitor temperature via a TMP36 sensor. When the room temperature reaches or exceeds the set threshold, an LED lights up to signal that it’s too hot. At that point, if a button is pressed, a DC fan powers up gradually, then winds down — providing a manual cooling response based on environmental data.

This system simulates a smart cooling control system — useful in homes, server rooms, or greenhouses where automated, responsive environments are crucial.

Supplies

Arduino Uno

TMP36 Temperature Sensor

DC Motor (Fan)

TIP120 NPN Transistor

1N4001 Diode

LED

200Ω Resistor (for LED)

Pushbutton

10kΩ Resistor (for button)

9V Battery + Battery Clip or 9V DC Power Supply

Breadboard + Jumper Wires

Build Circuit

FYFDI7JMC2HRT1F.png

Step 1: Connect the TMP36 Temperature Sensor

  1. Insert the TMP36 sensor onto the breadboard with its flat side facing you.
  2. Left pin → Connect to 5V on the Arduino.
  3. Middle pin → Connect to A0 on the Arduino (analog input).
  4. Right pin → Connect to GND.

Step 2: Wire the Pushbutton

  1. Place the pushbutton across the central groove of the breadboard.
  2. Connect one side of the button to digital pin 2 on the Arduino.
  3. Connect the same side to GND through a 10kΩ pull-down resistor.
  4. Connect the other side of the button to 5V.

This ensures a stable LOW reading when the button is not pressed.

Step 3: Connect the Status LED

  1. Place an LED on the breadboard.
  2. Anode (long leg) → Connect to pin 13 on the Arduino through a 200Ω resistor.
  3. Cathode (short leg) → Connect to GND.

Step 4: Set Up the DC Fan Motor with TIP120 Transistor

  1. Insert the TIP120 NPN transistor onto the breadboard.
  2. TIP120 pinout (flat side facing you):
  3. Left pin = Base
  4. Middle pin = Collector
  5. Right pin = Emitter

Motor Connections:

  1. Connect one lead of the motor to the 9V battery positive terminal.
  2. Connect the other motor lead to the collector (middle pin) of the TIP120.

TIP120 Control:

  1. Connect the emitter (right pin) of the TIP120 to GND.
  2. Connect the base (left pin) of the TIP120 to digital pin 9 on the Arduino.

Step 5: Add a Flyback Diode for Motor Protection

  1. Place the 1N4001 diode across the motor terminals.
  2. Stripe (cathode) → Connect to the positive motor lead (battery side).
  3. Non-striped end (anode) → Connect to the TIP120/motor side.

This protects the transistor from voltage spikes caused by the motor.


Step 6: Connect External Power (9V Battery)

  1. Connect the positive terminal of the 9V battery to the motor (already done in Step 4).
  2. Connect the negative terminal of the battery to the Arduino GND (shared ground).


Final Check Before Uploading Code

Make sure:

  1. All GNDs are connected (Arduino, TMP36, TIP120 emitter, button resistor, and LED).
  2. The TMP36 is not reversed (double-check the flat face and pin layout).
  3. The TIP120 is controlling the fan — don’t wire the motor directly to the Arduino.
  4. The 9V battery powers the motor (not the Arduino — unless using a barrel jack).


Upload Code + Breakdown

Code:

const int buttonPin = 2; // Button input
const int motorPin = 9; // Fan motor control
const int ledPin = 13; // LED for high temperature
const int tempPin = A0; // TMP36 sensor

void setup() {
pinMode(buttonPin, INPUT);
pinMode(motorPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(tempPin);
float voltage = sensorValue * (5.0 / 1023.0);
float temperatureC = (voltage - 0.5) * 100;
float temperatureF = (temperatureC * 9.0 / 5.0) + 32;

Serial.print("Temperature (F): ");
Serial.println(temperatureF);

if (temperatureF >= 85.0) {
digitalWrite(ledPin, HIGH);
if (digitalRead(buttonPin) == HIGH) {
for (int speed = 0; speed <= 50; speed++) {
analogWrite(motorPin, speed);
delay(50);
}
for (int speed = 50; speed >= 0; speed--) {
analogWrite(motorPin, speed);
delay(50);
}
}
} else {
digitalWrite(ledPin, LOW);
analogWrite(motorPin, 0);
}

delay(500);
}


Section-by-Section Breakdown


Variable Declarations

const int buttonPin = 2;
const int motorPin = 9;
const int ledPin = 13;
const int tempPin = A0;
  1. buttonPin: The pushbutton is connected to digital pin 2.
  2. motorPin: The motor (controlled via a TIP120 transistor) uses pin 9, which supports PWM.
  3. ledPin: The status LED for high temp is connected to pin 13.
  4. tempPin: The TMP36 sensor is connected to analog pin A0.

Setup Function

void setup() {
pinMode(buttonPin, INPUT);
pinMode(motorPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
  1. pinMode(): Defines pin roles.
  2. Button as input.
  3. Motor and LED as outputs.
  4. Serial.begin(9600);: Starts serial communication for debugging. You'll see temperature logs in the Serial Monitor.

Main Loop Function

int sensorValue = analogRead(tempPin);
  1. Reads analog voltage from TMP36. Value is between 0 and 1023.
float voltage = sensorValue * (5.0 / 1023.0);
  1. Converts the analog value to actual voltage.
  2. 5.0V is the Arduino reference voltage.
float temperatureC = (voltage - 0.5) * 100;
  1. Converts the TMP36 voltage to Celsius.
  2. TMP36 outputs 0.5V at 0°C, and every 0.01V = 1°C.
float temperatureF = (temperatureC * 9.0 / 5.0) + 32;
  1. Converts Celsius to Fahrenheit.

Display Temperature

Serial.print("Temperature (F): ");
Serial.println(temperatureF);
  1. Prints the temperature to the Serial Monitor for debugging or monitoring.

Check Temperature Condition

if (temperatureF >= 85.0) {
  1. If it’s 85°F or hotter, the system gets ready to cool.
digitalWrite(ledPin, HIGH);
  1. Turns on the LED to signal high temperature.

Check Button Press

if (digitalRead(buttonPin) == HIGH) {
  1. If the button is pressed, we start the cooling cycle.

Ramp Up the Fan

for (int speed = 0; speed <= 50; speed++) {
analogWrite(motorPin, speed);
delay(50);
}
  1. Increases the PWM signal to the fan gradually.
  2. PWM value from 0 to 50 (out of 255) gives a gentle spin-up.
  3. Each increase pauses for 50ms to create a smooth ramp effect.

Ramp Down the Fan

for (int speed = 50; speed >= 0; speed--) {
analogWrite(motorPin, speed);
delay(50);
}
  1. Slows the fan back down smoothly.

Else Condition (Normal Temp)

} else {
digitalWrite(ledPin, LOW);
analogWrite(motorPin, 0);
}
  1. If it’s cooler than 85°F, the system:
  2. Turns off the LED
  3. Keeps the motor off

Loop Delay

delay(500);
  1. Adds a half-second pause before the loop repeats.
  2. Helps smooth sensor readings and reduce noise.

Downloads