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)
- 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
- Download or clone this repository
- Place the folder inside your Arduino
librariesdirectory - Restart the Arduino IDE
#include <FeedbackSensors.h>You must define:
- An array of pins
- The number of sensors
int sensorPins[] = {A0, A1, A2, A3};
FeedbackSensors sensors(sensorPins, 4);The sensor mode is defined using numeric values:
0→ DIGITAL1→ 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 secondsIf you skip calibration, raw readings will still work.
int values[4];
sensors.readAll(values);Useful after calibration.
int normalized[4];
sensors.readAllNormalized(normalized);0→ minimum reflectance100→ maximum reflectance
Each sensor becomes 1 or 0, forming a binary pattern.
uint8_t mask = sensors.readAllBitmask(50);Example:
- Sensors:
1 1 0 0 - Result:
0011(decimal3)
Perfect for PID, switch-case, or decision tables.
If your robot logic is inverted (white line on black background):
sensors.invertLogic(true);Call again with false to restore normal logic.
#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);
}