Connecting Sapsan wireless motion sensors to Arduino. GSM security system for home based on Arduino

Its author wanted to do a homemade project so that it would be cheap and wireless.
This homemade product uses a PIR motion sensor, and information is transmitted using an RF module.

The author wanted to use the infrared module, but since it has a limited range, plus it can work only line of sight with the receiver, so he chose an RF module with which he can achieve a range of approximately 100 meters.


In order to make it more convenient for visitors to view the alarm assembly, I decided to divide the article into 5 stages:
Stage 1: Creating a transmitter.
Stage 2: Create a receiver.
Stage 3: Software installation.
Stage 4: Testing of assembled modules.
Stage 5: Assembling the case and installing the module into it.

All the author needed was:
- 2 ARDUINO UNO/ARDUINO MINI/ARDUINO NANO boards for receiver and transmitter;
- RF transceiver module (433 MHZ);
- PIR motion sensor;
- 9V batteries (2 pieces) and connectors for them;
- Buzzer;
- LED;
- Resistor with a resistance of 220 Ohms;
- Development board;
- Jumpers/wires/jumpers;
- Circuit board;
- Board-to-board pin connectors;
- Switches;
- Housings for receiver and transmitter;
- Colored paper;
- Mounting tape;
- Typesetting scalpel;
- Hot glue gun;
- Soldering iron;
- Wire cutters/insulation stripping tool;
- Metal scissors.


Stage 1.
Let's start creating the transmitter.
Below is a diagram of how the motion sensor works.


The transmitter itself consists of:
- Motion sensor;
- Arduino boards;
- Transmitter module.


The sensor itself has three outputs:
- VCC;
- GND;
- OUT.

After that, I checked the operation of the sensor


Attention!!!
Before downloading the firmware, the author makes sure that Arduino settings IDE the current board and serial port are installed correctly. Then I uploaded the sketch:

Later, when the motion sensor detects movement in front of you, the LED will light up, and you will also be able to see a corresponding message on the monitor.


According to the diagram below.


The transmitter has 3 pins (VCC, GND, and Data), connect them:
- VCC > 5V output on the board;
- GND > GND ;
- Data > 12 pins on the board.

Stage 2.


The receiver itself consists of:
- RF receiver module;
- Arduino boards
- Buzzer (speaker).

Receiver Circuit:


The receiver, like the transmitter, has 3 pins (VCC, GND, and Data), connect them:
- VCC > 5V output on the board;
- GND > GND ;
- Data > 12 pins on the board.


Stage 3.
The author chose file libraries as the basis for the entire firmware. I downloaded it and placed it in the Arduino libraries folder.

Transmitter software.
Before uploading the firmware code to the board, the author set the following IDE parameters:
- Board -> Arduino Nano (or the board you are using);
- Serial Port ->


After setting the parameters, the author downloaded the Wireless_tx firmware file and uploaded it to the board:

Receiver software
The author repeats the same steps for the receiving board:
- Board -> Arduino UNO (or the board you are using);
- Serial Port -> COM XX (check the com port to which your board is connected).



After the author has set the parameters, he downloads the wireless_rx file and loads it into the board:


Afterwards, using a program that can be downloaded, the author generated a sound for the buzzer.

Stage 4.
Next, after downloading the software, the author decided to check if everything was working properly. The author connected the power supplies and passed his hand in front of the sensor, and the buzzer started working, which means everything is working as it should.


Stage 5.
Final assembly of the transmitter
First, the author cut off the protruding leads from the receiver, transmitter, arduino boards, etc.


After that, I connected the arduino board with the motion sensor and RF transmitter using jumpers.


Next, the author began making a housing for the transmitter.

First he cut: a hole for the switch, and also round hole for a motion sensor, and then glued it to the body.




Then the author rolled up a sheet of colored paper and glued it to the front cover of the image in order to hide the internal parts of the homemade product.


After which, the author began to insert the electronic filling inside the case using double-sided tape.



Final assembly of the receiver
The author decided to connect the Arduino board to the circuit board rubber band, and also install an RF receiver.


Next, the author cuts two holes on the other case, one for the buzzer, the other for the switch.


And sticks it.


After which, the author installs jumpers on all parts.




Then the author inserts the finished board into the case and secures it with double-sided glue.

