Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Smart Fan Control System with Temperature and Presence Detection

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Fan Control System with Temperature and Presence Detection

Circuit Documentation

Summary

This circuit is designed to control a fan based on temperature readings and human presence detection. The system uses an Arduino UNO microcontroller to read data from a temperature sensor (LM35) and a human presence sensor (LD2410C). The fan is controlled via a relay, and the system status is displayed on a 16x2 I2C LCD. A pushbutton is used to cycle through temperature thresholds, and a rocker switch allows for manual control of the fan.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Temperature Sensor (LM35)

    • Description: Analog temperature sensor.
    • Pins: +Vs, Vout, GND
  3. 1-Channel Relay (5V 10A)

    • Description: Relay module for controlling high-power devices.
    • Pins: NC, signal, C, power, NO, ground
  4. 16x2 I2C LCD

    • Description: LCD display with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  5. Fan

    • Description: DC fan.
    • Pins: GND, 5V
  6. Pushbutton

    • Description: Momentary pushbutton switch.
    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
  7. Rocker Switch

    • Description: On/Off rocker switch.
    • Pins: 1, 2
  8. LD2410C

    • Description: Human presence sensor.
    • Pins: RX, OUT, GND, VCC, TX
  9. Socket

    • Description: Electrical socket.
    • Pins: earth, life, neutral

Wiring Details

Arduino UNO

Temperature Sensor (LM35)

1-Channel Relay (5V 10A)

16x2 I2C LCD

Fan

Pushbutton

Rocker Switch

LD2410C

Socket

Code Documentation

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>

// Define pins for LD2410C (connect TX to RX on Arduino and RX to TX)
#define LD2410_TX 10
#define LD2410_RX 11

// Initialize SoftwareSerial for LD2410C communication
SoftwareSerial ld2410Serial(LD2410_RX, LD2410_TX);

// Other component pins
const int lm35_pin = A0;            // LM35 temperature sensor pin
const int relay_pin = 2;            // Relay control pin
const int switch_pin = 4;           // Manual mode switch pin
const int threshold_button_pin = 5; // Button to cycle through thresholds

// Initialize the LCD (e.g., address 0x27, 16 columns, 2 rows)
LiquidCrystal_I2C lcd(0x27, 16, 2);

float temp_threshold = 60.0;         // Default temperature threshold
int threshold_state = 0;             // Tracks the threshold state
bool buttonPressed = false;          // Tracks button press state
bool personDetected = false;         // Tracks person detection status

void setup() {
  Serial.begin(9600);               // For debugging
  ld2410Serial.begin(115200);       // LD2410C operates at 115200 baud rate
  
  configureLD2410C();               // Configure LD2410C for human detection within range
  
  lcd.init();                       // Initialize the LCD
  lcd.backlight();                  // Turn on the LCD backlight
  lcd.setCursor(0, 0);
  lcd.print("Temp Threshold:");
  updateLCD();                      // Display initial threshold
  
  pinMode(relay_pin, OUTPUT);       // Set relay pin as output
  pinMode(switch_pin, INPUT_PULLUP);// Manual switch pin with internal pull-up
  pinMode(threshold_button_pin, INPUT_PULLUP); // Threshold button with internal pull-up
  
  digitalWrite(relay_pin, LOW);     // Turn off relay (fan) initially
}

void loop() {
  // Read temperature
  int temp_adc_val = analogRead(lm35_pin);
  float temp_val = (temp_adc_val * 4.88) / 10;  // Convert ADC value to °C
  
  // Debug temperature
  Serial.print("Temperature: ");
  Serial.print(temp_val);
  Serial.println(" °C");

  // Read manual switch state
  int switch_state = digitalRead(switch_pin);

  // Check person detection using LD2410C
  personDetected = detectPersonLD2410C();

  // Manual mode: override temperature control
  if (switch_state == LOW) {
    Serial.println("Manual Mode: Fan ON");
    digitalWrite(relay_pin, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Manual Mode:");
    lcd.setCursor(0, 1);
    lcd.print("Fan ON");
  } else {
    // Automatic mode with presence detection
    if (personDetected) {
      // Handle threshold button press
      if (digitalRead(threshold_button_pin) == LOW && !buttonPressed) {
        buttonPressed = true;
        threshold_state = (threshold_state + 1) % 3;  // Cycle through states
        
        if (threshold_state == 0) temp_threshold = 60.0;
        else if (threshold_state == 1) temp_threshold = 70.0;
        else if (threshold_state == 2) temp_threshold = 80.0;

        updateLCD();
      }

      // Reset buttonPressed when released
      if (digitalRead(threshold_button_pin) == HIGH && buttonPressed) {
        buttonPressed = false;
      }

      // Fan control based on temperature threshold
      if (temp_val < temp_threshold) {