# Touch Sensor

## Function introduction

The sensor contains two touch parts (left and right) and can detect changes in capacitance when a finger approaches. This means that 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/QPompig1xNpi0MaDegBb" alt=""><figcaption></figcaption></figure>

## Hardware setup

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

<figure><img src="/files/ePHLQu9HE2ZjgZoE20lC" 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 actual needs.

## Software setup

You can use the [Arduino IDE](https://www.arduino.cc/en/software) to upload the demo code (doubleTouch.ino) or compile and upload your own code.

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

This demo sketch (doubleTouch.ino) 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/8NF3ZsLnW2rtXUjD5ucP" alt=""><figcaption></figcaption></figure>

### The demo code

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


---

# Agent Instructions: 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:

```
GET https://docs.petoi.com/thai/extensible-modules/touch-sensor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
