Wireless alarm system based on Arduino. Home alarm or using a motion sensor and LCD monitor with Arduino What we will use to assemble

Over the past decade, car thefts have occupied one of the most significant places in the structure of crimes committed in the world. This is due not so much to the specific gravity of this category of theft relative to the total number of crimes, but to the significance of the damage caused due to the high cost of cars. The weak effectiveness of measures taken in the field of combating vehicle theft by the end of the 90s led to the creation of stable groups specializing in committing these crimes and possessing distinctive features organized crime; You've probably heard the term "black auto business." The car fleet of European countries annually lacks ≈ 2% of cars that become the subject of criminal attacks. Therefore, I came up with the idea of ​​​​making a GSM alarm for my car based on Arduino Uno.

Let's begin!

What will we collect from?

We need to choose the heart of our system. In my opinion, for such signaling there is nothing better than Arduino Uno. The main criterion is a sufficient number of “pins” and price.


Key Features of Arduino Uno

Microcontroller - ATmega328
Operating voltage - 5 V
Input voltage (recommended) - 7-12 V
Input voltage (limit) - 6-20 V
Digital Inputs/Outputs - 14 (6 of which can be used as PWM outputs)
Analog inputs - 6
Constant current through input/output - 40 mA
Constant current for output 3.3V - 50mA
Flash memory - 32 KB (ATmega328) of which 0.5 KB is used for the bootloader
RAM - 2 KB (ATmega328)
EEPROM - 1 KB (ATmega328)
Clock frequency - 16 MHz


Fits!

Now you need to select a GSM module, because our alarm system must be able to notify the car owner. So, you need to google it... Here, an excellent sensor - SIM800L, the size is simply wonderful.


I thought and ordered it from China. However, everything turned out to be not so rosy. The sensor simply refused to register the SIM card on the network. Everything possible was tried - the result was zero.
Found good people who provided me with more cool thing- Sim900 Shield. Now this is a serious thing. The Shield has both a microphone and headphone jack, making it a full-fledged phone.


Key Features of Sim900 Shield

4 operating frequency standards 850/ 900/ 1800/ 1900 MHz
GPRS multi-slot class 10/8
GPRS mobile station class B
Complies with GSM phase 2/2+
Class 4 (2 W @850/ 900 MHz)
Class 1 (1 W @ 1800/1900MHz)
Control using AT commands (GSM 07.07, 07.05 and SIMCOM extended AT commands)
Low power consumption: 1.5mA(sleep mode)
Operating temperature range: -40°C to +85°C


Fits!

Ok, but you need to take readings from some sensors in order to notify the owner. If the car is towed away, then the position of the car will obviously change in space. Let's take an accelerometer and a gyroscope. Great. Ok, now we are looking for a sensor.

I think that the GY-521 MPU6050 will definitely fit. It turned out that it also has a temperature sensor. We should use it too, there will be such a “killer feature”. Let's assume that the owner of the car parked it under his house and left. The temperature inside the car will change “smoothly”. What happens if an intruder tries to break into the car? For example, he will be able to open the door. The temperature in the car will begin to change rapidly as the air in the cabin begins to mix with the air environment. I think it will work.


Main Features of GY-521 MPU6050

3-axis gyroscope + 3-axis accelerometer GY-521 module on MPU-6050 chip. Allows you to determine the position and movement of an object in space, angular velocity during rotation. It also has a built-in temperature sensor. It is used in various copters and aircraft models; a motion capture system can also be assembled based on these sensors.

Chip - MPU-6050
Supply voltage - from 3.5V to 6V (DC);
Gyro Range - ±250 500 1000 2000°/s
Accelerometer range - ±2±4±8±16g
Communication interface - I2C
Size - 15x20 mm.
Weight - 5 g


Fits!

A vibration sensor will also come in handy. Suddenly they try to open the car with “brute force”, or in the parking lot another car hits your car. Let's take the vibration sensor SW-420 (adjustable).


Main characteristics of SW-420

Supply voltage - 3.3 - 5V
Output signal - digital High/Low (normally closed)
Sensor used - SW-420
The comparator used is LM393
Dimensions - 32x14 mm
Additionally - There is an adjustment resistor.


Fits!

Screw on the SD memory card module. We will also write a log file.


Main characteristics of the SD memory card module

The module allows you to store, read and write to an SD card the data required for the operation of a device based on a microcontroller. The use of the device is relevant when storing files from tens of megabytes to two gigabytes. The board contains an SD card container, a card power stabilizer, and a connector plug for interface and power lines. If you need to work with audio, video or other large-scale data, for example, keep a log of events, sensor data or store web server information, then the SD memory card module for Arduino will make it possible to use an SD card for these purposes. Using the module, you can study the features of the SD card.
Supply voltage - 5 or 3.3 V
SD card memory capacity - up to 2 GB
Dimensions - 46 x 30 mm


