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

Arduino UNO-Based Smart Home Security System with PIR Motion Sensor and Smoke Detection

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Home Security System with PIR Motion Sensor and Smoke Detection

Circuit Documentation

Summary

This circuit is designed to integrate various sensors and actuators with an Arduino UNO microcontroller. The components include a PIR motion sensor, an MQ-2 gas sensor, a red LED, a buzzer module, a 4-channel relay, and an 8 push button board. The Arduino UNO serves as the central controller, processing inputs from the sensors and buttons and controlling the actuators accordingly.

Component List

PIR Motion Sensor (Wokwi Compatible)

LED: Two Pin (red)

MQ-2

Buzzer Module

Relay 4 Channel 5v

8 Push Button Board PCB

Arduino UNO

Wiring Details

PIR Motion Sensor (Wokwi Compatible)

LED: Two Pin (red)

MQ-2

Buzzer Module

Relay 4 Channel 5v

8 Push Button Board PCB

Documented Code

void setup() {
  // Set up ports
  DDRB = 0xFF; // Set PORTB as output
  DDRD = 0xFF; // Set PORTD as output
  DDRC &= ~(1 << PINC0); // Set A0 as input for smoke sensor
  DDRD &= ~(1 << PIND9) & ~(1 << PIND8) & ~(1 << PIND6) & ~(1 << PIND7); // Set buttons as input
}

void loop() {
  // Check PIR sensor
  if (PIND & (1 << PINB5)) {
    PORTB |= (1 << PINB2); // Turn on LED
  } else {
    PORTB &= ~(1 << PINB2); // Turn off LED
  }
  
  // Check smoke sensor
  if (ADC(PINC0) > 300) { // Threshold for smoke detection
    PORTB |= (1 << BUZZER_PIN); // Turn on buzzer
    delay(300000); // Wait for 5 minutes
    PORTB &= ~(1 << BUZZER_PIN); // Turn off buzzer
  }
  
  // Check buttons and control relays
  if (PIND & (1 << PINB1)) {
    PORTD |= (1 << PIND2); // Turn on relay 1
  } else {
    PORTD &= ~(1 << PIND2); // Turn off relay 1
  }
  
  if (PIND & (1 << PINB0)) {
    PORTD |= (1 << PIND3); // Turn on relay 2
  } else {
    PORTD &= ~(1 << PIND3); // Turn off relay 2
  }
  
  if (PIND & (1 << PIND6)) {
    PORTD |= (1 << PIND4); // Turn on relay 3
  } else {
    PORTD &= ~(1 << PIND4); // Turn off relay 3
  }
  
  if (PIND & (1 << PIND7)) {
    PORTD |= (1 << PIND5); // Turn on relay 4
  } else {
    PORTD &= ~(1 << PIND5); // Turn off relay 4
  }
}

void ADC(double smoke) {
  ADMUX = 0x22;
  ADCSRA = 0x86;
  while (1) {
    ADCSRA |= (1 << ADSC);
    while ((ADCSRA & 0x10) == 0);
    return ADCH;
  }
}

This code sets up the Arduino UNO to read inputs from the PIR motion sensor, MQ-2 gas sensor, and push buttons, and control the LED, buzzer, and relays accordingly. The setup function configures the input and output ports, while the loop function continuously checks the sensor inputs and updates the outputs.