THE BELL

There are those who read this news before you.
Subscribe to receive fresh articles.
Email
Name
Surname
How do you want to read The Bell?
No spam

The Arduino motion sensor allows you to track the movement of objects that emit heat (people, animals) in a closed area. Such systems are often used in domestic conditions, for example, to turn on lighting in the entrance. In this article we will look at connecting PIR sensors in Arduino projects: passive infrared sensors or pyroelectric sensors that respond to movement. Small dimensions, low cost, ease of operation and lack of connection difficulties allow the use of such sensors in various types of alarm systems.

The design of a PIR motion sensor is not very complicated - it consists of a pyroelectric element that is highly sensitive (a cylindrical part with a crystal in the center) to the presence of a certain level of infrared radiation in the action area. The higher the temperature of an object, the greater the radiation. A hemisphere is installed on top of the PIR sensor, divided into several sections (lenses), each of which ensures that the thermal energy radiation is focused on different segments of the motion sensor. Most often, a Fresnel lens is used as a lens, which, due to the concentration of thermal radiation, allows you to expand the sensitivity range of the Arduino infrared motion sensor.

The PIR sensor is structurally divided into two halves. This is due to the fact that for an alarm device it is the presence of movement in the sensitivity zone that is important, and not the level of radiation itself. Therefore, the parts are installed in such a way that when one higher level of radiation is detected, a signal with a high or low value will be sent to the output.

The main technical characteristics of the Arduino motion sensor are:

  • The detection zone for moving objects is from 0 to 7 meters;
  • Tracking angle range – 110°;
  • Supply voltage – 4.5-6 V;
  • Operating current – ​​up to 0.05 mA;
  • Temperature range – from -20° to +50°С;
  • Adjustable delay time from 0.3 to 18 s.

The module on which the infrared motion sensor is installed includes additional electrical wiring with fuses, resistors and capacitors.

The principle of operation of a motion sensor on Arduino is as follows:

  • When the device is installed in an empty room, the radiation dose received by each element is constant, as is the voltage;
  • When a person appears in a room, he first enters the viewing area of ​​the first element on which a positive electrical impulse appears;
  • When a person moves around the room, thermal radiation moves along with him, which hits the second sensor. This PIR element already generates a negative pulse;
  • Multidirectional pulses are recorded by the electronic circuit of the sensor, which concludes that there is a person in the field of view of the Pir-sensor Arduino.

For reliable protection from external noise, temperature and humidity changes, the elements of the Pir sensor on Arduino are installed in a sealed metal case. On the top of the case in the center there is a rectangle made of material that transmits infrared radiation (most often silicone-based). Sensing elements are installed behind the plate.

Connection diagram of the motion sensor to Arduino

Connecting a Pir sensor to Arduino is not difficult. Most often, modules with motion sensors are equipped with three connectors on the back. The pinout of each device depends on the manufacturer, but most often there are corresponding inscriptions near the outputs. Therefore, before connecting the sensor to Arduino, you need to familiarize yourself with the symbols. One output goes to ground (GND), the second provides the necessary signal from the sensors (+5V), and the third is a digital output from which data is taken.

Connecting the Pir sensor:

  • “Ground” – to any of the GND Arduino connectors;
  • Digital output – to any digital input or output of Arduino;
  • Power supply – +5V on Arduino.

The diagram for connecting the infrared sensor to Arduino is shown in the figure.

Example program

A sketch is a program code that helps check the functionality of the motion sensor after it is turned on. His simplest example has many disadvantages:

  • Probability of false alarms due to the fact that it takes one minute for the sensor to self-initialize;
  • Lack of executive-type output devices - relays, sirens, LED indicators;
  • A short time interval of the signal at the sensor output, which must be delayed at the software level in the event of movement.

These disadvantages are eliminated by expanding the functionality of the sensor.

The simplest type of sketch, which can be used as an example of working with a motion sensor on Arduino, looks like this:

#define PIN_PIR 2 #define PIN_LED 13 void setup() ( Serial.begin(9600); pinMode(PIN_PIR, INPUT); pinMode(PIN_LED, OUTPUT); ) void loop() ( int pirVal = digitalRead(PIN_PIR); Serial. println(digitalRead(PIN_PIR)); //If motion is detected if (pirVal) ( digitalWrite(PIN_LED, HIGH); Serial.println("Motion detected"); delay(2000); ) else ( //Serial.print(" No motion"); digitalWrite(PIN_LED, LOW); ) )

