Skip to content

ohthias/FeedbackSensors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino library for reflective and digital feedback sensors

This library provides a flexible and scalable way to read multiple feedback sensors (reflective, digital or analog), commonly used in line follower robots, edge detection, and array-based sensing projects.

It supports:

  • Analog and digital sensors
  • Optional calibration for reflective sensors
  • Normalized readings (0–100)
  • Bitmask output (ideal for line follower logic)
  • Inverted logic (black line on white or vice-versa)

Features

  • Automatic pin initialization
  • Analog or Digital mode selection
  • Optional calibration (user decides)
  • Read all sensors at once
  • Normalized output (0–100)
  • Bitmask output (binary pattern)
  • Logic inversion support

Installation

  1. Download or clone this repository
  2. Place the folder inside your Arduino libraries directory
  3. Restart the Arduino IDE

Usage

Include the library

#include <FeedbackSensors.h>

Create the sensor array

You must define:

  • An array of pins
  • The number of sensors
int sensorPins[] = {A0, A1, A2, A3};
FeedbackSensors sensors(sensorPins, 4);

Sensor mode

The sensor mode is defined using numeric values:

  • 0 → DIGITAL
  • 1 → ANALOG

Example:

sensors.setMode(1); // ANALOG

## Calibration (Optional)

Calibration is **not mandatory**.
Only use it if you want normalized or threshold-based behavior (recommended for reflective sensors).

```cpp
sensors.calibrate(2000); // calibrates for 2 seconds

If you skip calibration, raw readings will still work.

Reading Sensors

Read all raw values

int values[4];
sensors.readAll(values);

Read all sensors normalized (0–100)

Useful after calibration.

int normalized[4];
sensors.readAllNormalized(normalized);
  • 0 → minimum reflectance
  • 100 → maximum reflectance

Read bitmask (ideal for line follower)

Each sensor becomes 1 or 0, forming a binary pattern.

uint8_t mask = sensors.readAllBitmask(50);

Example:

  • Sensors: 1 1 0 0
  • Result: 0011 (decimal 3)

Perfect for PID, switch-case, or decision tables.

Invert Logic

If your robot logic is inverted (white line on black background):

sensors.invertLogic(true);

Call again with false to restore normal logic.

Examples

Example 1 – Line Follower (Bitmask)

#include <FeedbackSensors.h>

int pins[] = {A0, A1, A2, A3};
FeedbackSensors sensors(pins, 4);

void setup() {
  Serial.begin(9600);
  sensors.setMode(1);
  sensors.calibrate(3000);
}

void loop() {
  uint8_t line = sensors.readAllBitmask(50);
  Serial.println(line);
  delay(100);
}

About

Library of Arduino for feedback it multiple sensors

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages