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

Arduino UNO-Based Smart Home Automation System with Bluetooth Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Home Automation System with Bluetooth Control

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions using various sensors and control devices such as a fan, light, and buzzer. The system is managed by an Arduino UNO microcontroller, which processes data from sensors and controls the actuators based on predefined conditions. Additionally, the circuit includes a Bluetooth module for remote control and monitoring.

Component List

Power 220V

Photosensitive Sensor Module Digital Light Intensity Detection

MQ2

Buzzer

Bulb

5V Relay

Arduino UNO

Fan

PIR Sensor

DHT11

HC-05 Bluetooth Module

Wiring Details

Power 220V

Photosensitive Sensor Module Digital Light Intensity Detection

MQ2

Buzzer

Bulb

5V Relay

Arduino UNO

Fan

PIR Sensor

DHT11

HC-05 Bluetooth Module

Documented Code

#include <SoftwareSerial.h>
#include <DHT.h>

#define MP2pin A1    // Cảm biến MQ-2 nối vào cổng A1
#define buzzerPin 9  // Buzzer nối vào cổng digital D9

// Khai báo chân và loại cảm biến nhiệt độ
#define DHTPIN 4       // Chân DATA của cảm biến nhiệt
#define DHTTYPE DHT11  // Loại cảm biến: DHT11 hoặc DHT22
DHT dht(DHTPIN, DHTTYPE);

// Khai báo chân cảm biến
const int lightSensorPin = A0;  // Chân cảm biến ánh sáng
const int motionSensorPin = 2;  // Chân cảm biến chuyển động
const int relayFanPin = 6;      // Chân relay điều khiển quạt
const int relayLightPin = 7;    // Chân relay điều khiển đèn

float smokeValue;  // Biến để lưu giá trị cảm biến khói

// Chân trạng thái kết nối Bluetooth
const int bluetoothStatePin = 8;

// Khai báo SoftwareSerial cho HC-05
SoftwareSerial Bluetooth(10, 11);  // RX, TX

// Biến trạng thái
bool bluetoothConnected = false;
bool fanState = false;    // Trạng thái quạt
bool lightState = false;  // Trạng thái đèn

void setup() {
  // Khởi tạo cảm biến
  pinMode(motionSensorPin, INPUT);
  pinMode(relayFanPin, OUTPUT);
  pinMode(relayLightPin, OUTPUT);
  pinMode(bluetoothStatePin, INPUT);
  pinMode(buzzerPin, OUTPUT);

  // Tắt quạt và đèn ban đầu
  digitalWrite(relayFanPin, LOW);
  digitalWrite(relayLightPin, LOW);

  // Khởi tạo giao tiếp
  Serial.begin(9600);
  Bluetooth.begin(9600);

  // Khởi tạo cảm biến nhiệt
  dht.begin();

  Serial.println("System initialized. Waiting for commands...");
}

void loop() {
  smokeValue = analogRead(MP2pin);  // Đọc giá trị từ cảm biến MQ-2 (Khói)
  // Đọc giá trị cảm biến ánh sáng
  int lightLevel = analogRead(lightSensorPin);

  // Đọc giá trị cảm biến nhiệt độ
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  // Hiển thị dữ liệu cảm biến lên Serial Monitor
  Serial.print("Light Level: ");
  Serial.print(lightLevel);
  Serial.println(" (0-1023)");

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");

  Serial.print("Smoke Sensor Value: ");
  Serial.println(smokeValue);  // In giá trị cảm biến ra Serial Monitor

  // Gửi dữ liệu qua Bluetooth (nếu cần)
  Bluetooth.print("Light: ");
  Bluetooth.print(lightLevel);
  Bluetooth.print(" | Temp: ");
  Bluetooth.print(temperature);
  Bluetooth.print(" °C | Humidity: ");
  Bluetooth.print(humidity);
  Bluetooth