Possible project options using the sensor

PIR sensors are indispensable in those projects where the main function of the alarm is to determine the presence or absence of a person within a certain work space. For example, in places or situations such as:

  • Turning on the light in the entrance or in front of the front door automatically when a person appears in it;
  • Turning on the lighting in the bathroom, toilet, corridor;
  • An alarm is triggered when a person appears, both indoors and in the local area;
  • Automatic connection of security cameras, which are often equipped with security systems.

PIR sensors are easy to use and do not cause difficulties when connecting, have a large sensitivity zone and can also be successfully integrated into any of the Arduino software projects. But it should be borne in mind that they do not have the technical ability to provide information about how many objects are in the coverage area, and how close they are to the sensor, and can also be triggered by pets.

This article describes the creation of a motion sensor based on modules with a passive IR sensor. There are many models of modules with PIR sensors from different manufacturers, but they are based on one principle. They have one output that produces a low or high signal (depending on model) when motion is detected. In my project, the PIC12F635 microcontroller constantly monitors the logic level at the output of the sensor module and turns on the buzzer when it is high.

Theory

Some crystalline materials have the property of generating a surface electrical charge when exposed to thermal infrared radiation. This phenomenon is known as pyroelectricity. Passive modules with an IR sensor operate based on this principle. The human body emits heat in the form of infrared radiation with a maximum wavelength of about 9.4 microns. The appearance of a person creates sudden changes in the IR range of the environment, which is perceived by the pyroelectric sensor. The PIR sensor module has elements that amplify the signal to match it to logic levels. Before starting operation, the sensor needs from 10 to 60 seconds to familiarize itself with the environment for further normal functioning. During this time, you should avoid moving within the sensor's field of view. The sensor has a range of up to 20 feet and does not respond to natural environmental changes over time. At the same time, the sensor reacts to any sudden change in the environment (for example, the appearance of a person). A model with a sensor should not be placed near batteries, sockets or any other objects that quickly change their temperature, because this will lead to a false positive. PIR sensor modules usually have 3 pins: Vcc, Output and GND. The pinout may vary from manufacturer to manufacturer, so I recommend checking the documentation. Also, the pin value can be marked directly on the board. There are no such markings on my sensor. It can operate at supply voltages from 5 to 12V and has its own built-in voltage regulator. When there is movement, a high logic level appears at the sensor output. It also has a 3-pin jumper to set the operating mode. The side contacts are marked H and L. When the jumper is in position H, when the sensor is triggered several times in a row, its output remains at a high logic level. In position L, a separate pulse appears at the output each time the sensor is triggered. The front of the module has a Fresnel lens to focus IR radiation onto the sensing element.

Scheme and design

The motion sensor circuit is quite simple. The device runs on 4 AA batteries that provide 6V. On the diode, which is used as protection against incorrect power connection, the voltage drops to 5.4V. I tested the circuit with a 4.8V NI-MH battery and it worked, but I recommend using 1.5V alkaline batteries each for best performance. You can also use 9V batteries, but then you need an LM7805 stabilizer. The output from the module is controlled by the PIC12F635 microcontroller via the GP5 port (pin 2). When moving, a voltage of about 3.3 V appears at the output of the sensor. This voltage is recognized by the microcontroller as a high logical level, but I preferred to use this voltage to control the NPN transistor BC547, the collector of which was connected to the microcontroller. When the transistor is turned off, its collector level is high (+5V). When moving, a high logic level appears at the output of the module, which saturates the transistor and the voltage at its collector drops to a low logic level. The jumper on the sensor is in position H so that the sensor output will remain high until the movement stops. The PIC12F635 microcontroller uses an internal clock generator operating at 4.0 MHz.

The LED connected to the GP4 port via a current-limiting resistor blinks 3 times when power is connected. The EFM-290ED piezoelectric buzzer connected to the GP2 port reports the presence of motion. The piezoelectric buzzer produces the loudest sound at its resonant frequency. The buzzer I used has a resonant frequency of 3.4 ± 0.5 kHz. After experimenting with it, I found that it produces maximum sound at a frequency of about 372 Hz. Although the documentation says that the operating voltage is from 7-12V, it also works on 5V.

Program

