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

Raspberry Pi Pico W-Based Multi-Sensor Security System

Image of Raspberry Pi Pico W-Based Multi-Sensor Security System

Circuit Documentation

Summary

The circuit is designed for a prison security system that detects fire sources and monitors movements. It utilizes a Raspberry Pi Pico W as the central microcontroller to interface with various sensors including an IR sensor, a flame sensor, a sound sensor, an LDR photoresistor, and an ultrasonic sensor. The system alerts personnel using a piezo speaker when a fire or movement is detected. The circuit is powered by the 3.3V output from the Raspberry Pi Pico W and shares a common ground.

Component List

Raspberry Pi Pico W

  • Microcontroller board with Wi-Fi capabilities.
  • Used as the main processing unit for controlling sensors and executing the security system logic.

KY-038 Sound Sensor

  • A module that detects sound levels with both analog and digital outputs.
  • Used to detect sound above a certain threshold in the environment.

KY-018 LDR Photo Resistor

  • A light-dependent resistor that changes resistance with light intensity.
  • Used to detect changes in light levels, which may indicate a security breach.

Piezo Speaker

  • An electronic device that emits sound when an electric current is applied.
  • Used to alert personnel when the system detects an anomaly.

KY-026 Flame Sensor

  • A sensor module that can detect flames or fire.
  • Used to detect the presence of fire within the vicinity of the sensor.

IR Sensor

  • An infrared sensor that detects infrared radiation from objects in its field of view.
  • Used to detect the presence of individuals or objects moving within its range.

Ultrasonic Sensor

  • A sensor that measures distance by emitting ultrasonic waves and measuring the time taken for the echo to return.
  • Used to detect the presence of objects or individuals within a certain distance.

Wiring Details

Raspberry Pi Pico W

  • 3v3 OUT connected to the VCC of all sensors to provide power.
  • GND connected to the ground of all sensors to complete the power circuit.
  • GP0 connected to the digital output (DO) of the KY-026 Flame Sensor.
  • GP1 connected to the digital output (D0) of the KY-038 Sound Sensor.
  • GP2 connected to the signal pin of the KY-018 LDR Photo Resistor.
  • GP3 connected to the trigger pin of the Ultrasonic Sensor.
  • GP4 connected to the echo pin of the Ultrasonic Sensor.
  • GP5 connected to one pin of the Piezo Speaker, the other pin connected to ground.
  • GP8 connected to the output of the IR Sensor.
  • GND AGND connected to the analog output (AO) of the KY-026 Flame Sensor.
  • GP26 ADC0 connected to the analog output (A0) of the KY-038 Sound Sensor.

KY-038 Sound Sensor

  • + connected to 3v3 OUT of Raspberry Pi Pico W for power.
  • G connected to GND of Raspberry Pi Pico W for ground.
  • A0 connected to GP26 ADC0 of Raspberry Pi Pico W for analog sound level.
  • D0 connected to GP1 of Raspberry Pi Pico W for digital sound detection.

KY-018 LDR Photo Resistor

  • Signal connected to GP2 of Raspberry Pi Pico W for light level detection.
  • VCC connected to 3v3 OUT of Raspberry Pi Pico W for power.
  • Ground connected to GND of Raspberry Pi Pico W for ground.

Piezo Speaker

  • pin1 connected to GP5 of Raspberry Pi Pico W to emit sound.
  • pin2 connected to GND of Raspberry Pi Pico W for ground.

KY-026 Flame Sensor

  • AO connected to GND AGND of Raspberry Pi Pico W for analog flame level.
  • GND connected to GND of Raspberry Pi Pico W for ground.
  • VCC connected to 3v3 OUT of Raspberry Pi Pico W for power.
  • DO connected to GP0 of Raspberry Pi Pico W for digital flame detection.