Hello, dear reader! Today's article is about creating a simple home system safety using available components. This small and cheap device will help you protect your home from intruders using an Arduino, motion sensor, display and speaker. The device can be powered by a battery or a computer’s USB port.

So let's begin!

How does it work?

The bodies of warm-blooded animals emit infrared radiation, which is invisible to human eyes, but can be detected using sensors. Such sensors are made of a material that can spontaneously polarize when exposed to heat, making it possible to detect the appearance of heat sources within the range of the sensor.

For a wider range, Fresnel lenses are used, which collect infrared radiation from different directions and concentrate it on the sensor itself.

The figure shows how the lens distorts the rays that fall on it.

It is worth noting that robots without particularly hot parts and cold-blooded ones emit very little infrared radiation, so the sensor may not work if Boston Dynamics employees or reptilians decide to surround you.

When there is a change in the level of IR radiation in the range, this will be processed on the Arduino, after which the status will be displayed on the LCD display, the LED will blink, and the speaker will beep.

What do we need?

  1. (or any other board).
  2. (16 characters on two lines)
  3. One connector for connecting the crown to Arduino
  4. (although you can use a regular speaker)
  5. USB cable - for programming only ( approx. translation: It always comes with our Arduino!)
  6. Computer (again, only for writing and loading the program).

By the way, if you don’t want to buy all these parts separately, we recommend that you pay attention to ours. For example, everything you need and even more is in our starter kit.

Let's connect!

Connecting a motion sensor is very simple:

  1. We connect the Vcc pin to 5V Arduino.
  2. We connect the Gnd pin to GND of the Arduino.
  3. We connect the OUT pin to digital pin No. 7 from Arduino

Now let's connect the LED and speaker. It's just as simple here:

  1. We connect the short leg (minus) of the LED to ground
  2. We connect the long leg (plus) of the LED to output No. 13 of the Arduino
  3. Red speaker wire to output No. 10
  4. Black wire - to ground

And now the hard part is connecting the 1602 LCD display to the Arduino. We have a display without I2C, so we will need a lot of Arduino outputs, but the result will be worth it. The diagram is presented below:

We only need part of the circuit (we will not have contrast adjustment with a potentiometer). Therefore, you only need to do the following:

Now you know how to connect a 1602 display to the Arduino UNO R3 (as well as to any version of Arduino from Mini to Mega).

Programming

It's time to move on to programming. Below is the code that you just need to fill in and, if you have assembled everything correctly, the device is ready!

#include int ledPin = 13; // LED pin int inputPin = 7; // Pin to which Out of the motion sensor is connected int pirState = LOW; // Current state (nothing detected at the beginning) int val = 0; // Variable for reading the state of digital inputs int pinSpeaker = 10; // The pin to which the speaker is connected. Requires PWM pin LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize the LCD display void setup() ( // Determine the direction of data transmission on digital pins pinMode(ledPin, OUTPUT); pinMode(inputPin, INPUT); pinMode(pinSpeaker, OUTPUT); // Start output of debugging information via the Serial serial port .begin(9600); // Start output to the LCD display lcd.begin(16, 2); // Set the index on the displays from which we will start output // (2 characters, 0 lines) lcd.setCursor(2, 0) ; // Output to the LCD display lcd.print("P.I.R Motion"); // Move again lcd.setCursor(5, 1); // Output lcd.print("Sensor"); // Pause to have time to read, what was output delay(5000); // Clearing lcd.clear(); // Same as lcd.setCursor(0, 0); lcd.print("Processing Data."); lcd.setCursor(3, 0); lcd.print("Waiting For"); lcd.setCursor(3, 1); lcd.print("Motion...."); void loop() ( // Read sensor reading val = digitalRead(inputPin); if (val == HIGH) ( // If there is movement, then light the LED and turn on the siren digitalWrite(ledPin, HIGH); playTone(300, 300); delay(150); // If the movements are before at this moment was not, then we display a message // that it was detected // The code below is needed in order to write only a state change, and not print the value every time if (pirState == LOW) ( Serial.println("Motion detected!"); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Motion Detected!"); pirState = HIGH; ) else ( // If the motion is over digitalWrite(ledPin, LOW); playTone(0, 0); delay(300); if (pirState == HIGH)( // Inform that there was movement, but it has already ended Serial.println("Motion ended!"); lcd.clear(); lcd.setCursor(3, 0); lcd.print("Waiting For"); lcd.setCursor(3, 1); lcd.print("Motion...."); pirState = LOW; ) ) // Sound playback function. Duration (duration) - in milliseconds, Freq (frequency) - in Hz void playTone(long duration, int freq) ( duration *= 1000; int period = (1.0 / freq) * 100000; long elapsed_time = 0; while (elapsed_time< duration) { digitalWrite(pinSpeaker,HIGH); delayMicroseconds(period / 2); digitalWrite(pinSpeaker, LOW); delayMicroseconds(period / 2); elapsed_time += (period); } }

