X
Home > Blog > STEM for Arduino > HOW to Make an Anti-theft Alarm with KidsIOT

HOW to Make an Anti-theft Alarm with KidsIOT

By r August 29th, 2024 544 views
1. Description
The anti-theft alarm system is composed of a PIR motion sensor, a buzzer, a LED and a kidsIOT mainboard. When programming via the KidsBlock, you are able to judge whether someone is moving by reading the digital signal detected by the PIR motion sensor. If someone is moving, the buzzer will sound an alarm and the LED will flash to alert the user that someone has entered the area. Thus, a low-cost anti-theft alarm system can be realized, which is suitable for homes or offices.

2. Components

Img

Img

Img

Img

kidsIOT Mainboard×1

PIR Motion Sensor×1

Passive Buzzer×1

Servo×1

Img

Img

Img

Wire×2

USB Cable×1

Anti-theft Alarm System LEGO Pieces×1

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2:Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Process 5:

Img

Process 6:Initialize the servo angle

Wiring of servo(it is the same as project 03)

Img

First write the following code in KidsBlock software and upload the code to the kidsIOT mainboard, then the servo will rotate 180° . (Note: If the servo can not rotate, you can press the RESET button on the kidsIOT board.)

Img

Process 7:(Place the three Lego boxes on the same side, then assemble the four gears.)

Img

Process 8:

Img

Process 9:

Img

Process 10:

Img

Complete 1:

Img

Process 11:Share the LEGO board with project 03

Img

Complete 2:

Img

4. Wiring Diagram

Module

kidsIOT Mainboard

PIR Motion Sensor

No.4 port(control pin is io27)

Passive Buzzer

No.6 port(control pin is io23)

Servo

G/V/io33 port(Brown→G,Red→V,Orange→io33)

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. Passive buzzer makes sound

Img

Method 1
(1). Knowledge

The passive buzzer is driven by square waves. Let’s simulate the square waves below. The high and low levels of the pin can simulate a square wave: keeping the high level for 1000us and the low level for 1000us can make the buzzer sound.

Img

Changing the time of high and low level can change the sound volume of the buzzer. You can try changing it to 1500us, 2000us, 3000us…

(2). Write the Program

① Initialize the buzzer’s pin IO23 and “Output” mode.

Img

② Set the buzzer pin IO23 to “High” and “Low”. Here we take the delay of 0.001 second (1000 microseconds) as an example to make the buzzer emit sound.

Img

The delay function is a microsecond delay, which means the time delay is 1000 microseconds.

Note: The conversion relationship between seconds, milliseconds and microseconds is: 1 second = 1000 milliseconds = 1000000 microseconds.



By f=1/T, changing high and low levels in 1000us, we can know that the frequency of such a square wave is 1000Hz (that is, the number of high and low level changes per second is 1000 times).

③ Complete Program

Img

(3). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, the passive buzzer will make sound.

Method 2
(1). Knowledge

Use the “passive buzzer” code block to drive. The “passive buzzer” code block can generate a fixed-frequency PWM signal to drive the passive buzzer to sound. The sounding time length (beat) and sounding frequency can be controlled via parameters.

Img

(2). Add “passive buzzer”

Tap the “Actuator” module in the “Extension” , then select “esp32 Passive buzzer” and click Imgto return to the programming interface.

Img

Img

Img

(3). Description of the Building Block

Img

Set the frequency and beat of the passive buzzer to the specified pin.

Img Set the passive buzzer to play specific music to the specified pin.

Img

Set the passive buzzer to make no sound to the specified pin.

(4). Write the Program

① Initialize the buzzer’s pin IO23 and “Output” mode.

Img

② Set the sound pin, frequency and beat can be selected by yourself.

Img

③ Produce different tones.

Img

④ Complete Program

Img

(5). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, the passive buzzer will make sounds with different tones.

6. Passive buzzer plays music

Img

(1). Write the Program

① The buzzer pin is IO23, and then select a piece of music (we take Birthday as an example here) .

Img

② Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, the passive buzzer will play a “Happy Birthday” music.

7. Read the value of PIR Motion Sensor

Img

Step 1:Write the Program

① Set the baud rate to 15200.

Img

② Set the pin IO27 connected to the PIR motion sensor to “input” mode.

Img

③ Define a “PIR_motion_sensor” global variable to store the value of the sensor.

Img

④ Store the read value of the sensor in the “PIR_motion_sensor” variable and print it on the serial port.

Img

⑤ Complete Program

Img

Step 2:Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200.

When the sensor detects movement of a person or animal, the serial monitor window prints 1, and the red LED on the sensor will be off; otherwise, the monitor prints 0, and the red LED on the sensor will be on.

Note: The sensor does not have penetrating capabilities. When detecting human movement, please do not block it.



Img

8. Anti-theft Alarm System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Write the Program

①Set the baud rate to 15200, the IO27 pin of PIR motion sensor to “input” mode.

Img

② Set the pin IO33 connected to the servo to “Output” mode, initialize the control channel of the servo to CH2 (LT1) and the initial angle to 90°, delay 0.5 seconds.

Img

② Define a “PIR_motion_sensor” global variable to store the value of the PIR motion sensor.

Img

③ Store the read value of the sensor in the “PIR_motion_sensor” variable.

Img

④ Judge whether the sensor detects that a person or animal is moving. When someone or an animal is moving, the buzzer sounds, the servo rotates to close the door, and the serial monitor prints “Someone”; otherwise, the buzzer does not sound, the servo rotates to open the door, and the monitor prints ” No one”.

Img

⑤ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200.

When the sensor detects that someone or an animal is moving, the buzzer sounds, the servo rotates to close the door, and the serial monitor prints “Someone”; otherwise, the buzzer does not sound, the servo rotates to open the door, and the monitor prints “No one”.

Img

Img

9. Common Problems
Q1: The tone of the passive buzzer is not accurate to the actual tone?

A: The tones simulated by ordinary passive buzzers cannot meet the requirements of professional tones. If you need accurate tones, you need to use a more professional passive buzzer.

Q2: Does the PIR motion sensor make false alarms?
A: ① Non-professional PIR motion sensor.
② The requirements for the sensor to avoid false alarms are as follows: Within the detection range, avoid objects that are caused by the wind, such as curtains, clothing, flowers, etc. Avoid interference from strong light within the detection range, such as sunlight, car lights, spotlights, lighting and other light sources.
HOW to Build an Automatic Feeding System with KidsIOT
Previous
HOW to Build an Automatic Feeding System with KidsIOT
Read More
How to Program Relay Module on Kidsuno
Next
How to Program Relay Module on Kidsuno
Read More
Message Us