Skip to content
International Shipping
Wish Lists Cart
0 items

#18 Smart House Project With PicoBricks

10 Nov 2023
#18 Smart House Project With 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.

 

smart house project with rasperry pi

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

MicroBlocks Codes of the PicoBricks

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

 


Microblocks Run Tab

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();
  }
}
GitHub Project Page
Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Have Questions?

Back In Stock Notification

Compare

Product SKUDescription Collection Availability Product Type Other Details

Terms & Conditions

What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
this is just a warning
Login
Shopping Cart
0 items