if-desing-picobricks

Workplaces, factories, homes and even animal shelters… There are different electronic systems that can be used to protect our living spaces against intruders. These systems are produced and marketed as home and workplace security systems. There are systems where the images produced by security cameras are processed and interpreted, as well as security systems that detect the human body and its movements with sensors and take action. Security systems are set up like a kind of alarm clock and give audible and visual warnings when an unidentified activity is detected in the specified zone. It notifies the business or the homeowner, and it can also make automatic notifications to the security companies.

 In cases of gas leakage, fire etc., gas sensors are used in homes and workplaces to prevent poisoning. In a problem situation, people living in the environment are alerted by a loud alarm.

We will prepare a model smart home project with PicoBricks using the HC-SR501 and MQ-2 gas sensor. This sensor HC-SR501, is also known as PIR sensor. Passive infrared (PIR) sensors use a pair of pyroelectric sensors to detect heat energy in the surrounding environment. These two sensors sit beside each other, and when the signal differential between the two sensors changes (if a person enters the room, for example), the sensor will engage.

Details and Algorithm

When the HC-SR501 PIR sensor detects motion, it gives digital output for 3 seconds. We will use a Picoboard, buzzer and button LED module in the project. All parts must be in the model.

When the program starts, the button must be pressed to activate the alarm system. After pressing the button, we must wait 3 seconds to allow for the hand to be pulled out of the model. At the end of 3 seconds, the red LED lights up and the alarm system is activated. When the alarm system detects a movement, the red LED will start to flash and the buzzer will sound the alarm. To mute it, PicoBricks must be restarted.

The MQ-2 sensor is always on. When it detects a toxic gas, it will notify you with a buzzer and flashing red LED.

Components

1X PicoBricks
1X HC-SR501 PIR sensor
1X MQ-2 Gas sensor
1X Mini breadboard
Jumper Cables
Easy Connection Cables

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

Construction Stages of the Project

To run the project, you have to turn a cardboard box into a model house. You will need scissors, pencils, tape, glue, and a utility knife. Draw windows and doors on the box with a pencil. Cut the door section with a utility knife.

You can use another cardboard to make the roof part.

Attach double-sided foam tape under the PicoBricks pieces.

Place pieces of PicoBricks inside the model house. Position the PIR sensor to see the door directly from the inside. attach the button module just above the door from the inside.

When you connect the battery case to Picoboard and turn it on, the code will start to run. 3 seconds after pressing the button, the alarm system will be activated and the red LED will turn on. As soon as you put your hand in the door, the buzzer will start to sound.

When you hold the lighter gas inside the house, the alarm system is expected to be activated again.

MicroBlocks Codes of the PicoBricks

204215604 4a427167 a8b0 4e84 b02b 889dea5ccd74

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button.

MicroPython Codes of the PicoBricks

				
					from machine import Pin, PWM
from utime import sleep
# define libraries
PIR=Pin(14, Pin.IN)
MQ2=Pin(1,Pin.IN)
buzzer=PWM(Pin(20,Pin.OUT))
redLed=Pin(7,Pin.OUT)
button=Pin(10,Pin.IN,Pin.PULL_DOWN)
# define output and input pins

activated=0
gas=0

while True:
    if button.value()==1:
        activated=1
        gas=0 
        sleep(3)
        redLed.value(1)
        buzzer.duty_u16(0)
    if MQ2.value()==1:
        gas=1
    if activated==1:
        if PIR.value()==1:
            buzzer.duty_u16(6000)
            buzzer.freq(440)
            sleep(0.2)
            buzzer.freq(330)
            sleep(0.1)
            buzzer.freq(494)
            sleep(0.15)
            buzzer.freq(523)
            sleep(0.3)
    if gas==1:
        buzzer.duty_u16(6000)
        buzzer.freq(330)
        sleep(0.5)
        redLed.value(1)
        buzzer.freq(523)
        sleep(0.5)
        redLed.value(0)
        # LED will light and buzzer will sound when PIR detects motion or MQ2 detects toxic gas
				
			

Arduino C Codes of the PicoBricks

				
					void actived (){
  digitalWrite(7,1);
  while(!(digitalRead(14) == 1))
  {
    _loop();
  }
  motion_detected();
}

void motion_detected (){
  while(1) {
      // buzzer settings 
      tone(20,262,0.25*1000);
      delay(0.25*1000);
      tone(20,330,0.25*1000);
      delay(0.25*1000);
      tone(20,262,0.25*1000);
      delay(0.25*1000);
      tone(20,349,0.25*1000);
      delay(0.25*1000);
// sound the buzzer when PIR detected a motion 
      _loop();
  }
}

void _delay(float seconds) {
  long endTime = millis() + seconds * 1000;
  while(millis() < endTime) _loop();
}

void _loop() {
}

void loop() {
  _loop();
}

void setup() {
  
  pinMode(10,INPUT);
  pinMode(1,INPUT);
  pinMode(20,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(14,INPUT);
  // define input and output pins
  
  while(1) {
      if(digitalRead(10) == 1){
          _delay(3);
          actived();
      }
      if(digitalRead(1) == 1){
          while(!(digitalRead(10) == 1))
          {
            _loop();
            tone(20,349,0.5*1000);
            delay(0.5*1000);
            digitalWrite(7,1);
            _delay(0.5);
            tone(20,392,0.5*1000);
            delay(0.5*1000);
            digitalWrite(7,0);
            _delay(0.5);
          }
      }
      _loop();
  }
}
				
			

Project Image

Project Proposal 💡

You can install fire extinguishing pipes on the ceiling of the house with a submersible pump, so that when there is a fire in the house, you can automatically extinguish it.

After completing the #25 Smart Greenhouse project, you will learn how to use the ESP01 WIFI module. Afterwards, you can enhance this project with the ESP01 as an IOT project, and send a notification to the home owner’s phone when any of the alarms are triggered. However, this would be a very complicated enhancement and will require research into a few more additional topics like MQTT etc to complete successfully.