Temperature Controlled Fan

by RamTrinadh in Circuits > Arduino

916 Views, 12 Favorites, 0 Comments

Temperature Controlled Fan

IMG20220407111401.jpg

Here in this project, we’ll use an Arduino uno and LM35 temperature sensor to turn a fan on automatically when the temperature is too high.

Materials Required

14-02-scaled.jpg
images (31).jpeg
1-channel-5v-relay-board-module-robotics-bangladesh.jpg
mexico-dc-fan-80x80x25mm-12-vol-original-imafgvernyymuawc.jpeg
Arduino_Uno_-_R3.jpg
61g52cx9AbL._SL1337_.jpg
1. Arduino board
2. Breadboard
3. Jumper wires
4. LM35 temperature sensor
5. 5V single-channel relay module
6. 12V mini computer cooling fan
7. 9V battery snap and battery

Connecting the Circuit

IMG_20220503_164238.jpg
Build or Connect the circuit as shown in the diagram attached.
1. Insert the LM35 sensor into the breadboard with the front of the sensor (the flat surface with text on it) facing you. Connect the left pin to the +5V rail on the breadboard, the center pin to Arduino A0, and the right pin to the GND rail.
2. There are a number of connections on the relay, If your relay module has a different layout, adapt the wiring accordingly (using the data sheet or the pin markings on the module).
Our relay has an LED marked PWR to indicate when it’s receiving power, and another LED to show when the electromagnetic switch is on (you can usually hear this, too, as it makes a satisfying clicking noise).
The relay can be set to be HIGH or LOW when triggered, as indicated by a small jumper switch or pins. For our project, make sure the jumper is set to HIGH so the relay will send power when it is triggered.
3.The pins on the right side of the relay module are Signal, GND, and +5V. Attach the relay’s Signal pin to Arduino pin 5, GND to Arduino GND, and +5V to the Arduino power via the breadboard rails.
4. On the left side of the relay module are the connections for the electromagnetic switch. The center pin is the common connection; the left pin is marked NO for normally open, meaning the circuit is broken and the default state is off; and the right pin is marked NC for normally closed, meaning the default state is on. If the relay is not switched, the common pin is connected to the NC pin. If the relay is switched, the common pin is connected to the NO pin. Because we want the circuit to be off until we use the switch, we will use the NO pin.
5. Next, connect the black GND wire of the fan to the GND wire of the 9V battery. Then, as shown in the following table, attach the red positive wire of the fan to the common pin on the relay, and connect the positive wire of the 9V battery to NO on the relay.
6. Connect the breadboard power rails to each other and to the Arduino GND and +5V pins.
7. Make sure your setup matches the circuit diagram and then upload the code.

Running the Code

Now, copy and paste the below code into your Arduino programming environment. Note that in this code, i have set the temperature for the fan to turn on when it reaches 71 degrees Fahrenheit or 21 degrees Celsius. If you want to adjust this temperature, simply go into the code and change it to whatever temperature you want your fan to turn on at.

CODE:
#define SENS_PIN A0 // Defines A0 pin as "sensor"
#define FAN_PIN 5
int Vin; // Reads value from Arduino pin
float Temperature; // Receives converted voltage value to temp
float TF; // Receives converted value in °F
void setup() {
pinMode(FAN_PIN, OUTPUT); // Fan pin as an output
Serial.begin(9600); // Start Serial Monitor
}
void loop() {
// Tells Arduino to read pin and stores value in Vin
Vin = analogRead(SENS_PIN);
// Converts voltage value into temperature and
// stores value in Temperature (as °F)
Temperature = (500*Vin) / 1023*(1.8) + 32;
TF = Temperature;
Serial.print("Temperature: "); // Sends text to display screen
Serial.print(TF); // Shows value of temperature in Serial Monitor
Serial.println(" F"); // Writes F to indicate it is in Fahrenheit
if (TF > 71) { // If temperature is more than 71
digitalWrite(FAN_PIN, HIGH); // Turn fan on
}
else if (TF < 71) {
digitalWrite(FAN_PIN, LOW); // Or keep fan off
}
delay(1000); // Waits for a second to read the pin again
}

Time for Testing!!

Upload the code onto the arduino board by using USB cable and run the code. Now, watch the temperature that your temperature sensor is reading. You should be able to see the fan turning on and off depending on the temperature!