PROJECT Nº 5: Light and motion alarm

Learn to build and program a light and motion alarm using the components of the Maker Control Kit and Maker Kit 1.

For this project, you will use the analog light sensor, the PIR motion sensor, and the passive buzzer. When the light sensor detects light or the PIR motion sensor detects movement, the buzzer will start to go off. Create your own light and motion alarm!

INDEX OF EXERCISES:

  • Exercise 1.1: Create the light alarm
  • Exercise 1.2: Create the motion alarm

Exercise 1.1: Create the light alarm

Using the light sensor and the buzzer, create an alarm that activates when it comes into contact with light, such as when a box or drawer opens.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 30 min.

MATERIALS:

  • 1 Light sensor
  • 1 Passive buzzer
  • 1 Box with a lid
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer
  • Adhesive

What is a buzzer?

A buzzer is an electroacoustic transducer that makes a continuous or intermittent sound of the same, generally shrill tone. It serves as a signal or warning mechanism, and it is used in many systems, such as automobiles and home appliances, including alarm clocks.

CONNECTIONS:

  1. Connect the light sensor to the analog port A0 on the 4in1 Build&Code board.
  2. Connect the buzzer to digital port 3 on the 4in1 Build&Code board.

Look at the colors of the cables and the colors of the terminals on the 4in1 Build&Code board to guide you. Each cable should be connected to its color.

BUILDING THE STRUCTURE:

Use a box that you have on hand. It can be made of any material, as long as it has a lid. Download the quick assembly guide and follow the steps given to set up the structure.

Ask an adult to help you make a hole in one of the sides of the box so that the USB cable can pass through it.

Place the electronic system in the box and connect the USB cable to the 4in1 Build&Code board. Keep in mind that the light must be positioned toward the box lid so that, when it opens, it detects the light and the alarm goes off.

PROGRAMMING CODE:

When the light sensor has a reading greater than 300, it activates the buzzer to sound for five seconds through the program. After this time, the sound will stop. When the light sensor no longer picks up external light, the entire system will reset.

You can do this activity by using Arduino and Bitbloq software, as well as other compatible block programming software. Below you will find the programming code needed for each software.

Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Open the Arduino program, and once in, copy the following program:
    byte BUZZERpin = 3; // Buzzer connected to digital port 3
    int BUZZERon_off; // Buzzer on/off variable
    int PortLight = A0, Light; // Light sensor connected to analog port A0 ; dependent on light reading
    
    void setup() {
      // Put your setup code here, to run once:
      pinMode(BUZZERpin,OUTPUT); // Buzzer configuration
    }
    
    void loop() {
      // Put your main code here, to run repeatedly:
      Light = analogRead(PortLight); // Light contains the light sensor reading
      if((Light > 300)&&(BUZZERon_off == 1)) // If the light sensor is greater than 300 and BUZZERon_off is equal to 1
      {
        tone(BUZZERpin,300); // The buzzer goes off
        delay(5000); // For 5 seconds
        BUZZERon_off = 0; // BUZZERon_off is equal to 0
        noTone(BUZZERpin); // Buzzer stops going off
      }
     else if (Light < 300) // If the light sensor is less than 300
      {
        noTone(BUZZERpin); // Buzzer does not sound
        BUZZERon_off = 1; // BUZZERon_off is equal to 1
      }
    }
    
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software

  1. Download the software and go through the installation process.
  2. Open the program, and once in, copy the following code:
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

RESULT OF THE EXERCISE:

When the light sensor comes in contact with light, the alarm is activated, and after a short time it stops going off. The alarm resets when it no longer comes into contact with light, that is, when the box lid is closed. You have created your light alarm!

 

Exercise 1.2: Create the motion alarm

Use the PIR motion sensor and the buzzer to create an alarm that goes off when the motion sensor detects movement.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 30 min.

MATERIALS

  • 1 PIR motion detector
  • 1 Passive buzzer
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer
  • Support structure for the alarm
  • Adhesive

What is a PIR motion sensor?

A PIR motion sensor is primarily comprised of a pyroelectric sensor. Its operation consists of detecting changes in the infrared radiation emitted by objects and beings.

To capture infrared radiation, a Fresnel lens is installed, which helps concentrate the radiation toward the pyroelectric sensor.

CONNECTIONS

  1. Connect the PIR motion sensor to digital port 2 on the 4in1 Build&Code board.
  2. Connect the buzzer to digital port 3 on the 4in1 Build&Code board.

Look at the colors of the cables and the colors of the terminals on the 4in1 Build&Code board to guide you. Each cable should be connected to its color.

BUILDING THE STRUCTURE:

Use any box that you have on hand. It can be made of any material, as long as it has a lid. Download the quick assembly guide and follow the steps shown.

  1. Ask an adult to help you make 3 holes in the sides of the box, one for the PIR motion sensor, another for the buzzer, and another to insert the USB cable into the box.
  2. Put all the electronic components inside the box. Place the PIR motion sensor and the buzzer in their respective holes and fasten them to the box.

PROGRAMMING CODE:

When the PIR motion sensor detects a movement in its range, the program instructs the buzzer to be activated, which will emit a sound for 5 seconds. After this time, the buzzer will stop going off. When the PIR motion sensor does not detect movement, the system will reset.

Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Open the Arduino program, and once in, copy the following program:
    byte PIRpin = 2; // PIR s connected to digital port 2
    byte PIRstate; // Dependent on the state of the PIR sensor
    byte BUZZERpin = 3; // Buzzer connected to digital port 3
    int BUZZERon_off; // Dependent on state
    
    void setup() {
      // Put your setup code here, to run once:
      pinMode(PIRpin,INPUT); // Configuration of the PIR sensor
      pinMode(BUZZERpin,OUTPUT); // Buzzer configuration
    }
    
    void loop() {
      // Put your main code here, to run repeatedly:
      PIRState = digitalRead(PIRpin); // PIRState contains the reading of the PIR sensor
      if((PIRstate == 1)&&(BUZZERon_off == 1)) //If the PIR sensor is equal to 1 and BUZZERon_off is equal to 1
      {
        tone(BUZZERpin,300); // The buzzer goes off
        delay(5000); // for 5 seconds
        BUZZERon_off = 0; // BUZZERon_off is equal to 0
        noTone(BUZZERpin); // Buzzer stops going off
      }
     else if (PIRstate == 0) // If the PIR sensor is equal to 0
      {
        noTone(BUZZERpin); // Buzzer does not sound
        BUZZERon_off = 1; // BUZZERon_off is equal to 1
      }
    }
    
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software

  1. Download the software and go through the installation process.
  2. Open the program, and once in, copy the following code:
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

RESULT OF THE EXERCISE:

The alarm is activated when it detects a movement and plays a sound for 5 seconds. When the motion sensor does not detect any movement, the system resets. You have created your own motion alarm!

1 0

0