agsdix-fas fa-child

A Simple Anti-Theft Alarm

We create a security alarm to protect our home. We use a motion sensor to detect intruders and trigger the alarm for added security.

info outline icon
Basic Activity; Simple Conditional; Main Loop; Motion Sensor; Camera.

What are we going to do?

¿Eres Profesor?

Lesson Plan

Courses

  • Grades 3-12
  • 3rd grade – 12th grade courses

Materials

  • Cell phone, tablet, or computer
  • Internet connection

Description

In this activity, students can experiment in an introductory way with Protobject, learning visual programming and computer science safely and playfully using a device.

Educational Objectives

  • Understand the concepts of IF-THEN.
  • Create a technological object (prototype) using a device.
  • Identify relationships between technology and the surrounding world.
  • Evaluate personal work and the work of others, both individually and in teams.
  • Engage in discussions and reflect on improvement ideas.

Start (10 minutes)

Welcome the students to class and briefly introduce the day’s activity: “Today, we will learn how to prototype a motion-detecting camera.”
We will start the class by providing technical knowledge to the students for meaningful learning of the practical activity.
To kick off the class, we can begin with a question:
Have you heard of motion sensors?
 
You can allow the students to propose their answers and then complement them with the correct response.
 
Motion sensors are devices capable of detecting when someone or something moves near them and operate using different technologies. Today, we will see infrared sensors, ultrasonic sensors, and image-based sensors.
Some motion sensors work with infrared technology, which is a type of light that is invisible to the human eye. These sensors emit a small amount of infrared light and then detect the light reflected from nearby objects. If an object moves near the sensor, the amount of reflected infrared light changes, activating the sensor and indicating that something is moving.
Other motion sensors use ultrasonic technology, which consists of high-frequency sound waves that are inaudible to the human ear. These sensors emit sound waves and then detect the echoes bouncing off nearby objects. If an object moves near the sensor, the echo changes, activating the sensor and indicating that something is moving.
There are also other types of motion sensors, such as those based on cameras, which we will use in this activity.
Using a camera, changes in the image can be detected when something moves in front of it. For example, if someone moves in front of a smartphone’s camera, the captured image will change, indicating that something is moving.
In this activity, we will also learn about conditionals.
Have you heard about conditionals in programming?
You can allow the students to propose their answers and then complement them with the correct response.
 
It’s a way of instructing the computer to do different things depending on whether something is true or false.
 
For example, you can tell the computer that if it’s daytime, turn off the light (true), and if it’s not, turn it on (false).
 
So, how do we use a conditional to activate an alarm when motion is detected?
We can instruct the camera that if it detects motion, activate an alarm, and if it doesn’t detect motion, do not activate it.
To do this, we’ll first specify how much motion is considered activity by using a numerical value. If the amount of detected motion exceeds this pre-set numerical threshold, the condition is true, and the alarm is activated.
But how do we continuously check if something is moving?
With a main loop! We constantly repeat our condition. If you don’t remember what a loop is, you can review Activity 5.
Finally, to kickstart the prototyping process and make them feel like the protagonists of their learning, ask them:
Do you want to learn how to prototype a motion detector?

Development (20-30 minutes)

We connect our equipment to the Protobject platform. For this exercise, we will use the ENVIRONMENTAL MOTION motion sensor and the AUDIO PLAYER lamp.
Remember to experiment on your own beforehand before asking the students to experiment with Protobject. This way, you can anticipate questions that may arise from the students.
First, we use the IF/DO block, which allows us to assign the condition and the action to be executed.
We state that if the detected motion is greater than 40, then a song, which is a YouTube link, should be activated.
Finally, we encapsulate everything within a main loop to continually repeat this condition.
To test the prototype, we instruct the students to click the activation button.
Congratulations!

Closure (5-10 minutes)

Now that you have prototyped a motion sensor with Protobject, challenge the students with a question:

  • What would happen if the motion occurs at night?

Note that the camera’s image detector only works when the image is altered, unlike infrared or ultrasonic sensors.

  • So, how reliable is this camera?
agsdix-fas fa-book-reader

Learn

Have you ever heard of motion sensors?

Motion sensors are devices that can detect when someone or something moves near them and operate using various technologies.

Some motion sensors work with infrared, which is a type of light that we cannot see with our eyes. These sensors emit a small amount of infrared light and then detect the light that reflects off nearby objects. If an object moves near the sensor, the amount of reflected infrared light changes, activating the sensor and indicating that something is moving.

Other motion sensors use ultrasound, which are high-frequency sound waves that we cannot hear. These sensors emit sound waves and then detect the echo that bounces off nearby objects. If an object moves near the sensor, the bouncing echo changes, activating the sensor and indicating that something is moving.

Motion Sensors Using the Camera

There are also other types of motion sensors, such as those based on cameras, which is what we will use in this activity.

Using a camera, you can detect changes in the image that occur when something moves in front of it. For example, if someone moves in front of a smartphone’s camera, the captured image will change, indicating that something is moving.

If There’s Motion, the Alarm Sounds: Simple Conditionals

Have you heard of conditionals? This is the simplest one: if a condition is true, something happens.

Simple conditionals in programming, also known as “if (condition) then,” are a control structure used for a program to make decisions based on specific conditions.

Practical example of conditionals

Let’s see how to use a conditional to activate an alarm when motion is detected.

First, a motion sensor is required that can measure the amount of motion and generate a variable representing the motion itself. Then, a threshold is set to determine the minimum amount of motion needed to activate the alarm. This threshold is represented by a numerical value.

Finally, if the detected amount of motion exceeds this predefined threshold, then the condition is true, and the alarm is activated.

But how do we continuously check if there is motion?

With a main loop! Let’s look at the code below.

If you don’t remember what a loop is, you can review Activity 5.

Let’s Get to Work!

To prototype our anti-theft alarm, we will instruct the code to play a sound or song whenever it detects motion. For this, we will tell the sensor that if it detects motion above 40, it should activate. Finally, we’ll wrap everything in a loop to keep the code repeating constantly, keeping it always active.

Make

Let’s create a prototype to make the alarm.

The first step is to add two devices that allow us to (1) detect motion and (2) play the sound of an alarm.

1

Add the component CameraMotion that detects motion in the environment through the camera.

2

Add the component AudioPlayer to play the sound of an alarm.

3

Remember that if you don’t have a smartphone to scan the QR codes, you can click on Open in this window to open the components on the same computer.

plus square icon

Suggestion: In Protobject, you can add more components on the same smartphone by pressing the SCAN button as many times as you need.

We are ready to start prototyping!

Code composition

Click on the question circle icon to open the comments explaining the code.

Conditionals are found in the  Logic category.

agsdi-bulb-options

Reflect

What would happen if a thief entered at night with all the lights off?

How reliable is this alarm?

plus square icon

Hint: Remember that not all sensors work the same. This one works with images!

In the next activity, we will explore a slightly more complex conditional.