Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO-Based Smart Safety System with HC-05 Bluetooth Connectivity

Image of Arduino UNO-Based Smart Safety System with HC-05 Bluetooth Connectivity

Circuit Documentation

Summary

The circuit in question is designed to interface with various sensors and a Bluetooth module to monitor environmental conditions such as motion, water level, and temperature. It also includes an accelerometer for additional functionality. The central processing unit of the circuit is an Arduino UNO, which is programmed to read sensor data, process it, and communicate with a Bluetooth module (HC-05) for potential remote monitoring or alerting.

Component List

  • HC-05 Bluetooth Module: A wireless communication module that allows for Bluetooth connectivity.
  • Arduino UNO: A microcontroller board based on the ATmega328P, used for controlling the sensors and handling logic.
  • PIR/Motion Sensor: A passive infrared sensor that detects motion by measuring changes in the infrared levels emitted by surrounding objects.
  • Water Level Float Switch Sensor: A sensor that detects the water level by opening or closing a circuit as the float rises or falls.
  • MPU-6050 Accelerometer/Gyroscope: A sensor that measures acceleration and angular rate.
  • DS18B20 Temperature Sensor: A digital thermometer providing high precision temperature readings.
  • Resistor (4.7 Ohms): A component used to limit current or divide voltages in the circuit.

Wiring Details

HC-05 Bluetooth Module

  • EN: Not connected
  • VCC: Connected to the 5V power supply through a 4.7 Ohm resistor.
  • GND: Connected to the common ground.
  • TXD: Connected to the Arduino UNO's D0 (RX) pin.
  • RXD: Connected to the Arduino UNO's D1 (TX) pin.
  • STATE: Not connected

Arduino UNO

  • 5V: Supplies power to the HC-05, DS18B20, PIR/Motion Sensor, and MPU-6050.
  • GND: Common ground for HC-05, DS18B20, PIR/Motion Sensor, MPU-6050, and Water Level Float Switch Sensor.
  • A4 (SDA): Connected to the MPU-6050's SDA pin.
  • A5 (SCL): Connected to the MPU-6050's SCL pin.
  • D0 (RX): Receives data from the HC-05's TXD pin.
  • D1 (TX): Sends data to the HC-05's RXD pin.
  • D2: Connected to the PIR/Motion Sensor's OUTPUT pin.
  • D3: Connected to the DS18B20's DQ pin.
  • D4: Connected to the Water Level Float Switch Sensor's Wire1.

PIR/Motion Sensor

  • GND: Connected to the common ground.
  • OUTPUT: Connected to the Arduino UNO's D2 pin.
  • VCC: Connected to the 5V power supply.

Water Level Float Switch Sensor

  • Wire1: Connected to the Arduino UNO's D4 pin.
  • Wire2: Connected to the common ground.

MPU-6050 Accelerometer/Gyroscope

  • VCC: Connected to the 5V power supply.
  • GND: Connected to the common ground.
  • SCL: Connected to the Arduino UNO's A5 pin.
  • SDA: Connected to the Arduino UNO's A4 pin.
  • XDA, XCL, AD0, INT: Not connected

DS18B20 Temperature Sensor

  • VDD: Connected to the 5V power supply.
  • DQ: Connected to the Arduino UNO's D3 pin.
  • GND: Connected to the common ground.

Resistor (4.7 Ohms)

  • pin1: Connected to the 5V power supply.
  • pin2: Connected to the HC-05's VCC pin.

Documented Code

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <MPU6050.h>

#define PIR_PIN 2
#define FLOAT_PIN 4
#define ONE_WIRE_BUS 3

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
MPU6050 mpu;

bool motionDetected = false;
unsigned long lastMotionTime = 0;
const unsigned long timeoutPeriod = 5000; // 5 seconds

void setup() {
    Serial.begin(9600); // Initialize serial communication for USB
    Serial1.begin(9600); // Initialize serial communication for Bluetooth (HC-05)
    sensors.begin();
    mpu.initialize();
    pinMode(PIR_PIN, INPUT);
    pinMode(FLOAT_PIN, INPUT);
}

void loop() {
    // Read the PIR sensor
    motionDetected = digitalRead(PIR_PIN);
    
    if (motionDetected) {
        lastMotionTime = millis();
    } else if (millis() - lastMotionTime > timeoutPeriod) {
        sendAlert();
    }

    // Check water level
    if (digitalRead(FLOAT_PIN) == HIGH) {
        Serial.println("Water level is high!");
        Serial1.println("Water level is high!"); // Send to Bluetooth
        sendAlert();
    }

    // Read temperature
    sensors.requestTemperatures();
    float temperature = sensors.getTempCByIndex(0);
    Serial.print("Temperature: ");
    Serial.println(temperature);
    Serial1.print("Temperature: "); // Send to Bluetooth
    Serial1.println(temperature);

    // Optional: Read MPU6050 data for more functionality
    int16_t ax, ay, az;
    mpu.getAcceleration(&ax, &ay, &az);
    Serial.print("Accelerometer: ");
    Serial.print("ax: "); Serial.print(ax);
    Serial.print(" ay: "); Serial.print(ay);
    Serial.print(" az: "); Serial.println(az);
    Serial1.print("Accelerometer: "); // Send to Bluetooth
    Serial1.print("ax: "); Serial1.print(ax);
    Serial1.print(" ay: "); Serial1.print(ay);
    Serial1.print(" az: "); Serial1.println(az);

    delay(1000);
}

void sendAlert() {
    Serial.println("ALERT: Possible drowning detected!");
    Serial1.println("ALERT: Possible drowning detected!"); // Send to Bluetooth
    Serial.println("No motion detected for 5 seconds!");
    Serial1.println("No motion detected for 5 seconds!"); // Send to Bluetooth
}

This code is designed to run on the Arduino UNO microcontroller. It initializes the connected sensors and sets up serial communication for both USB and Bluetooth. The loop function continuously checks for motion, water level, and temperature, and sends alerts through both USB and Bluetooth if certain conditions are met. The MPU6050 accelerometer data is also read and outputted, which could be used for additional features such as detecting orientation or movement.