Fits!

And let's add a servo drive; when the sensors are triggered, the servo drive with the video recorder will turn and shoot a video of the incident. Let's take the MG996R servo drive.


Main Features of MG996R Servo Drive

Stable and reliable protection from damage
- Metal drive
- Double row ball bearing
- Wire length 300 mm
- Dimensions 40x19x43mm
- Weight 55 g
- Rotation angle: 120 degrees.
- Operating speed: 0.17sec/60 degrees (4.8V no load)
- Operating speed: 0.13sec/60 degrees (6V no load)
- Starting torque: 9.4kg/cm at 4.8V power supply
- Starting torque: 11kg/cm at 6V power supply
- Operating voltage: 4.8 - 7.2V
- All drive parts are made of metal


Fits!

We collect

There are a huge number of articles on Google about connecting each sensor. And I have no desire to invent new bicycles, so I will leave links to simple and working options.

GSM alarm system on Arduino

In this article you will learn how to (buy) make a GSM alarm yourself using a GSM module and Arduino very cheaply. The object of GSM alarm security is ideal a dacha will do, house, garage, apartment.


Step 1: Elements
For this project you will need:


GSM Shield

Buzzer
Alarm siren 12V
12V power supply

Keyboard for Arduino
Frame.

Step 2: Connecting Components


First you place GSM module on Arduino Uno, you will need to solder the GND and VCC wires along with two sensors, a buzzer and a relay module input. After that, connect these soldered wires to the corresponding connector of the GSM shield. Next you will make an I/O signal connector from these parts, and the last thing you will need to do is connect the keyboard

Arduino Uno/GSM Terminals:

Pin 0: not connected;
Conclusion 1: not related;
Pin 2: unconnected (GSM will use this pin);
Pin 3: unconnected (GSM will use this pin);
Pin 4: last line using keyboard (keyboard pin 4 - from 8);
Conclusion 5: unrelated;
Pin 6: second column via keyboard (keyboard pin 6 - from 8);
Output 7: third column from the keyboard (finger keyboard 7 - from 8);
Pin 8: unconnected (GSM will use this pin);
Pin 9: unconnected (GSM will use this pin);
Pin 10: PIR sensor data No. 2;
Conclusion 11: siren sound signal(enters the relay module input);
Pin 12: PIR sensor data No. 1;
Pin 13: buzzer input signal;

As you can see, although the keyboard has 8 pins, only three are connected (one row and two columns, allowing two numbers to be read - a 1×2 matrix), so I can make passwords using these three wires and there is no need to use all contacts from the keyboard. This is because once the motion sensor detects a person walking in the room, the person will only have 5 seconds to turn off the alarm. After the alarm is not turned off at a given time, the GSM shield sends an SMS to you, or calls your phone number. The Arduino has been programmed to make a call and as soon as you answer the phone it will hang up.

Of course, it is possible to get false readings from the sensor, so there is an option to turn off the alarm by simply sending an SMS from your phone to the Arduino. Additionally, another option that you can do is to set the shield to send you one message per day so that you know that it is working correctly.

Step 3: Code

Just download the code below and compile. It uses the Keypad.h and GSM.h libraries.
Download file: (downloads: 181)
Download file: (downloads: 104)

Step 4: Conclusion


Given that the Arduino Uno code will text and call your phone in just five seconds after someone breaks into your home, I'm guessing you'll have plenty of time to call the police. Of course, the siren will scare away thieves and your home or other premises will become safer with the help of this article.

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 intrusion. Arduino help, 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 IR 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(); // Similar to lcd.setCursor(0, 0); lcd.print("Processing Data."); delay(3000); lcd.clear(); 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 there was no movement until this moment, then we display a message // that it was detected // The code below is needed 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); } }

Over the past decade, car thefts have occupied one of the most significant places in the structure of crimes committed in the world. This is due not so much to the specific gravity of this category of theft relative to the total number of crimes, but to the significance of the damage caused due to the high cost of cars. The weak effectiveness of measures taken in the field of combating vehicle theft by the end of the 90s led to the creation of stable groups specializing in the commission of these crimes and having the distinctive features of organized crime; You've probably heard the term "black auto business." The car fleet of European countries annually lacks ≈ 2% of cars that become the subject of criminal attacks. Therefore, I came up with the idea of ​​​​making a GSM alarm for my car based on Arduino Uno.

Let's begin!

What will we collect from?

We need to choose the heart of our system. In my opinion, for such signaling there is nothing better than Arduino Uno. The main criterion is a sufficient number of “pins” and price.


Key Features of Arduino Uno

