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 presence detection. The system uses an Arduino UNO microcontroller to read temperature data from an LM35 sensor, detect presence using an LD2410C sensor, and control a fan through a relay. The system also includes a 16x2 I2C LCD for displaying the current temperature threshold and system status, a pushbutton to cycle through temperature thresholds, and a rocker switch for manual fan control.

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 that outputs a voltage proportional to the temperature.
    • 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: 5V fan for cooling purposes.
    • Pins: GND, 5V
  6. Pushbutton

    • Description: Button for user input.
    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
  7. Rocker Switch

    • Description: Switch for manual control.
    • Pins: 1, 2
  8. LD2410C

    • Description: Presence detection sensor.
    • Pins: RX, OUT, GND, VCC, TX
  9. Socket

    • Description: Power 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
  
  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: ");