> ## Documentation Index
> Fetch the complete documentation index at: https://docs.deneyapkart.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Using with Arduino

## Library Installation

Search for the **Deneyap Cift Kanalli Cizgi Algilayici** library in the Library Manager and install version **1.1.1 or later**. For the installation steps, see the [Library Installation](https://docs.deneyapkart.org/en/Moduls/Library-Installation.md) page.

## First Application

The code below calibrates the sensor for 10 seconds, then prints the position of the line to the serial monitor:

```cpp theme={null}
#include <Deneyap_CiftKanalliCizgiAlgilama.h>

LineFollower4Channel LineSensor;                       // 4 channel (ITR1502SR40A) module
uint16_t Values[LINEFOLLOWER_4CH_SENSOR_COUNT];        // values of the 4 sensors

void setup() {
    Serial.begin(115200);
    if (!LineSensor.begin(0x07)) {                     // Default I2C address
        Serial.println("I2C connection failed");
        while (1);
    }

    // 10 second calibration: sweep the sensor left and right across the line
    unsigned long start = millis();
    while (millis() - start < 10000) {
        LineSensor.Calibrate();
    }
}

void loop() {
    uint16_t position = LineSensor.ReadLineBlack(Values); // 0 - 3000
    Serial.println(position);
    delay(20);
}
```

## Basic Functions

| Function | Description |
| - | - |
| `begin(address)` | Starts communication with the module, returns `false` if the module does not answer. |
| `Read(values)` | Reads the raw values of the 4 sensors. |
| `Calibrate()` | Takes one calibration reading; call it repeatedly during calibration. |
| `ReadCalibrated(values)` | Reads the values scaled to 0 (white) - 1000 (black). |
| `ReadLineBlack(values)` | Returns the position (0 - 3000) of a black line on a white surface. |
| `ReadLineWhite(values)` | Returns the position (0 - 3000) of a white line on a black surface. |
| `SetEmitter(state)` | Turns the infrared emitters on or off. |
| `SetDimmingLevel(level)` | Sets the brightness (0 - 100) of the infrared emitters. |

## Calibration

Each sensor reads the white surface and the black line differently depending on ambient light and the surface. During calibration the lightest (white) and darkest (black) value seen by each sensor is recorded. `ReadCalibrated`, `ReadLineBlack` and `ReadLineWhite` do not work before calibration.

**1. Fix the height**

Hold the module over the line with the sensors facing down, 3-5 mm above the surface. Keep the same height during calibration and use; calibrating with the module mounted on the robot, or resting on a fixed spacer, is recommended.

**2. Call Calibrate() repeatedly**

Call `Calibrate()` repeatedly for a few seconds. The `KalibrasyonluCizgiTakibi` example in the library does this for 10 seconds and turns the built-in LED on during that time.

**3. Sweep the module across the line**

Meanwhile, slowly sweep the module left and right across the line. Each of the 4 sensors must pass over both the white surface and the black line. If the module is mounted on a robot, you can rotate the robot left and right in place over the line.

**4. Check the result**

After calibration, check `calibrationOn.minimum[]` and `calibrationOn.maximum[]`. If the minimum and maximum of a sensor are very close, that sensor did not see the line; repeat the calibration.

Calibration values are not stored permanently; calibrate every time the board starts, and again if the lighting or the surface changes.

> [!WARNING]
>
> If the board is reset (upload, RESET button, opening the serial monitor) while it is talking to the module, the module may stop responding until its power is removed: `begin()` fails, or the module stops answering shortly after. Unplug the board's USB cable and plug it back in to power-cycle the module. A short `delay()` between reads in `loop()` makes this less likely.

## Examples

The `4Kanal_GP2S700HCP` folder of the library contains two ready examples: **SensorDegerleriniOkuma** (reads the raw values) and **KalibrasyonluCizgiTakibi** (calibrates and calculates the line position). Examples for the first version module are in the `2Kanal_TCRT5000` folder.

> [!NOTE]
>
> The module uses the Everlight ITR1502SR40A sensor. The library and its example folder carry the name of its equivalent, the Sharp GP2S700HCP; there is no difference in use.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.