Microcontroller - ATmega328
Operating voltage - 5 V
Input voltage (recommended) - 7-12 V
Input voltage (limit) - 6-20 V
Digital Inputs/Outputs - 14 (6 of which can be used as PWM outputs)
Analog inputs - 6
Constant current through input/output - 40 mA
Constant current for output 3.3V - 50mA
Flash memory - 32 KB (ATmega328) of which 0.5 KB is used for the bootloader
RAM - 2 KB (ATmega328)
EEPROM - 1 KB (ATmega328)
Clock frequency - 16 MHz


Fits!

Now you need to select a GSM module, because our alarm system must be able to notify the car owner. So, you need to google it... Here, an excellent sensor - SIM800L, the size is simply wonderful.


I thought and ordered it from China. However, everything turned out to be not so rosy. The sensor simply refused to register the SIM card on the network. Everything possible was tried - the result was zero.
There were kind people who provided me with a cooler thing - Sim900 Shield. Now this is a serious thing. The Shield has both a microphone and headphone jack, making it a full-fledged phone.


Key Features of Sim900 Shield

4 operating frequency standards 850/ 900/ 1800/ 1900 MHz
GPRS multi-slot class 10/8
GPRS mobile station class B
Complies with GSM phase 2/2+
Class 4 (2 W @850/ 900 MHz)
Class 1 (1 W @ 1800/1900MHz)
Control using AT commands (GSM 07.07, 07.05 and SIMCOM extended AT commands)
Low power consumption: 1.5mA(sleep mode)
Operating temperature range: -40°C to +85°C


Fits!

Ok, but you need to take readings from some sensors in order to notify the owner. If the car is towed away, then the position of the car will obviously change in space. Let's take an accelerometer and a gyroscope. Great. Ok, now we are looking for a sensor.

I think that the GY-521 MPU6050 will definitely fit. It turned out that it also has a temperature sensor. We should use it too, there will be such a “killer feature”. Let's assume that the owner of the car parked it under his house and left. The temperature inside the car will change “smoothly”. What happens if an intruder tries to break into the car? For example, he will be able to open the door. The temperature in the car will begin to change rapidly as the air in the cabin begins to mix with the ambient air. I think it will work.


Main Features of GY-521 MPU6050

3-axis gyroscope + 3-axis accelerometer GY-521 module on MPU-6050 chip. Allows you to determine the position and movement of an object in space, angular velocity during rotation. It also has a built-in temperature sensor. It is used in various copters and aircraft models; a motion capture system can also be assembled based on these sensors.

Chip - MPU-6050
Supply voltage - from 3.5V to 6V (DC);
Gyro Range - ±250 500 1000 2000°/s
Accelerometer range - ±2±4±8±16g
Communication interface - I2C
Size - 15x20 mm.
Weight - 5 g


Fits!

A vibration sensor will also come in handy. Suddenly they try to open the car with “brute force”, or in the parking lot another car hits your car. Let's take the vibration sensor SW-420 (adjustable).


Main characteristics of SW-420

Supply voltage - 3.3 - 5V
Output signal - digital High/Low (normally closed)
Sensor used - SW-420
The comparator used is LM393
Dimensions - 32x14 mm
Additionally - There is an adjustment resistor.


Fits!

Screw on the SD memory card module. We will also write a log file.


Main characteristics of the SD memory card module

The module allows you to store, read and write to an SD card the data required for the operation of a device based on a microcontroller. The use of the device is relevant when storing files from tens of megabytes to two gigabytes. The board contains an SD card container, a card power stabilizer, and a connector plug for interface and power lines. If you need to work with audio, video or other large-scale data, for example, keep a log of events, sensor data or store web server information, then the SD memory card module for Arduino will make it possible to use an SD card for these purposes. Using the module, you can study the features of the SD card.
Supply voltage - 5 or 3.3 V
SD card memory capacity - up to 2 GB
Dimensions - 46 x 30 mm


Fits!

And let's add a servo drive; when the sensors are triggered, the servo drive with the video recorder will turn and shoot a video of the incident. Let's take the MG996R servo drive.


Main Features of MG996R Servo Drive

Stable and reliable protection against damage
- Metal drive
- Double row ball bearing
- Wire length 300 mm
- Dimensions 40x19x43mm
- Weight 55 g
- Rotation angle: 120 degrees.
- Operating speed: 0.17sec/60 degrees (4.8V no load)
- Operating speed: 0.13sec/60 degrees (6V no load)
- Starting torque: 9.4kg/cm at 4.8V power supply
- Starting torque: 11kg/cm at 6V power supply
- Operating voltage: 4.8 - 7.2V
- All drive parts are made of metal


Fits!

We collect

There are a huge number of articles on Google about connecting each sensor. And I have no desire to invent new bicycles, so I will leave links to simple and working options.

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 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 circuits actuators, 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 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 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 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 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.
Share