> For the complete documentation index, see [llms.txt](https://docs.petoi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.petoi.com/~/changes/MnaoHQ6wOvffal3XIPZR/extensible-modules/pir-motion-sensor.md).

# PIR Motion Sensor

{% embed url="<https://youtu.be/_3CZfGW3Ngw>" %}

## Function introduction

This sensor allows you to detect the movement of animals, usually the movement of humans within its detection range. Just connect it to the NyBoard and program it, and when anyone moves within its detection range, the sensor will output a high potential on its **SIG** pin.

<figure><img src="/files/nkDpmJ1Tehk5fwxuviro" alt=""><figcaption></figcaption></figure>

## Hardware setup

* NyBoard

Connecting to the NyBoard with wire as shown in the following picture:

<figure><img src="/files/tRKrnoQmSIJyLrXvhVTb" alt=""><figcaption></figcaption></figure>

* BiBoard

<figure><img src="/files/Fj1VPiqT4igxYjkPHlNI" alt=""><figcaption></figcaption></figure>

For specific use, the end connected to the sensor can be fixed on the robot's head (included in Bittle's mouth or attached to the top of Nybble's head), of course, you can also use your creativity according to your needs.

## Software setup

The code using this sensor has been integrated into the [**OpenCat**](https://github.com/PetoiCamp/OpenCat) (NyBoard)/ [**OpenCatEsp32**](https://github.com/PetoiCamp/OpenCatEsp32) (BiBoard) project. Uncomment the line **`#define PIR`**  in the **OpenCat.ino / OpenCatEsp32.ino**, as shown in the figure below, and then use the [Arduino IDE](https://www.arduino.cc/en/software) to upload the sketch to the robot main board, which can reproduce the example function of integrating the robot action.

### NyBoard

#### Prepare the Arduino UNO development environment

With **NyBoard V1\_\***, you can simply choose **Arduino Uno**.&#x20;

<figure><img src="/files/4JBNM8f9Sdm40i7VCH7O" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/rpk27n9zoYHfkwm0A2pQ" alt=""><figcaption></figcaption></figure>

### BiBoard

#### [Prepare the ESP32 development environment](https://docs.petoi.com/arduino-ide/upload-sketch-for-biboard#2.1-prepare-the-esp32-development-environment)

<figure><img src="/files/WrrfTwjPxYxDfCcl66C4" alt=""><figcaption></figcaption></figure>

If you want to test the function of a PIR motion sensor alone or want to learn more about its principles. You can use the Arduino IDE to upload the demo sketch(**test\_Touch\_Reflection\_PIR.ino**), as shown below:

<figure><img src="/files/yXcJAPMU66ggYfyGEYYq" alt=""><figcaption></figcaption></figure>

This demo sketch implements real-time printing of sensor detection results in the [serial monitor](https://docs.petoi.com/arduino-ide/serial-monitor) - when anyone moves within its detection range, print 1; otherwise, print 0.

<figure><img src="/files/LJCOqd0lvhIbye9DyTei" alt=""><figcaption></figcaption></figure>

### The demo code

The demo code is in the OpenCat code repository on GitHub (specific path: OpenCat/ModuleTests/test\_Touch\_Reflection\_PIR). You can visit our GitHub code repository <https://github.com/PetoiCamp/OpenCat> to download the complete code, as shown in the following picture:

<figure><img src="/files/Xv4iqGG0WcQEnjP75NCY" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.petoi.com/~/changes/MnaoHQ6wOvffal3XIPZR/extensible-modules/pir-motion-sensor.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
