Intrusion Detection Device Based on PIC16F628A

Publisher:咖啡狐狸Latest update time:2020-02-19 Source: eefocusKeywords:PIC16F628A Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction: This paper introduces the principle and characteristics of a person detection device. The device is based on the PIC16F628A single-chip microcomputer, uses a pair of independent ultrasonic transducers for transmission and reception, and uses the Doppler effect to effectively detect whether someone enters a certain space, and can output signals to control the switch of lighting equipment.


Ultrasonic waves can be used to effectively detect moving objects in a certain space. It is easy to install and has good detection effects. This article introduces a person detection device designed using the ultrasonic Doppler effect. The design uses the PIC16F628A microcontroller, improves the ultrasonic detection hardware circuit used in the past, uses software programming to effectively detect the person, and then outputs a control signal to control the switch of the lighting device.


1 Working principle and characteristics


When there is relative motion between the sound source and the sound wave receiver, the frequency of the signal received by the sound wave receiver will be different from the frequency of the propagated sound wave. The frequency difference is related to the relative motion speed between the sound source and the receiver. This is caused by the Doppler effect. This design uses an ultrasonic transmitter and receiver that are both fixed in the same direction. When an obstacle moves toward or away from the two, it can be regarded as a relative motion between the image source and the receiver formed by the reflection effect of the obstacle surface on the sound wave. The Doppler effect can also be used to determine whether someone is moving within the detection range based on the signal received by the receiver.


The device has both ultrasonic transmitting and receiving transducers, and is easy to install. The maximum detection distance of the front is adjustable from 1 to 5.5 m, and can effectively detect moving objects in the space. After detecting a moving object, a +12 V signal is output to control the switch of the lighting device. The duration of the +12 V output can be adjusted from 15 to 1 800 s.


2 Hardware System


The device uses ultrasonic transducers with independent transmission and reception. The hardware system can be basically divided into a microprocessor part, a transmission part and a reception part.


The microprocessor used is the PIC16F628A microcontroller produced by Microchip, and its pins are shown in Figure 1. This microcontroller is a reduced instruction set processor (RISC) with a total of 35 assembly instructions, which is simple and effective to use. The PIC16F628A has a total of 18 pins, a standard operating voltage of 5 V, and an external crystal oscillator can reach a maximum of 20 MHz. Its internal resources are very rich, including 2 KB of Flash program memory, 224B of data memory, 2 analog comparators, 1 PWM controller, 1 16-bit timer/counter, 1 8-bit timer/counter, 1 8-bit timer, as well as power-on startup circuit, power-off reset circuit and watchdog circuit. The PIC16F628A can also respond to various hardware interrupts such as timers, comparators, RB ports, etc. Reasonable use of these resources can effectively simplify peripheral circuits and reduce product costs (the on-chip resources not used in this design are not listed here).

The circuit diagram of the transmitting part is shown in Figure 2. The ultrasonic transmitting transducer uses 328STl60, and its center frequency is 32.81.0 kHz. Using the PWM controller of the PIC16F628A microcontroller, the RB3 port outputs a square wave signal of about 32.8 kHz, and the voltage and current are amplified through transistors Q1 and 4069, thereby driving the transmitting transducer to emit an ultrasonic signal. Among them, transistor Q2 is designed for system self-test. In the normal detection process, the RBO port always outputs a low level, so that the transistor Q2 remains in the cut-off state, which will not affect the normal transmission of the ultrasonic transmitting transducer.

The receiving circuit diagram is shown in Figure 3. The ultrasonic receiving transducer uses 328SRl60, and its center frequency is also 32.8 ± 1.0 kHz. Since the signal directly received by the receiving transducer is relatively weak, it needs to be amplified by an operational amplifier first. The operational amplifier model used here is TLO62. In order to cooperate with the subsequent detection, it forms a positive phase and a negative phase amplifier circuit respectively. The detection circuit actually uses a bidirectional analog switch chip 4066, and uses the driving signal sent by the ultrasonic wave as the reference signal for detection, that is, the switching of the analog switch of 4066 is controlled by RB3. When the RB3 level is high, the positive phase amplifier circuit is connected; when the RB3 level is low, the negative phase amplifier circuit is connected. This is equivalent to multiplying the amplified signal by 1 continuously, and its switching frequency is the same as the ultrasonic transmission frequency. Let the frequency be, fo, then the equivalent signal generated by the analog switch is a square wave with a frequency of fo and an amplitude of 1, let it be uo. Then uo can be obtained from the Fourier series. The expression of is:

