Intrusion Detector | MindPlus Coding Kit for Arduino Started Tutorial E15

0 4380 Easy

In the film Entrapment, there is a breathtaking scene when Virginia steals the famous painting. And what exactly are the red lines we see in the film? Is it visible to the human eyes? Let's find out.


Task Navigation

1. Learn about infrared ranging

2. Making an infrared intrusion detector

Key Points Analysis


1. Infrared Rays

Infrared is an electromagnetic wave with a wavelength between microwave and visible light, which is between 1mm and 760 nanometers (nm). It’s an invisible light that has longer wavelength than red light.

Anything above absolute zero (-273.15 ° C) can generate infrared rays. Modern physics calls it heat rays. Medical infrared can be divided into two categories: near infrared and far infrared. Infrared rays contain heat and that’s most of the sun’s heat is transmitted to earth.

As shown in the figure, we call radiation outside red light infrared rays (and radiation outside purple light is called ultraviolet), which is invisible to the human eyes.

2. Infrared sensor


Infrared Obstacle Avoidance Switch

The button module used in Chapter II is a very typical digital input sensor. When we press the button, the signal port of the module will maintain high level; when the button is released, the signal port will maintain low level.

Are there any digital sensors that output signals without contatct?

Infrared obstacle avoidance switch. When an object approaches it, the yellow signal line will output a low level and the red LED on the sensor will light up; when the object is removed, it will output a high level and the red LED will go out.

There is another version with slightly different pins, brown -- + 5V; blue -- ground; black -- signal.

Command List



Hardware connection

Connect the infrared obstacle avoidance switch to Digital Pin 3, and the RGB light module to Digital Pin 10.


Hardware connection (IR obstacle avoidance switch --3, RGB light module --10)

Please match the colors when plugging


In the Adjustable Light chapter we learned how to control the LED brightness, with an primitive understanding of the mechanism of the RGB lights : RGB color mode uses the the RGB model give a intensity value between 0 and 255 to every RGB component in every pixel in the image. Various colors are constituted through different intensities in three primary colors, red, green, and blue.

In fact, controlling RGB colors is not easy. Fortunately, the software has ready-made modules to reduce programming difficulty.

1. Write the program

Open "Extensions" and select "RGB Lights" in "Monitor":


You might ask questions that why it’s a strap of lights? The RGB light module we actually use is only one light bulb of the them. This module is also applicable to single RGB bulb, which can be cascaded by wires.


2. Reference program


3. Program results

When the device is placed in an unoccupied room, RGB displays yellow; when someone enters the room and the device detects him/her, RGB displays red.

4. Program analysis

Why set "0 to 0 display"? We are accustomed to counting from 1, while computers count from 0. From "0 to 0" means only one RGB light is turned on. It starts with the first LED with index 0 and ends with the first LED at index 0.


If you want to see the data output in real time, remember to add building blocks


Further reading

How did humans discover infrared?

How can a dark place be "hotter" than a bright place? The story begins at two centuries ago.

Before 1800s, people now the “white” light of sunlight can be dispersed into red, orange, yellow, green, blue, indigo, and violet lights. This experiment was first successfully carried by the famous Newton in 1666. 100 years later, nobody bothered to think what else exists besides these seven colors.

However, William Herschel (1738-1822), a British physician and astronomer who was born in Germany, came up with a whimsy. What exists “beyond” these seven visible lights in those invisible areas? So, he did the following experiment in 1800.

He made the sunlight pass through a prism and refract it to the white paper screen on the back. Of course, he also got seven colors like Newton. The difference is that this time he also put nine identical thermometers in each color area. Seven were put in every color area, while the last two were put “outside” red and purple. With the illumination of colorful light refracted by the sunlight, the temperature of the thermometers in the seven visible light areas have increased. For example, the temperatures of red, green, and purple areas have each increased by 5 °C, 3 °C, and 2 °C; but the temperature outside the purple light has not increased. He also found that the temperature outside the red-light area not only increased, but also rose even higher than the red-light area, by 7 °C! This was a surprise -- there was no light there!

Would the temperature be higher in the area farther from the red? Then he moved the thermometer to an area farther from the red area, but the temperature did not increase at this time, dropped to room temperature instead. After repeated experiments and researches, he finally determined that "infrared" or "infrared radiation" exists in the area near the red light. He also demonstrated with experiments that, infrared rays, no matter from earth or sun or other sources, also obeys the laws of refraction and refraction just like visible lights. But it is more easily absorbed by air than visible light. Because it is "invisible", it was called "invisible radiation" when it was first discovered.

Further Exercise

Now that you have learned to make a light warning device, review the previous chapter and try adding a buzzer warning function to it!

icon Program 6-2 E15.rar 165KB Download(0)
All Rights