Title: Creating a Temperature-Controlled Fan System with Arduino Nano, LCD, DHT11, Buzzer, and Fan
In this project, we will build a temperature-controlled fan system using an Arduino Nano, an LCD display, a DHT11 sensor, a fan, and a buzzer. The system monitors the temperature and automatically triggers the fan when the temperature crosses a certain threshold. The current temperature and humidity levels will be displayed on the LCD, and an alarm will sound if it gets too hot.
Components Required:
- Arduino Nano
- DHT11 Temperature and Humidity Sensor
- 16×2 LCD (with I2C interface)
- Fan (DC motor or small cooling fan)
- Buzzer
- NPN Transistor (for driving the fan)
- Diode (for back EMF protection)
- Resistors
- Breadboard and jumper wires
Circuit Diagram:
- DHT11 Sensor:
- VCC: Connect to 5V on Arduino Nano
- GND: Connect to GND on Arduino Nano
- Data Pin: Connect to Digital Pin D12 on Arduino Nano
-
16×2 LCD Pin Connections:
- RS (Register Select): Connect to digital pin 7 on Arduino Nano.
- E (Enable): Connect to digital pin 6 on Arduino Nano.
- D4: Connect to digital pin 5 on Arduino Nano.
- D5: Connect to digital pin 4 on Arduino Nano.
- D6: Connect to digital pin 3 on Arduino Nano.
- D7: Connect to digital pin 2 on Arduino Nano.
- VSS: Connect to GND on Arduino Nano.
- VDD: Connect to 5V on Arduino Nano.
- RW (Read/Write): Connect to GND (for write mode).
- K (LED Cathode): Connect to GND (for backlight).
- A (LED Anode): Connect to 5V (for backlight).
- V0: Connect to the middle pin of a 10kΩ potentiometer (adjust for contrast).
Fan:
- Connect the fan to the collector of the NPN transistor.
- Emitter of the transistor goes to GND.
- The base is connected to a resistor, which is connected to a digital pin (D9) of Arduino.
- A diode is connected across the fan to protect from back EMF.
- Buzzer:
- Positive pin of the buzzer to D8
- Negative pin to GND
Code Implementation
You need to use the LiquidCrystal
library for directly controlling the LCD .
////////////////////////////////////////
#include <Wire.h>
#include <LiquidCrystal.h>
#include <DHT.h>
#define DHTPIN 12 // Pin where the DHT11 is connected
#define DHTTYPE DHT11
#define FAN_PIN 9 // Fan connected to Pin 9
#define BUZZER_PIN 8 // Buzzer connected to Pin 8
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
pinMode(FAN_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
lcd.begin();
dht.begin();
Serial.begin(9600);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Sensor Error”);
return;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Temp: “);
lcd.print(t);
lcd.print(” C”);
lcd.setCursor(0, 1);
lcd.print(“Humidity: “);
lcd.print(h);
lcd.print(” %”);
// Control fan based on temperature threshold
if (t > 30) { // if temp exceeds 30°C, fan turns on
digitalWrite(FAN_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH); // Activate buzzer for high temperature
} else {
digitalWrite(FAN_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
}
delay(2000); // Wait for 2 seconds before taking the next reading
}
/////////////////////////////
Explanation:
- Libraries Used:
- <LiquidCrystal.h>: Handles the 16×2 LCD .
DHT
: Reads temperature and humidity values from the DHT11 sensor.
- Temperature Monitoring:
- The DHT11 sensor reads the temperature and humidity every 2 seconds.
- The LCD displays the current temperature and humidity in real-time.
- Fan and Buzzer Control:
- The fan is connected to a transistor, allowing it to be powered by the Arduino when the temperature exceeds 30°C.
- The buzzer activates simultaneously to alert when the temperature is too high, providing an auditory warning.
- Fan Activation Logic:
- If the temperature exceeds the set threshold (30°C), the fan and buzzer are activated to cool down the system and provide an alert.
- Once the temperature drops below 30°C, both the fan and buzzer turn off.
Final Result:
As shown in the image and video, the system successfully monitors the temperature and controls the fan accordingly. The fan is activated automatically when the temperature exceeds a defined threshold, and the buzzer sounds an alert. The LCD continuously displays the temperature and humidity values, providing a visual representation of the environment.
Applications:
- Home automation cooling systems
- Temperature regulation in closed spaces
- Smart ventilation systems