Assume that the received signal is u1=Usin(2πf1t+π), and the amplification factor of the positive and negative phase amplifier circuits is A. Then the expression of the signal u after passing through the detection circuit is:

Among them, fo is the frequency of the ultrasonic signal sent, θ0 is its initial phase angle, f1 is the frequency of the received ultrasonic signal, θ1 is its initial phase angle, and U is its amplitude.


Due to the Doppler effect, if there is no moving object reflecting the ultrasound, then fo=f1; once there is a moving object reflecting the ultrasound, then fo-f1≠0. Although fo and f1 are both relatively large, the frequency difference caused by human motion, that is, the absolute value of fo-f1, will not be too large. From the above formula derivation results, it can be seen that as long as a low-pass RC filter is used to filter out the high-frequency signal, the characteristic signal generated by human motion can be obtained.

Then, u' is further processed by a differentiator to obtain a waveform with more obvious changes, which can effectively improve the detection sensitivity. After removing useless signals or interference signals through a bandpass filter, the output waveform is sent to the RB5 port of the microcontroller through the comparator. The received pulse signal can be processed in real time using the RB port interrupt of the microcontroller. As shown in Figure 3, adjusting R can change the comparison level of the level comparison circuit, so that the maximum detection distance of the front of the device can be adjusted between 1 and 5.5 m.

As shown in Figure 4, by using the structural feature that the RA4 port of the PIC16F628A microcontroller is an open collector, a pull-up resistor can be directly added to the RA4 port to conveniently control the lighting device. The driving capability of the PIC series microcontroller port is very strong and can directly drive the LED. When a moving object is detected, the microcontroller outputs a +12 V level signal through the RA4 port to drive the lighting device, and at the same time controls the LED to flash once through the RB2 port.

In addition, adjusting R3 can make the duration of the +12V level signal change between 15 and 1800 s. This function mainly uses the two comparators inside the microcontroller and combines with the peripheral RC charging circuit to detect the position of R3. The specific process is as follows: By setting the control word of the microcontroller, the positive input terminals of the comparators P1 and P2 are connected together inside the microcontroller and connected to the RA2 port. RA0, RAl, and RA2 are all input ports, as shown in Figure 4.


Under normal conditions, RA3 is an output port, and the output is low level. At this time, capacitor C1 and comparators P1 and P2 are in a stable state. When the position of the R3 slider needs to be tested, port RA3 changes from output to input, and the timer inside the microcontroller starts timing. In this way, +12 V starts to charge capacitor C1 through resistor R1. When the level of port RA2 exceeds port RA1, the output of comparator P2 changes, causing the comparator interrupt of the microcontroller. In the interrupt service program, the position of the resistor R3 slider can be calculated by reading the value of the timer. Then restore port RA3 to an output low level, discharge capacitor C1, and the entire circuit returns to the initial state, ready for the next test. The function of comparator P1 is to prevent comparator P2 from unexpected events. When the level of port RA2 exceeds port RA1, if no interrupt has been generated, comparator P1 will generate an interrupt and stop charging capacitor C1 to avoid excessive levels of ports RA2 and RA3, which may damage the microcontroller. The purpose of measuring the resistor R3 is to set the lighting time of the lighting equipment. The accuracy requirement is not high, so using this circuit for measurement is not only simple, convenient and low-cost, but also has good practical effect.


3 Software Programming


Based on hardware processing, the waveform reaching the microcontroller is already ideal, but the received pulse signal cannot be used as the detection standard. Software programming is still needed to further increase the anti-interference performance. Since the main purpose of the device is to detect the movement of the human body, a small movement of the human body can at least cause the microcontroller to receive a pulse signal of several hundred ms. In order to improve reliability, this design ignores signals with a duration of less than 100 ms. In addition, if multiple devices work at the same time, various hardware errors may cause the ultrasonic frequency sent out to be not exactly the same. When the difference is relatively large, a pulse signal of a certain frequency will continue to be received. If no processing is done, this will also affect normal detection. Considering that when no one passes by, if there is interference and the interference source is stable, the frequency of the pulse signal received by the microcontroller is basically unchanged, so the more ideal detection mechanism is: judging whether there is human movement based on whether the frequency of the returned frequency difference signal changes.

[1] [2]
Keywords:PIC16F628A Reference address:Intrusion Detection Device Based on PIC16F628A

Previous article:How to exit the sleep state of PIC16C5X microcontroller
Next article:Describe the principle of PIC microcontroller

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号