This circuit is designed to monitor environmental parameters such as temperature and smoke levels, as well as to detect motion via an accelerometer. It utilizes an Arduino UNO as the central microcontroller to process sensor data and control various outputs including a relay, a buzzer, and multiple LEDs that serve as indicators. The circuit is powered by the Arduino UNO, which supplies 3.3V and 5V to the respective components. The sensors and outputs are interfaced with the Arduino through various digital and analog pins, and the system behavior is defined by the embedded code running on the Arduino.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
// Pin Definitions
#define TEMP_SENSOR_PIN 2
#define SMOKE_SENSOR_PIN A0
#define RELAY_PIN 3
#define BUZZER_PIN 4
#define WARNING_LIGHT_PIN 5
#define SEATBELT_LED_PIN 7
#define DOOR_LOCK_LED_PIN 8
#define HAZARDOUS_LIGHT_PIN 9 // Red LED
#define DASHBOARD_LIGHT_PIN 10 // Green LED
// Create instances for sensors
OneWire oneWire(TEMP_SENSOR_PIN);
DallasTemperature sensors(&oneWire);
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified();
// Setup
void setup() {
Serial.begin(9600);
sensors.begin();
accel.begin();
pinMode(RELAY_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(WARNING_LIGHT_PIN, OUTPUT);
pinMode(SEATBELT_LED_PIN, OUTPUT);
pinMode(DOOR_LOCK_LED_PIN, OUTPUT);
pinMode(HAZARDOUS_LIGHT_PIN, OUTPUT);
pinMode(DASHBOARD_LIGHT_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(WARNING_LIGHT_PIN, LOW);
digitalWrite(SEATBELT_LED_PIN, LOW);
digitalWrite(DOOR_LOCK_LED_PIN, LOW);
digitalWrite(HAZARDOUS_LIGHT_PIN, LOW);
digitalWrite(DASHBOARD_LIGHT_PIN, LOW);
}
// Main Loop
void loop() {
// Read temperature
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
// Read smoke level
int smokeLevel = analogRead(SMOKE_SENSOR_PIN);
// Read accelerometer data
sensors_event_t event;
accel.getEvent(&event);
// Example thresholds (you can adjust these as needed)
if (temperature > 30) {
digitalWrite(RELAY_PIN, HIGH); // Activate relay
digitalWrite(BUZZER_PIN, HIGH);
digitalWrite(WARNING_LIGHT_PIN, HIGH);
digitalWrite(SEATBELT_LED_PIN, HIGH);
digitalWrite(DOOR_LOCK_LED_PIN, HIGH);
digitalWrite(HAZARDOUS_LIGHT_PIN, HIGH); // Turn on Red LED
digitalWrite(DASHBOARD_LIGHT_PIN, LOW); // Turn off Green LED
} else {
digitalWrite(RELAY_PIN, LOW); // Deactivate relay
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(WARNING_LIGHT_PIN, LOW);
digitalWrite(SEATBELT_LED_PIN, LOW);
digitalWrite(DOOR_LOCK_LED_PIN, LOW);
digitalWrite(HAZARDOUS_LIGHT_PIN, LOW); // Turn off Red LED
digitalWrite(DASHBOARD_LIGHT_PIN, HIGH); // Turn on Green LED
}
if (smokeLevel > 500) {
digitalWrite(HAZARDOUS_LIGHT_PIN, HIGH); // Ensure Hazardous Light is on
digitalWrite(DASHBOARD_LIGHT_PIN, LOW); // Ensure Dashboard Light is off
}
// Print data to serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
Serial.print("Smoke Level: ");
Serial.println(smokeLevel);
Serial.print("Accelerometer X: ");
Serial.print(event.acceleration.x);
Serial.print(" Y: ");
Serial.print(event.acceleration.y);
Serial.print(" Z: ");
Serial.println(event.acceleration.z);
delay(2000); // Wait 2 seconds before next reading
}
This code initializes and reads from the temperature sensor, smoke sensor, and accelerometer, and controls the relay, buzzer, and LEDs based on the sensor readings. It also prints the sensor data to the serial monitor for debugging purposes.