Temperature Controlled Relay Fan with Arduino


In this project, we are going to build something very simple project, a temperature controlled relay that is used to turn on a dc fan. You can actually change the DC Fan to other electrical devices such as light or servo motor. We are going to make an automatic fan that will be ON when the temperature rises above certain threshold temperature and OFF when it is below.
Just follow the steps below and you are ready to get yourself one Temperature-Controlled Automatic Fan!
Things that you need
  • Arduino UNO
  • LM35 Temperature Sensor(Celsius) 
  • Relay Module 
  • A 9V battery (To supply to the coil of relay and the fan)
  • A DC fan (9V/12V)
  • Some jumper wires
  • 16 x 2 LCD
Okay, now let’s get started.
Step 1
Connect the hardware according to the schematic below:
LCD & LM 35

Relay Module

DC Fan

Done with the hardware part? Awesome!
Part 2: Software
For the software part, I program it using arduino IDE v1.01.
  1. #include <LiquidCrystal.h>
  2. int reading = 0;
  3. int sensorPin = A0;
  4. int relay =7;
  5. // initialize the library with the numbers of the interface pins
  6. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  7.  
  8. void setup() {
  9. // set up the LCD's number of columns and rows:
  10. lcd.begin(16, 2);
  11. pinMode(relay,OUTPUT);
  12. }
  13.  
  14. void loop() {
  15. reading = analogRead(sensorPin);
  16. int celsius = reading/2;
  17. lcd.setCursor(0, 0);
  18. lcd.print("Temperature: ");
  19. lcd.setCursor(0,1);
  20. lcd.print(celsius, DEC);
  21. lcd.print((char)223);
  22. lcd.print("C");
  23. if (celsius >35) {
  24. digitalWrite(7,HIGH);
  25. } else {
  26. digitalWrite(7,LOW);
  27. }
  28. delay(500);
  29. lcd.clear();
  30. }
Some brief explanation about the coding:
1. reading = analogRead(sensorPin);
– Read analog pin from LM35 temperature sensor input pin and store at reading.
2. int celsius = reading/2;
– LM35 are design to give the exact value of temperature in Celsius. To get the celsius
value, the ADC value are required to divided by 2 .
So, load this code into your arduino UNO and you are ready to go!

Problem Encountered & Solutions

Problem 1
The GND of the 9V battery is not connected to the GND of the arduino. So, this cause the fan unable to move even if the temperature exceed the threshold temperature.
Solution 1
Connect the GND of the battery to the GND of arduino – common GND. If you are using a 5V relay instead of 12V relay, you only have to connect the arduino GND. I am using a 12V relay. So the coil voltage required would be higher.
Problem 2
When done uploading the code into my arduino UNO, the LCD display nothing.
Solution 2
After some troubleshoot work, I realised it is due to the contrast(pin 3 on LCD). You have to adjust the potentiometer connected to pin 3 of LCD until the LCD would display what you want it to display.
Hope this simple guides would lead you to make your own success Temperature-Controlled Automatic Fan too.
If you have any doubt, do leave your comments or contact me.
Hope you enjoy. Happy reading !

Comments

Post a Comment