1578 views|6 replies

501

Posts

4

Resources
The OP
 

[Digi-Key Follow me Issue 1] +5. Extension Project: Intrusion Detection Alarm Based on PicoW [Copy link]

 This post was last edited by qinyunti on 2023-4-10 16:08

78afb5e5d54b7e4804f394c1dc8f64a1

Preface

In the previous articles, we played with PicoW through various modules and conducted tests on LED, buzzer, OLED, network, etc.

There are also some interesting ways to play, such as using a buzzer to play "Two Tigers".

In this article, we will implement a comprehensive demo based on the above peripherals: an intrusion detection monitor based on PicoW.

Summary Design

The overall block diagram is as follows

The TOF module detects the approach of a person.

Then the GPS location time and personnel approach information are reported to the server via WIFI.

At the same time, alarm indications are given through sound and light such as OLED, BEEP, LED, etc.

accomplish

TOF personnel approach detection

The TOF module model used is HLK-LD116S-24G

When human movement is detected, the output will be high, otherwise the output will be low.

Use GPIO18 as IO input to detect TOF output

The test code is as follows

from machine import Pin

import time

led = Pin("LED",Pin.OUT)

tof = Pin(18,Pin.IN)



led.value(0)

while True:

time.sleep(0.1)

print(tof.value())

The test is as follows

LED Indication

When a person approaches, the LED lights up to indicate an alarm, otherwise it goes out.

The test code is as follows

from machine import Pin

import time

led = Pin("LED",Pin.OUT)

tof = Pin(18,Pin.IN)



led.value(0)

while True:

time.sleep(0.1)

print(tof.value())



if(tof.value()):

led.value(1)

else:

led.value(0)

When the test hand approaches, the LED lights up, and goes out when it is removed.

Buzzer alarm

When a person approaches, the buzzer sounds to warn, otherwise it does not sound.

The test code is as follows

from machine import Pin

import time

from machine import PWM



led = Pin("LED",Pin.OUT)

tof = Pin(18,Pin.IN)

pwm = PWM(Pin(16))

pwm.freq(1000)



led.value(0)

while True:

time.sleep(0.1)

print(tof.value())



if(tof.value()):

led.value(1)

pwm.duty_u16(1000)

else:

led.value(0)

pwm.duty_u16(0)

OLED Display

When a person approaches, the OLED displays a warning message.

The test code is as follows

from machine import Pin

import time

from machine import PWM

from machine import I2C

from ssd1306 import SSD1306_I2C

WIDTH = 128 

HEIGHT = 64

i2c = I2C(0)

oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)



led = Pin("LED",Pin.OUT)

tof = Pin(18,Pin.IN)

pwm = PWM(Pin(16))

pwm.freq(1000)



led.value(0)

pwm.duty_u16(0)



while True:

time.sleep(0.1)

print(tof.value())



if(tof.value()):

led.value(1)

pwm.duty_u16(1000)

oled.fill(0)

oled.text("Warning!Intruder!",5,20)

oled.show()

else:

led.value(0)

pwm.duty_u16(0)

oled.fill(0)

oled.text("Safety!",5,20)

oled.show()

When Juve is detected approaching, it displays "arning! Intruder!", otherwise it displays "Safety!"

Online reporting

When a person approaches, the OLED will report the detected status, GPS location, current time and other information to the server.

test

The complete code is as follows

from machine import Pin
import time
from machine import PWM
from machine import I2C
from ssd1306 import SSD1306_I2C
from micropyGPS import MicropyGPS
from machine import UART
import network
import socket
ssid = 'qiqiqiqi'
password = 'cqmygysdss'
host='192.168.31.236'  #服务器IP地址
port = 10000 #服务器端口

my_gps = MicropyGPS()

WIDTH  = 128                            
HEIGHT = 64
i2c = I2C(0)
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)
uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))

led = Pin("LED",Pin.OUT)
tof = Pin(18,Pin.IN)
pwm = PWM(Pin(16))
pwm.freq(1000)

led.value(0)
pwm.duty_u16(0)

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)

