# Light Sensor

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

## Function introduction

The sensor integrates two photoresistors (depending on the light intensity adjustment resistance) to detect the light intensity. The photoresistor is a particular resistance that uses the photoconductive effect, and its resistance is directly related to the intensity of the incident light. When the light intensity increases, the resistance decreases; when the light intensity decreases, the resistance increases. The output signal is an analog value. The brighter the brightness, the larger the value. You can realize the function you want by judging the value of the detected light intensity, such as the function of a robot tracing light.

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

## BiBoard

### Hardware setup

#### BiBoard V1 for Bittle X V2 / Bittle X+Arm / Nybble Q

<figure><img src="/files/wKh1Wl7fMNLxyF4BavaX" alt="" width="375"><figcaption></figcaption></figure>

#### BiBoard V0 for Bittle X

<figure><img src="/files/msVRT8zAL0QlRVz1rcSG" 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

* You can use the [Firmware Uploader](https://guide.petoi.com/desktop-app/firmware-uploader#select-the-correct-options-to-upload-the-latest-firmware) within the Petoi Desktop App.\
  Please select the correct ***Product*** type, ***Borard version***, and ***Serial port***. The mode should be **Standard**, so press the **Upgrade the Firmware** button. for example, Bittle, BiBoard\_V0\_2, COM5 as follows:

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

  After uploading,  [open the serial monitor](https://guide.petoi.com/arduino-ide/serial-monitor) and use the serial command "***XL***" to switch to using the light sensor mode.
* You can use [Arduino IDE](https://www.arduino.cc/en/software) to [upload the sketch](https://guide.petoi.com/arduino-ide/upload-sketch-for-biboard#id-2.-set-up-biboard)(***OpenCatEsp32.ino***). \
  Use the latest OpenCatESP32 source code to finish the setup. For example,  to modify the code for ***Bittle*** as shown below:<br>

  <figure><img src="/files/5vX8SspsC7PHdkYCZkE3" alt=""><figcaption></figcaption></figure>

  After uploading,  [open the serial monitor](https://guide.petoi.com/arduino-ide/serial-monitor) and use the serial command "***XL***" to switch to using the light sensor mode.

## NyBoard for Bittle / Nybble

### Hardware setup

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

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

### Software setup

* You can use the [Firmware Uploader ](https://guide.petoi.com/desktop-app/firmware-uploader#select-the-correct-options-to-upload-the-latest-firmware)within the Petoi Desktop App.\
  Please select the correct ***Product*** type, ***Borard version***, and ***Serial port***. The mode should be **Light**, so press the **Upgrade the Firmware** button. for example, Nybble, NyBoard\_V1\_2, COM5 as follows:<br>

  <figure><img src="/files/Sm7CbvmK6rPSPlgAhvhE" alt=""><figcaption></figcaption></figure>
* You can use [Arduino IDE](https://www.arduino.cc/en/software)  to upload and modify the source code.&#x20;

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

#### Prepare the Arduino UNO development environment.

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

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

For example,  to modify the code for ***Bittle*** as shown below:

<figure><img src="/files/464CI2FfEMmDJjxlmTiQ" alt=""><figcaption></figcaption></figure>

### Arduino module test code

Suppose you want to test a light sensor's function alone or learn more about its principles. You can use the Arduino IDE to upload the test code(**testDoubleLight.ino**):

The test code is in the **OpenCat** project source code ([ModuleTests/testDoubleLight](https://github.com/PetoiCamp/OpenCat/blob/main/ModuleTests/testDoubleLight/testDoubleLight.ino))

This test code implements real-time printing of the analog values of the two analog pins (A2 and A3) in the [serial monitor](https://guide.petoi.com/arduino-ide/serial-monitor). You can also use the serial plotter to view the two analog pins (A2 and A3) more intuitively. The waveform graph is generated by the analog value of the pin output along the time axis.

<figure><img src="/files/5stbpWnDnlowmWmrEEiy" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/74ISZ7yXiw4z5YHm4jKg" alt=""><figcaption></figcaption></figure>


---

# 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://guide.petoi.com/extensible-modules/light-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.
