# Gesture Sensor

{% embed url="https://youtu.be/1sznhot5U0E" %}

{% embed url="https://youtu.be/namXLL7VmrQ" %}

## Function introduction

The sensor features advanced gesture detection, proximity detection and digital ambient light sensing. Gesture detection can accurately sense "up, down, left and right" and more complex movements.

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FtSN6KysyGMVmmYhnmYQn%2FGesture_New.png?alt=media&#x26;token=b7f17656-7d53-4528-84e7-862889e3f0f4" alt=""><figcaption></figcaption></figure>

## Software setup

Install the latest version of the **Arduino\_APDS9960** library using the [Arduino IDE](https://www.arduino.cc/en/software).

<div><figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FG1g9tL85pdwuCyKpsqVy%2Fimage.png?alt=media&#x26;token=70ade8c2-207a-43a8-9588-4b2272f8fb95" alt=""><figcaption></figcaption></figure> <figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FYJX1bwhT0LQUEle1nFsZ%2FAPDS9960%E5%BA%93_en.png?alt=media&#x26;token=14452e52-492f-429f-874d-81282d519f51" alt=""><figcaption></figcaption></figure></div>

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 GESTURE`**  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="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FXDvIUhP1OotHdF3rFSZN%2Fimage.png?alt=media&#x26;token=4170cb44-69cd-4d52-9701-83618dbfb59c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FijiuA2yGCHHJJrJJAWoM%2Fimage.png?alt=media&#x26;token=e1a55828-cf36-4434-953a-ec270b15347c" 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="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FjJT9PZNWuqZC1DlK2c35%2Fimage.png?alt=media&#x26;token=c8885bec-983d-4f61-b82e-82aca323ea5c" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FuGwwk91NgKofq8vpmlYh%2Fimage.png?alt=media&#x26;token=87b2b722-c730-4b85-a49c-0519256b76c2" alt=""><figcaption></figcaption></figure>

## Hardware setup

* NyBoard

After uploading the sketch, connect to the NyBoard with wire, as shown in the following picture:

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FaUh1KEKMeBQAthAQA0E0%2FPANA0502%20%E6%8B%B7%E8%B4%9D.jpg?alt=media&#x26;token=dfb6db2f-0d6a-4f60-8887-71d72f8915a1" alt=""><figcaption></figcaption></figure>

* BiBoard

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FuoKKjkPdac7DMDJ34BUu%2FGesture_BiBoard.png?alt=media&#x26;token=c75a5c6e-7f1b-4053-84a7-70117b4409e5" 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.

This demo sketch (gesture.ino) implements real-time printing of various directional gestures (up, down, left, and right) made by the user in front of the gesture sensor in the [serial monitor](https://docs.petoi.com/arduino-ide/serial-monitor).

<figure><img src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FahxdZuxZemJ8wMCW86MV%2Fimage.png?alt=media&#x26;token=ae21860f-9192-4372-94df-11e6ee79ba67" alt=""><figcaption></figcaption></figure>

### The demo code

{% file src="https://1565080149-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQ6a951Q6Jn1Zzt5Ajr-887967055%2Fuploads%2FU2qR06fet8Sx1oj9mF61%2Fgesture.zip?alt=media&token=69c2c3d0-db84-44ff-95c8-956e9869ad6e" %}