The program is written in C and compiled for PIC. When power is applied, the LED flashes three times, indicating successful startup. After this, the microcontroller waits 60 seconds before starting to check the output value from the sensor. This is required to stabilize the sensor. When the microcontroller detects that the sensor is triggered, it triggers the piezo buzzer at a frequency of 3725 Hz. MikroC has a built-in library for sound generation (Sound_Play()). The buzzer makes a sound as long as the sensor senses movement. When the movement stops, the logical level at the sensor output changes, but the buzzer does not stop immediately, but makes a sound at a frequency of 3570 Hz for about 10 seconds. If it detects motion again, it will run at 3725 Hz again. This design uses an internal oscillator running at 4.0 MHz, MCLR and watchdog disabled.

/* Project: PIR Motion Sensor Alarm (PIC12F635) Piezo: EFM-290ED, 3.7 KHz connected at GP2 PIR sensor module in retriggering mode Internal Clock @ 4.0 MHz, MCLR Disabled, WDT OFF */ sbit Sensor_IP at GP5_bit; // sensor I/P sbit LED at GP4_bit; // LED O/P unsigned short trigger, counter; void Get_Delay())( Delay_ms(300); ) void main() ( CMCON0 = 7; TRISIO = 0b00101000; // GP5, 5 I/P"s, Rest O/P"s GPIO = 0; Sound_Init(&GPIO,2 ); // Blink LED at Startup LED = 1; Get_Delay(); LED = 0; Get_Delay(); LED = 1; Get_Delay(); LED = 0; Get_Delay(); LED = 1; Get_Delay(); LED = 0; Delay_ms(60000); // 45 Sec delay for PIR module stabilization counter = 0; trigger = 0; do ( while (!Sensor_IP) ( // Sensor I/P Low Sound_Play(3725, 600); Delay_ms(500) ; trigger = 1; counter = 0; ) if (trigger) ( Sound_Play(3570, 600); Delay_ms(500); counter = counter+1; if(counter == 10) trigger=0; ) )while(1) ; ) // End main()

Photo of the device:

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
MK PIC 8-bit

PIC12F635

1 To notepad
Bipolar transistor

BC547

1 To notepad
Resistor

1 kOhm

1 To notepad
Resistor

10 kOhm

1 To notepad
Resistor

470 Ohm

1 To notepad
Light-emitting diode 1

Hello everyone, today we will look at a device called a motion sensor. Many of us have heard about this thing, some have even dealt with this device. What is a motion sensor? Let's try to figure it out, so:

Motion sensor or displacement sensor - a device (device) that detects the movement of any objects. Very often these devices are used in security, alarm and monitoring systems. There are a great many forms of factors of these sensors, but we will consider the motion sensor module for connection to boards Arduino,and specifically from the company RobotDyn. Why this company? I don’t want to advertise this store and its products, but it was the products of this store that were chosen as laboratory samples due to the high-quality presentation of their products to the end consumer. So, we meet - motion sensor(PIR Sensor) from RobotDyn:


These sensors are small in size, consume little power and are easy to use. In addition, RobotDyn motion sensors also have silk-screened contacts, this is of course a small thing, but very pleasant. Well, those who use the same sensors, but only from other companies, should not worry - they all have the same functionality, and even if the contacts are not marked, the pinout of such sensors is easy to find on the Internet.

Main technical characteristics of the motion sensor (PIR Sensor):

Sensor operating area: from 3 to 7 meters

Tracking angle: up to 110 o

Operating voltage: 4.5...6 Volts

Current consumption: up to 50 µA

Note: The standard functionality of the sensor can be expanded by connecting a light sensor to the IN and GND pins, and then the motion sensor will only work in the dark.

Initializing the device.

When turned on, the sensor takes almost a minute to initialize. During this period, the sensor may give false signals; this should be taken into account when programming a microcontroller with a sensor connected to it, or in actuator circuits if the connection is made without using a microcontroller.

Detection angle and area.

The detection(tracking) angle is 110 degrees, the detection distance range is from 3 to 7 meters, the illustration below shows it all:

Adjustment of sensitivity (detection distance) and time delay.

The table below shows the main adjustments of the motion sensor; on the left there is a time delay regulator, respectively, in the left column there is a description of the possible settings. The right column describes the detection distance adjustments.


Sensor connection:

  • PIR Sensor - Arduino Nano
  • PIR Sensor - Arduino Nano
  • PIR Sensor - Arduino Nano
  • PIR Sensor - for light sensor
  • PIR Sensor - for light sensor

