X
Home > Blog > STEM for Arduino > HOW to Make an Invasion Alarm with Kidspico

HOW to Make an Invasion Alarm with Kidspico

By r December 11th, 2024 779 views
Invasion alarm is a device that alarms when detecting illegal invasion in a prevention area. It plays a pivotal role in security prevention, so it is widely applied to family, stores, warehouses and supermarkets. Thus, our life can be better protected from illegal invasion. Meanwhile, our personal and property safety can also be guaranteed.
In this experiment, we adopt PIR motion sensor, power amplifier and a white LED to form an invasion alarm. When someone is detected, the white LED flashes and the amplifier alarms.

Flow

4201

Assembly

line1

Required Parts

42_00

line1

Step 1

42_01

line1

Step 2

42_02

line1

Step 3

42_03

line1

Step 4

42_04

line1

Step 5

42_05

line1

Step 6

42_06

line1

Step 7

42_07

line1

Completed

42_08

line1

Wiring Diagram

4202

Test Code

Open 4.2Invasion alarm.py in Files and click 1407.

'''
 * Filename    : Smart Safe Home: Invasion Alarm
 * Thonny      : Thonny 4.1.4
 * Auther      : http//www.keyestudio.com
'''
from machine import Pin, PWM
import time

PIR = Pin(3, Pin.IN)
led = Pin(11, Pin.OUT)
trumpet = PWM(Pin(2))

while True:
    PIR_value = PIR.value()
    if PIR_value == 1:
        for i in range(6):
            trumpet.freq(880)
            trumpet.duty_u16(2000)
            led.on()
            time.sleep(0.5)
            trumpet.freq(523)
            trumpet.duty_u16(1000)
            led.off()
            time.sleep(0.5)
    else:
        trumpet.duty_u16(0)
        led.off()

Explanations

5top

Conceive:

When the sensor detects a human motion (an invasion), the LED flashes and the amplifier alarms. If it detects nothing, LED will go off and the amplifier will not emit sound.

line2

Code structure:

  1. Initialization.

    Set the pins of the PIR motion sensor, white LED module and the power amplifier.

  2. Loop.

    Read the power level of the board input from the PIR motion sensor.

    Determine whether the power level is 1(indicates an invasion).

    • If yes, the LED flashes and the amplifier alarms.

    • If not, LED will go off and the amplifier will not emit sound.

5bottom

Test Result

4top

After uploading code, when the sensor detects a human motion (an invasion), the LED flashes and the amplifier alarms.

4206

4bottom

FAQ
10top
Q: After uploading code, the LED and amplifier are no response when you put your palm in front of the sensor?
A: The PIR motion sensor detects only movement rather than objects.
Q: After uploading code, the LED lights up but the amplifier does not emit sound?
A: Rotate clockwise the potentiometer on the amplifier to turn up the sound volume.
3418
10bottom
HOW to Make a Card-scanning Door-lock Control Device with Kidspico
Previous
HOW to Make a Card-scanning Door-lock Control Device with Kidspico
Read More
How to Program Relay Module on Kidsuno
Next
How to Program Relay Module on Kidsuno
Read More
Message Us