This project concerns the development and improvement of a system to prevent/control any attempts at infiltration by thieves. Developed security device uses an embedded system (includes a hardware microcontroller using open source software and a gsm modem) based on GSM (Global System for Mobile Communications) technology.

A security device can be installed in the house. Interface sensor burglar alarm also connected to a controller-based security system.
When an attempt is made to penetrate, the system sends a warning message (for example, sms) to the owner on mobile phone or to any pre-configured mobile phone for further processing.

The security system consists of a microcontroller Arduino Uno and a standard SIM900A modem based on GSM/GPRS. The whole system can be powered by any 12V 2A power source/battery.

Below is a diagram of an Arduino-based security system.

The operation of the system is very simple and does not require explanation. When power is supplied to the system, it goes into standby mode. When J2 connector pins are shorted, a pre-programmed warning message is sent to the required mobile number. You can connect any intrusion detector (such as a light guard or motion sensor) to the J2 input connector. Note that an active-low (L) signal on pin 1 of connector J2 will activate the burglar alarm.

Moreover, an optional “call-alarm” device has been added to the system. It activates phone call when the user presses button S2 (or when another electronic unit initiates an alarm). After pressing the “call” button (S2), the call can be canceled by pressing another button S3 – the “end” button. This option can be used to generate a “missed call” alarm in case of intrusion.

The circuit is very flexible, so it can use any SIM900A modem (and, of course, the Arduino Uno board). Please read the modem documentation carefully before starting assembly. This will make the system manufacturing process easier and more enjoyable.

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
Arduino board

Arduino Uno

1 To notepad
GSM/GPRS modemSIM900A1 To notepad
IC1 Linear regulator

LM7805

1 To notepad
C1 100uF 25V1 To notepad
C2 Electrolytic capacitor10uF 16V1 To notepad
R1 Resistor

1 kOhm

1 To notepad
LED1 LED 1 To notepad
S1 ButtonWith fixation1

Today we will talk about how to use Arduino collect security system. Our “security” will guard one circuit and control one siren.

For Arduino this is not a problem, and, as you will see from the program code and the device diagram, you can easily increase the number of protected access points and the number of notification or indication devices.
Security system can be used to protect both large objects (buildings and structures), and small items (boxes, safes), and even portable cases and suitcases. Although you need to be careful with the latter, if you install a security system, for example, on a suitcase with which you decide to travel, and the warning system goes off at some airport, then I think you will have a serious conversation with the local security service :-)

A simplified operating principle of the device is as follows (Fig. 1). After turning on the power, the device goes into operating mode and waits for arming. Arming and disarming are carried out with one button. To increase security, it is better to place this button inside a protected area (safe or box). Before turning on the security mode, the door must be opened slightly. When you turn on the security mode (press the button) electronic circuit waits until you close the door to the room (safe door, box lid, etc.).

A limit switch of any type must be installed on the door (or door), more on that later. By closing (or opening), the limit switch will inform the device that the protected circuit is closed, and the device will go into security mode. The system will notify you about entering the security mode with two short signals (like in car alarms). In this mode, the device “catches” the opening of the door. After opening the door, the system waits a few seconds (this value is adjustable, about ten seconds for rooms, one or two for a box) for the security mode to turn off; if this does not happen, the siren turns on. The algorithm and circuit are designed in such a way that you can turn off the siren only by completely disassembling the housing and turning off the power.

Device security system very simple (Fig. 2). Based on the board Arduino. The limit switches are connected like a regular button, through pull-up resistors. I will dwell separately on the end switches. They are either normally closed or normally open. You can turn on a regular button as a limit switch, only the travel of a regular button is very large, the door backlash is usually greater. Therefore, it is necessary to come up with some kind of pusher for the button and spring it so as not to break the button with the door. Well, if you’re not too lazy, you can go to the store and buy a magnetic switch (reed switch) (Fig. 3), it is not afraid of dust and dirt.

