1 of 23

PIR Motion Sensor

2 of 23

  1. Input – Process – Output, and IPO
  2. Configure the graphical coding environment
  3. Introduction to PIR motion sensors
  4. Use AnalogRead block
  5. Use the buzzer to play the alarm
  6. Use PIR motion sensors to detect people

CONTEN TS

3 of 23

Let’s set up the Mind+ programming environment for Bittle and use the coding blocks to do I-P-O experiments!

4 of 23

Upload the Firmware for Mind+

  1. Download the PetoiDesktopApp at https://github.com/PetoiCamp/OpenCat/releases
  2. Install the PetoiDesktopApp.
  3. Select the Bittle, Software version 2.0, Board version, Mind+ mode
  4. Connect the serial port to Bittle and upload the firmware

Connect Bittle.

Notice the direction of the pins

5 of 23

Configure the Graphical Coding Environment

6 of 23

Paste the Mind+ library’s address https://github.com/PetoiCamp/Petoi_MindPlusLib into the field

7 of 23

8 of 23

Note to MAC users:

After importing the extension library, Please copy the folder (PetoiRobot) extracted from PetoiRobot.zip to /Users/{your The username}/ Documents/mindplus-py/environment/Python3.6.5-64/lib/python3.6/site-packages/.

The version number 3.6.5 May be slightly different

9 of 23

Build The Program and Run It

10 of 23

  • In this lesson, we want to keep Bittle always on guard.
  • When someone passes by, Bittle should light up the LED and make an alarm sound.

11 of 23

什么是红外光?

Infrared radiation is an electromagnetic wave in the infrared band between visible light and microwave, with a wavelength range from 780 nanometers to 1 mm. It is invisible light with a lower frequency than red light. It has all the properties of light.

What is Infrared Light?

The light reflected off an object's surface determines the color we see

12 of 23

Use scenario:

Infrared sensors usually utilize the transmission or reflection of infrared light.

The infrared thermometer measures the infrared radiation from the human body to calculate its temperature.

Infrared from the Human Body

13 of 23

The human body emits specific infrared light

Detects infrared light emitted by the human body

photosensitive element

Fresnel lens

When a hot object moves,

it causes a change in the voltage on the sensor

Heat

Detect Motion

14 of 23

Connect the PIR Sensor

15 of 23

After connecting the hardware, we can display the value detected by the sensor on the serial port monitor

We're going to learn a new function that lets Bittle read the value from the digital sensor

16 of 23

Digital Read

  • Digital read (pin);
    • Read the HIGH or LOW of the digital pin
    • pin: Pin number to be read
    • Here we connect D8

17 of 23

Digital Read

If person detected:

the serial monitor prints 1;

Else

prints 0;

\CODE\5.01_FindPeopleAndPrint.mp

18 of 23

Thinking & Analysis

  • Now that we have the sensor’s return value, what can we do with it?
  • What can Bittle do?

19 of 23

Task 1

Please write code to achieve:

If someone is detected:

Turn on the LED

Else:

Turn off the LED

\CODE\5.02_FindPeopleAndOpenLED.mp

20 of 23

Task 2

Modify the above code so that:

If the sensor detects someone:

Triggers the alarm

Else

Stop playing

\CODE\5.03_FindPeopleAndOpenBuzzer.mp

21 of 23

Task 3

Please write code:

If the sensor detects someone:

Sit

Trigger an alarm

Light the LED

Else:

Lay down

Stop the alarm

Turn off the LED

\CODE\5.04_FindPeopleAndSit.mp

22 of 23

23 of 23

Summary

It‘s great that Bittle can feel

the environment and react

Next time we'll continue to help Bittle perceive the world

woof~

woof~