SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
Code
When the program is executed, if someone walks into the PIR detection range, the buzzer will be’BEEP BEEP’ for 5
seconds!
import
machine
import
utime
pir_sensor
=
machine
.
Pin(
14
, machine
.
Pin
.
IN)
buzzer
=
machine
.
Pin(
15
, machine
.
Pin
.
OUT)
def
motion_detected
(pin):
for
i
in
range
(
50
):
buzzer
.
toggle()
utime
.
sleep_ms(
100
)
pir_sensor
.
irq(trigger
=
machine
.
Pin
.
IRQ_RISING, handler
=
motion_detected)
(
"Intruder Alarm Start!"
)
What more?
PIR is a very sensitive sensor. In order to adapt it to the environment of use, it needs to be adjusted. Let the side with
the 2 potentiometers facing you, turn both potentiometers counterclockwise to the end and insert the jumper cap on
the pin with L and the middle pin.
Copy the following code into Thonny and run it, let us analyze its adjustment method along with the experimental
results.
import
machine
import
utime
pir_sensor
=
machine
.
Pin(
14
, machine
.
Pin
.
IN)
global
timer_delay
timer_delay
=
utime
.
ticks_ms()
(
"start"
)
def
pir_in_high_level
(pin):
global
timer_delay
pir_sensor
.
irq(trigger
=
machine
.
Pin
.
IRQ_FALLING, handler
=
pir_in_low_level)
intervals
=
utime
.
ticks_diff(utime
.
ticks_ms(), timer_delay)
timer_delay
=
utime
.
ticks_ms()
(
"the dormancy duration is "
+
str
(intervals)
+
"ms"
)
def
pir_in_low_level
(pin):
global
timer_delay
pir_sensor
.
irq(trigger
=
machine
.
Pin
.
IRQ_RISING, handler
=
pir_in_high_level)
intervals2
=
utime
.
ticks_diff(utime
.
ticks_ms(), timer_delay)
timer_delay
=
utime
.
ticks_ms()
(
"the duration of work is "
+
str
(intervals2)
+
"ms"
)
pir_sensor
.
irq(trigger
=
machine
.
Pin
.
IRQ_RISING, handler
=
pir_in_high_level)
74
Chapter 3. For MicroPython User
Содержание Thales Kit
Страница 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Страница 10: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 6 Chapter 1 Introduction to Raspberry Pi Pico ...
Страница 12: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 8 Chapter 2 What is Included in This Kit ...
Страница 13: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 1 Components List 2 1 Components List 9 ...
Страница 42: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 38 Chapter 2 What is Included in This Kit ...
Страница 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Страница 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...