# 网络连接
# Wait for connect or fail
max_wait = 10
while max_wait > 0:
    if wlan.status() < 0 or wlan.status() >= 3:
        break
    max_wait -= 1
    print('waiting for connection...')
    time.sleep(1)
# Handle connection error
if wlan.status() != 3:
    raise RuntimeError('network connection failed')
else:
    print('connected')
    status = wlan.ifconfig()
    print( 'ip = ' + status[0] )
    
#建立Socket连接
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#Socket属性
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)

while True:
    time.sleep(0.1)
    #print(tof.value())
    if uart0.any():
        stat = my_gps.update(uart0.read(1).decode('utf-8')) # Note the conversion to to chr, UART outputs ints normally
        if stat:
            print('Latitude:', my_gps.latitude_string())
            print('Longitude:', my_gps.longitude_string())
            print('Speed:', my_gps.speed_string('kph'), 'or', my_gps.speed_string('mph'), 'or', my_gps.speed_string('knot'))
            print('Date (Long Format):', my_gps.date_string('long'))
            print('Date (Short D/M/Y Format):', my_gps.date_string('s_dmy'))
            print('timestamp (Short [H,M,S] Format):', my_gps.timestamp)
            
            sstr = 'Warning!Intruder!' + my_gps.latitude_string() + my_gps.longitude_string() + my_gps.date_string('s_dmy') + '\r\n'
            s.sendto(sstr,(host,port))
            stat = None  
    if(tof.value()):
        led.value(1)
        pwm.duty_u16(1000)
        oled.fill(0)
        oled.text("Warning!Intruder!",5,20)
        oled.show()
    else:
        led.value(0)
        pwm.duty_u16(0)
        oled.fill(0)
        oled.text("Safety!",5,20)
        oled.show()
  

Summarize

In the above, we first carried out a rough design, then tested each module according to the module division, and finally achieved the design goals comprehensively.

From the whole process, since each module has been fully tested before, this article is actually the 'assembly' process.

With the design block diagram, the implementation was carried out according to the outline design, which was relatively smooth.

This activity is very meaningful. I became familiar with the corresponding development of PicoW and drove each module.

We also implemented some interesting tests and finally realized a comprehensive Demo, which was very rewarding.

Finally, I have a small suggestion. You can add more free peripheral modules to give full play to your creativity.

This post is from DigiKey Technology Zone

Latest reply

After this, can I claim the money?  Details Published on 2023-4-14 19:58
 
 

6062

Posts

4

Resources
2
 

Thanks for sharing this great event!

This post is from DigiKey Technology Zone
 
 
 

6004

Posts

6

Resources
3
 

How many points can the TOF module detect?

This post is from DigiKey Technology Zone

Comments

As long as there is a moving object within the detection range, the angle range is quite large. The test shows that it can detect a person sitting on the side and nodding slightly. However, it may be because of the reflection in the house, so the detection angle range has become larger. [attachimg]689340[/attachimg]   Details Published on 2023-4-10 11:42
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

501

Posts

4

Resources
4
 
Qintianqintian0303 posted on 2023-4-10 11:16 How many points can the TOF module detect?

As long as there is a moving object within the detection range,

The test shows that the angle range is quite large. When sitting at the side, it can detect a slight nod of the head. However, there may be reflections in the house, so the detection angle range becomes larger.

This post is from DigiKey Technology Zone
 
 
 

6820

Posts

11

Resources
5
 

This activity is very meaningful. I became familiar with the corresponding development of PicoW and drove each module.

We also implemented some interesting tests and finally realized a comprehensive Demo, which was very rewarding.

Finally, I have a small suggestion. You can add more free peripheral modules to give full play to your creativity.

Such activities cost a lot of money.

This post is from DigiKey Technology Zone

Comments

What's the fee?  Details Published on 2023-4-13 17:30
 
 
 

164

Posts

2

Resources
6
 
lugl4313820 posted on 2023-4-13 15:10 This activity is very meaningful. I became familiar with the corresponding development of PicoW, drove various modules, and implemented some interesting tests in the end...

What's the fee?

This post is from DigiKey Technology Zone
 
 
 

6820

Posts

11

Resources
7
 
After this, can I claim the money?
This post is from DigiKey Technology Zone
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list