|
|
|
|
|
|---|---|---|---|
|
kidsIOT Mainboard×1 |
PIR Motion Sensor×1 |
Passive Buzzer×1 |
Servo×1 |
|
|
|
|
|
|
Wire×2 |
USB Cable×1 |
Anti-theft Alarm System LEGO Pieces×1 |


Process 1:

Process 2:

Process 3:

Process 4:

Process 5:

Process 6:Initialize the servo angle
Wiring of servo(it is the same as project 03)

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.)

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

Process 8:

Process 9:

Process 10:

Complete 1:

Process 11:Share the LEGO board with project 03

Complete 2:

|
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.


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.

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…
① Initialize the buzzer’s pin IO23 and “Output” mode.

② 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.

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

Click
to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, the passive buzzer will make sound.
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.

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




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

Set the passive buzzer to make no sound to the specified pin.
① Initialize the buzzer’s pin IO23 and “Output” mode.

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

③ Produce different tones.

④ Complete Program

Click
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.

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

② Complete Program

Click
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.

① Set the baud rate to 15200.

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

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

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

⑤ Complete Program

Click
to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click
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.



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

② 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.

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

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

④ 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”.

⑤ Complete Program

Click
to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, click
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”.


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.