IR Sensor

  • out connected to GP8 of Raspberry Pi Pico W for IR detection.
  • gnd connected to GND of Raspberry Pi Pico W for ground.
  • vcc connected to 3v3 OUT of Raspberry Pi Pico W for power.

Ultrasonic Sensor

  • +VCC connected to 3v3 OUT of Raspberry Pi Pico W for power.
  • Trigger connected to GP3 of Raspberry Pi Pico W to initiate distance measurement.
  • Echo connected to GP4 of Raspberry Pi Pico W to receive distance measurement.
  • GND connected to GND of Raspberry Pi Pico W for ground.

Documented Code

Raspberry Pi Pico W Code (sketch.ino)

/*
 * Prison Security Project
 * This code is designed to detect fire sources and monitor movements.
 * It alerts the personnel using a piezo speaker when a fire or movement is detected.
 */

// Pin definitions
#define FLAME_SENSOR_PIN 0
#define SOUND_SENSOR_PIN 1
#define LDR_PIN 2
#define ULTRASONIC_TRIG_PIN 3
#define ULTRASONIC_ECHO_PIN 4
#define PIEZO_PIN 5
#define IR_SENSOR_PIN 8

// Constants
const int SOUND_THRESHOLD = 500;
const int FLAME_THRESHOLD = 100;
const int LDR_THRESHOLD = 300;
const int DISTANCE_THRESHOLD = 50; // in cm

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize pins
  pinMode(FLAME_SENSOR_PIN, INPUT);
  pinMode(SOUND_SENSOR_PIN, INPUT);
  pinMode(LDR_PIN, INPUT);
  pinMode(ULTRASONIC_TRIG_PIN, OUTPUT);
  pinMode(ULTRASONIC_ECHO_PIN, INPUT);
  pinMode(PIEZO_PIN, OUTPUT);
  pinMode(IR_SENSOR_PIN, INPUT);
}

void loop() {
  // Check sensors and alert if any are triggered
  if (detectFlame() || detectSound() || detectLight() || detectMovement() || detectIR()) {
    alertPersonnel();
  }

  delay(100); // Delay for stability
}

// Detect flame presence
bool detectFlame() {
  if (digitalRead(FLAME_SENSOR_PIN) == HIGH) {
    Serial.println("Flame detected!");
    return true;
  }
  return false;
}

// Detect sound above threshold
bool detectSound() {
  int soundLevel = analogRead(SOUND_SENSOR_PIN);
  if (soundLevel > SOUND_THRESHOLD) {
    Serial.println("Sound detected!");
    return true;
  }
  return false;
}

// Detect light intensity above threshold
bool detectLight() {
  int lightLevel = analogRead(LDR_PIN);
  if (lightLevel > LDR_THRESHOLD) {
    Serial.println("Light intensity change detected!");
    return true;
  }
  return false;
}

// Detect object within specified distance
bool detectMovement() {
  long duration, distance;

  // Send ultrasonic pulse
  digitalWrite(ULTRASONIC_TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(ULTRASONIC_TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(ULTRASONIC_TRIG_PIN, LOW);

  // Read echo pulse duration and calculate distance
  duration = pulseIn(ULTRASONIC_ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1;

  if (distance > 0 && distance < DISTANCE_THRESHOLD) {
    Serial.println("Movement detected!");
    return true;
  }
  return false;
}

// Detect IR sensor trigger
bool detectIR() {
  if (digitalRead(IR_SENSOR_PIN) == HIGH) {
    Serial.println("IR sensor triggered!");
    return true;
  }
  return false;
}

// Alert personnel by activating the piezo speaker
void alertPersonnel() {
  Serial.println("Alerting personnel...");
  digitalWrite(PIEZO_PIN, HIGH);
  delay(1000); // Alert duration
  digitalWrite(PIEZO_PIN, LOW);
}

Other Microcontrollers

The other microcontrollers in the system have placeholder code or empty documentation files, indicating that they are not currently programmed with specific functionality for this project.