A typical connection diagram is shown in the diagram below; in our case, the sensor is shown conventionally from the rear side and connected to the Arduino Nano board.

Sketch demonstrating the operation of the motion sensor (we use the program):

/* * PIR Sensor -> Arduino Nano * PIR Sensor -> Arduino Nano * PIR Sensor -> Arduino Nano */ void setup() ( //Establish a connection to the port monitor Serial.begin(9600); ) void loop() ( //Read the threshold value from port A0 //usually it is higher than 500 if there is a signal if(analogRead(A0) > 500) ( //Signal from the motion sensor Serial.println("There is movement!!!"); ) else ( / /No signal Serial.println("Everything is quiet..."); ) )

The sketch is a common test of the operation of the motion sensor; it has many disadvantages, such as:

  1. Possible false alarms, the sensor requires self-initialization within one minute.
  2. Rigid binding to the port monitor, no output actuators (relay, siren, LED indicator)
  3. The signal time at the sensor output is too short; when motion is detected, it is necessary to programmatically delay the signal for a longer period of time.

By complicating the circuit and expanding the functionality of the sensor, you can avoid the above-described disadvantages. To do this, you will need to supplement the circuit with a relay module and connect a regular 220-volt lamp through this module. The relay module itself will be connected to pin 3 on the Arduino Nano board. So the schematic diagram:

Now it's time to slightly improve the sketch that tested the motion sensor. It is in the sketch that a delay in turning off the relay will be implemented, since the motion sensor itself has too short a signal time at the output when triggered. The program implements a 10-second delay when the sensor is triggered. If desired, this time can be increased or decreased by changing the value of the variable DelayValue. Below is a sketch and video of the entire assembled circuit in action:

/* * PIR Sensor -> Arduino Nano * PIR Sensor -> Arduino Nano * PIR Sensor -> Arduino Nano * Relay Module -> Arduino Nano */ //relout - pin (output signal) for the relay module const int relout = 3; //prevMillis - variable for storing the time of the previous program scanning cycle //interval - time interval for counting seconds before turning off the relay unsigned long prevMillis = 0; int interval = 1000; //DelayValue - the period during which the relay is kept in the on state int DelayValue = 10; //initSecond - Initialization loop iteration variable int initSecond = 60; //countDelayOff - time interval counter static int countDelayOff = 0; //trigger - motion sensor trigger flag static bool trigger = false; void setup() ( //Standard procedure for initializing the port to which the relay module is connected //IMPORTANT!!! - in order for the relay module to remain in the initially off state //and not trigger during initialization, you need to write //the value HIGH to the input/output port , this will avoid false “clicking”, and will //preserve the state of the relay as it was before the entire circuit was put into operation pinMode(relout, OUTPUT); digitalWrite(relout, HIGH); //Everything is simple here - we wait until 60 ends cycles (initSecond variable) //lasting 1 second, during which time the sensor “self-initializes” for(int i = 0; i< initSecond; i ++) { delay(1000); } } void loop() { //Считать значение с аналогового порта А0 //Если значение выше 500 if(analogRead(A0) >500) ( //Set the motion sensor trigger flag if(!trigger) ( trigger = true; ) ) //While the motion sensor trigger flag is set while(trigger) ( //Execute the following instructions //Save in the currMillis variable //the value of milliseconds elapsed since the start //of program execution unsigned long currMillis = millis(); //Compare with the previous value of milliseconds //if the difference is greater than the specified interval, then: if(currMillis - prevMillis > interval) ( //Save the current value of milliseconds to a variable prevMillis prevMillis = currMillis; //Check the delay counter by comparing it with the value of the period //during which the relay should be kept in the ON state if(countDelayOff >= DelayValue) ( ​​//If the value is equal, then: //reset the sensor activation flag movement trigger = false; //Reset the delay counter countDelayOff = 0; //Turn off the relay digitalWrite(relout, HIGH); //Abort the cycle break; ) else ( //If the value is still less, then //Increment the delay counter by one countDelayOff++; //Keep the relay in the on state digitalWrite(relout, LOW); ) ) ) )

The program contains the following structure:

unsigned long prevMillis = 0;

int interval = 1000;

...

unsigned long currMillis = millis();

if(currMillis - prevMillis > interval)

{

prevMillis = currMillis;

....

// Our operations are enclosed in the body of the structure

....

}

To clarify, it was decided to comment separately on this design. So, this design allows you to perform a parallel task in the program. The body of the structure operates approximately once per second, this is facilitated by the variable interval. First, the variable currMillis the value returned when calling the function is assigned millis(). Function millis() returns the number of milliseconds that have passed since the beginning of the program. If the difference currMillis - prevMillis greater than the value of the variable interval then this means that more than a second has already passed since the start of the program execution, and you need to save the value of the variable currMillis into a variable prevMillis then perform the operations contained in the body of the structure. If the difference currMillis - prevMillis less than the variable value interval, then a second has not yet passed between program scanning cycles, and the operations contained in the body of the structure are skipped.

Well, at the end of the article, a video from the author:

Please enable javascript for comments to work.

In this tutorial we will show you how to make a motion sensor using an ultrasonic sensor (HC-SR04), which will turn on the LED every time. The components for this lesson can be ordered at any convenient store, and eventually on our website.

The lesson is suitable for beginners, but will also be interesting for more experienced engineers.

Below is the entire list of components that we will need for our lesson.

1 x Arduino Board (we used Arduino Uno)
1 x LED (LED, color does not matter)
1 x Resistor/Resistance 220 ohm
1 x Development board
1 x Arduino USB cable
1 x 9V battery with clip (optional)
6 x Wires

Step 2: Positioning Parts

First connect the ultrasonic sensor and LED on the breadboard. Connect the short LED cable (cathode) to the GND (ground) pin of the sensor. Then install the resistor in the same row as the longer LED wire (anode) so that they are connected.

Step 3: Connecting the Parts

Now you need to connect some wires on the back of the sensor. There are four pins - VCC, TRIG, ECHO and GND. After inserting the wires, you need to make the following connections:

End the resistor to a digital pin of your choice, just remember to change it later in the code.

Sensor -> Arduino
VCC -> 5V (power)
TRIG -> 5*
ECHO -> 4*
GND -> GND (ground)

* - can be connected to any two Arduino digital pins, just make sure you change them in the code later.

Now you can connect the Arduino to your computer using a USB cable. Open the Arduino software and download the code which you can find below. The constants are commented so you know exactly what they do and can probably change them.

Const int ledPin = 6; // Digital LED output const int trigPin = 5; // Digital output for connecting TRIG const int echoPin = 4; // Digital output for connecting ECHO const int ledOnTime = 1000; // Time the LED remains on after motion is detected (in milliseconds, 1000 ms = 1 s) const int trigDistance = 20; // Distance (and smaller value) at which the sensor is triggered (in centimeters) int duration; int distance; void setup() ( pinMode(ledPin, OUTPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); ) void loop() ( digitalWrite(trigPin, LOW); digitalWrite(trigPin, HIGH); delay(1) ; digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration * 0.034 / 2; if (distance<= trigDistance) { digitalWrite(ledPin, HIGH); delay(ledOnTime); digitalWrite(ledPin, LOW); } delay(100); }

Step 5: Final Result (video)

The final result of the motion sensor and its operation can be seen in the video below.

Happy projects everyone!

PrincipleworkPIR (Passive Infra Red)-sensors

Any object that has a certain temperature becomes a source of electromagnetic (thermal) radiation, including the human body. The wavelength of this radiation depends on temperature and is in the infrared part of the spectrum. This radiation is invisible to the eye and is detected only by sensors. They are also called PIR sensors.

This is an abbreviation for the words “passive infrared” or “passive infrared” sensors. Passive - because the sensors themselves do not emit, but only perceive radiation with a wavelength from 7 to 14 µm.

A person radiates heat. Its thermal image in infrared rays shows the temperature distribution over the surface of the body. Warmer objects appear lighter, colder objects appear darker, because... emit less heat.

The PIR sensor contains a sensing element that responds to changes in thermal radiation. If it remains constant, no electrical signal is generated.

In order for the sensor to respond to movement, special lenses (Fresnel lenses) with several focusing areas are used, which divide the overall thermal picture into active and passive zones located in a checkerboard pattern. A person, being in the area of ​​operation of the sensor, occupies several active zones in whole or in part.

Therefore, even with minimal movement, movement occurs from one active zone to another, which triggers the sensor. The background thermal pattern usually changes very slowly and evenly. The sensor does not respond to it. The high density of active and passive zones allows the sensor to reliably detect the presence of a person even with the slightest movement.



THE BELL

There are those who read this news before you.
Subscribe to receive fresh articles.
Email
Name
Surname
How do you want to read The Bell?
No spam