Part I Introduction to a problem

Robots and portable electronics in general uses batteries to stay powered on. Battery technology has improved dramatically in recent years, allowing us to use our devices longer on one charge. But even the best batteries are not unlimited and so oftentimes we need to conserve the energy used by device - one of the ways to do that is to put device in sleep mode and only activate it when needed. In this lesson we’re going to do the same with Bittle by using a new sensor - Grove PIR Motion sensor.

Part II Explaining the knowledge

How can we detect motion?

In many instances we can judge on whether or not an electronic device needs to be activated by detecting motion. One of the most common examples of this technology in use is motion activated light bulbs. Inside of it there is a motion sensor, which when activated lights up the light bulb. There are a few different ways we can detect motion - for example we can shine infrared light into the environment and detect the changes in reflected infrared light. That would be active infrared motion sensor, the word “active” denoting that we actively interact with environment in order to get the measurement. Same principle can be applied if you’d like to use sound waves or radio waves - release them into the environment and look for changes in reflected signal.
But active interaction with environment uses energy by itself - so, instead we could passively monitor the environment for changes. The best “channel” to monitor if we want to detect movement of humans or animals is infrared light.

What is Infrared Light or Infrared Radiation?

In earlier lessons we have already familiarized ourselves with concept of visible light - that it is a form of electromagnetic radiation that our eyes can perceive.

Lesson 7 PIR motion sensor - Always on guard - 图1
Inferred spectrum waves are longer than light which humans can see and shorter than microwaves. The word infrared means below red. It comes from the Latin word infra (meaning below) and the English word red. Despite you cannot see infrared radiation you can feel it - as heat. The hotter something is the more infrared waves it emits.
This for example is the image of a dog in infrared.

Lesson 7 PIR motion sensor - Always on guard - 图2
You can see that the parts that are hotter, such as mouth and eyes are brighter and nose (which is normally cold in healthy dogs) is darker. Mammals regulate their body temperature and keep it at constant level.
Passive infrared (PIR) sensors are sensitive to a person’s skin temperature, in contrast to background objects at room temperature.
Lesson 7 PIR motion sensor - Always on guard - 图3
No energy is emitted from the sensor, thus the name passive infrared. These devices can detect objects, people, or animals by picking up one’s infrared radiation. When an object, such as a person, passes in front of the background, such as a wall, the temperature at that point in the sensor’s field of view will rise from room temperature to body temperature, and then back again. The sensor converts the resulting change in the incoming infrared radiation into a change in the output voltage, and this triggers the detection.

Part III Solving a problem

Task 1: Read raw data from sensor

Let’s test motion sensor by outputting it’s values to Serial monitor.
Lesson 7 PIR motion sensor - Always on guard - 图4
Connect PIR Motion sensor to Grove Digital Sokcet D6 and upload the following code (you can find PIR Motion Sensor block under Grove Digital category):
7-1.png
7-1

Then connect to the device in Codecraft and click on the Serial Monitor.

企业微信截图_20210304185203.png
Wave your hand over the mini PIR motion sensor, then the serial port reading will change from 0 to 1, as shown in the picture below. It means the sensor is working properly. 7-2.mp4 (453.91KB)

Task 2: Activate Bittle with PIR motion sensor

For the next ask, we’re going to make Bittle make a greeting gesture if motion is detected.
7-2.png
7-2

Pay attention to a little 10 millisecond delay in the end of the loop - it is necessary to get proper readings from PIR Motion sensor.
Lesson 7 PIR motion sensor - Always on guard - 图9

Task 3: Combine PIR motion sensor with Vision sensor

We have mentioned in the beginning of this lesson, that one of the application scenarios for PIR motion sensor is energy conservation. Inside BIttle Sensor pack there is a sensor that has particularly high energy consumption - Vision sensor. We can create a program that will first check if there is a movement detected and only if there is movement will activate the Vision sensor.
7-3.png
7-3

That will help us to preserve Bittle’s battery. 7-1.mp4 (9.47MB)

Part IV Expanding the knowledge

Use PIR motion sensor and Ultrasonic ranger to create a guard robot, that would patrol the area when motion is detected.