PROJECT Nº 2: Surprise Box

Learn to build and program a surprise box using the components of the Maker Control Kit and Maker Kit 1.

Mount the box’s opening mechanism using the servomotor and the PIR motion detector. When the motion sensor detects a movement (for example, that of a hand), the box will open and automatically close 5 seconds later. Surprise people with your surprise box!

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 45 min.

MATERIALS:

  • 1 PIR motion detector
  • 1 Servomotor
  • 1 Box with a lid
  • Adhesive
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer
  • 1 Battery holder and 4 AA batteries

CONNECTIONS:

  1. Connect the PIR motion detector to digital port 3 of the 4in1 Build&Code board.
  2. Connect the servomotor to digital port 9 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 cardboard box with a lid. Place the 4in1 Build&Code board, the servomotor, and the PIR motion detector in it.

Download the quick assembly guide and follow the steps given to set up the structure. Use the images as a guide to position the PIR motion detector in the box and build the opening and closing mechanism of the box with the servomotor.

PROGRAMMING CODE:

When the PIR motion detector detects a movement in its range, the program instructs the servomotor to open the box and then close it after 5 seconds.

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:
    #include <Servo.h> // SERVOMOTOR LIBRARY
    Servo motor; // SERVOMOTOR VARIABLE
    byte PortPIR = 3, PIRState; // PIR motion sensor connected to digital port 3; PIRState is the PIR sensor's reading variable.
    
    void setup() {
      // put your setup code here, to run once:
      pinMode(PortPIR,INPUT); // configuration of the PIR sensor
      motor.attach (9); // Servomotor connected to digital port 9
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      PIRState = digitalRead(PortPIR); // PIRState contains the reading of the PIR sensor
      if (PIRState == 1) // If PIRState contains a 1
      {
        motor.write (15); // Set servomotor to 15º
        delay (5000); // Wait 5 seconds
        motor.write (85); // Set servomotor to 85º
      }
      else // If PIRState contains a 0
      {
        motor.write (85); // Set servomotor to 85º
      }
    }
    
  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 a movement is detected nearby, the box opens automatically and closes again after 5 seconds. Now you have your surprise box!

1 0

0