A limit switch for car alarms is also suitable (Fig. 4). It should be noted that the program is written for a reed switch. At closed door its contact is closed. If you use a car alarm switch, then when the door is closed it will most likely be open, and in the appropriate places in the code you will need to change 0 to 1 and vice versa.

As a siren, I propose to use the PKI-1 IVOLGA sound siren, produced in Belarus (Fig. 5). Supply voltage 9 - 15 V, operating current 20 - 30 mA. This allows it to be used with battery power. At the same time, it “produces” 95 - 105 dB.

With such characteristics, it will sound for several tens of minutes from a Krona battery. I found it on the Internet for 110 rubles. There, a reed switch with a magnet costs about 30 rubles. The car alarm switch was purchased at auto parts for 28 rubles. The KT315 transistor can be taken with any letter or replaced with any modern low-power silicon transistor of appropriate conductivity. If the volume of one siren is not enough (who knows, maybe you want it to be heard from many kilometers away), you can connect several sirens in parallel or take a more powerful one, only in this case the transistor must be replaced with a more powerful one (for example, the familiar transistor assembly ULN2003). As connectors for connecting the reed switch and siren, I used the simplest connectors for audio/video devices - the price on the radio market is 5 rubles. for a couple.

The device body can be glued together from plastic or plywood; If a serious object is being protected, then it is better to make it metal. To increase reliability and safety, it is advisable to place batteries or accumulators inside the case.

To simplify the program code, energy-saving elements were not used, and the batteries do not last long. You can optimize the code, or even better, radically remake it by using interrupt event processing and MK sleep mode. In this case, power from two square batteries connected in series (9 V) should be enough for several months.

Now the code

// constants
const int button = 12; // pin for the button
const int gerkon = 3; // pin for reed switch
const int sirena = 2; // siren control pin
const int led = 13; // indicator pin
// variables
int buttonState = 0; // button state
int gerkonState = 0; // reed switch state
int N = 0; // disarm button counter
void setup() (
// control siren and indicator - output
pinMode(sirena, OUTPUT);
pinMode(led, OUTPUT); // button and reed switch - inputs
pinMode(gerkon, INPUT);
pinMode(button, INPUT);
}
void loop()
digitalWrite(led, HIGH);
while(buttonState= =0)( // wait loop until we press the button
buttonState = digitalRead(button); // to switch to security mode
}
digitalWrite(led, LOW);
buttonState = 0; // reset the button value
while(gerkonState= =0)( // loop until we close the door

}
delay(500); // :-)
digitalWrite(sirena, HIGH); // Code
delay(100); // indications
digitalWrite(sirena, LOW); // enable
delay(70); // mode
digitalWrite(sirena, HIGH); // security
delay(100); // alert
digitalWrite(sirena, LOW); // sound
while(gerkonState= =1)( // wait for the door to open
gerkonState = digitalRead(gerkon);
}
for (int i=0; i<= 5; i++){ // 7,5 секунды на нажатие
buttonState = digitalRead(button); // secret button
if (buttonState = = HIGH) ( // track ours - someone else's
N=N+1;
}
delay(1500); // secret feature :-)))
}
if (N > 0) ( // the most important thing
digitalWrite(sirena, LOW); // don't turn on the siren
}
else(
digitalWrite(sirena, HIGH); // or turn on the siren
}
digitalWrite(led, HIGH); // turn on the indicator N = 0;
buttonState = 0;
delay(15000); // reminder for dummies who like
digitalWrite(led, LOW); // press the buttons without interruption delay (1000);

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.

Basic technical specifications 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; accordingly, a description is given in the left column 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 an ordinary lamp at 220 volts 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 work assembled circuit:

/* * 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 turning on the entire circuit 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 following instructions//Save in the variable currMillis //the value of milliseconds that have passed since the start of //execution of the program 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 the 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 motion sensor trigger flag trigger = false; //Reset the delay counter countDelayOff = 0; // Turn off the relay digitalWrite(relout, HIGH); //Interrupt the loop 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 is activated 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 there is a video from the author:

Please enable javascript for comments to work.