> 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/touch-sensor.md).

# Touch Sensor

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

## Function introduction

The sensor contains two touch parts (left and right) and can detect changes in capacitance when a finger approaches. This means the touch sensor will output a high level whether your finger touches lightly or presses hard. You can realize the function you want by judging the detected value (1 for high level, 0 for low level).

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

## Hardware setup

* NyBoard

Connecting to the NyBoard with wire as shown in the following picture, connect to the NyBoard Grove interface which include D6, D7:

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

* BiBoard

<figure><img src="/files/yJFecILCdOlTxDzsSQh2" 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 DOUBLE_TOUCH`**  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/GiQdQ9peny9sQHUM6qwD" 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/FvjlDZXQQmolNulEJ6rd" alt=""><figcaption></figcaption></figure>

### Arduino C++ demo

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

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

This demo sketch implements real-time printing of the detection values of D6 and D7 pins in the [serial monitor](https://docs.petoi.com/arduino-ide/serial-monitor):&#x20;

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

#### The demo sketch

{% file src="/files/2ewVasMSNcahRxfVXgcy" %}

### Mind+ Demo

If you want to use the sensor with the Mind+ program for **NyBoard**:

1. &#x20;You can upload the firmware via the Petoi Desktop App:

   ![](/files/C941rKUVkO5wd6kEIJsE)

{% hint style="info" %}
Or you can upload the **OpenCat.ino** as follows, uncomment the line **`#define GROVE_SERIAL_PASS_THROUGH`** in the **OpenCat.ino:**

<img src="/files/lcwY9gQHVogAwA6pPBx5" alt="" data-size="original">
{% endhint %}

{% hint style="success" %}
For BiBoard, you can skip this step.
{% endhint %}

&#x20;2\.    Follow [the instructions](https://docs.petoi.com/block-based-programming/petoi-coding-blocks#import-petoi-mind+-extension-library) to import the Petoi Coding Blocks in the app **Mind+**, and load the Mind+ code file.

3. &#x20;Connect the robot and computer with the [USB adapter](https://docs.petoi.com/communication-modules/usb-downloader-ch340c)(USB uploader) or [Bluetooth module](https://docs.petoi.com/communication-modules/dual-mode-bluetooth).
4. &#x20;Power on the robot and click the **Run** button ![](/files/IgSx3kYHC78aLZ9jc6hK) in **Mind+.**<br>

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

#### Mind+ demo code

{% file src="/files/julSL9ymP5nCUqc9NggB" %}


---

# 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/touch-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.
