QRE1113 Digital Reflective Cliff & Line Sensor – Wiring, Arduino Code & Calibration
The QRE1113 digital reflective sensor module uses an infrared LED and phototransistor to measure how much infrared light is reflected from a nearby surface. It can be used for robot line tracking, floor detection, edge sensing and short-range cliff detection.
This guide applies to the 3-pin capacitor-discharge version labelled VCC, OUT and GND. It covers Arduino UNO wiring, how the digital timing output works, a basic proof-of-operation test, calibration for line or cliff detection and common troubleshooting steps.
QRE1113 Digital Sensor Overview
The onboard QRE1113 contains a 940nm infrared emitter beside an infrared-sensitive phototransistor. The module circuit includes an LED current-limiting resistor and a small timing capacitor so the amount of reflected infrared light can be measured using a digital I/O pin.
A light or highly reflective surface normally produces a shorter discharge time. A dark, poorly reflective surface or an open edge normally produces a longer time. The exact values depend on the surface, sensor height, angle, ambient infrared light and controller.
Important – This Is a Timed Digital Output
The digital QRE1113 module uses capacitor-discharge timing. The microcontroller first drives OUT HIGH, changes the same pin to an input, and then measures how long it remains HIGH before the phototransistor pulls it LOW. A simple continuous digitalRead() does not provide the intended reflectance measurement.
The normal measurement sequence is:
- Configure the OUT connection as a digital output.
- Drive it HIGH briefly to prepare the timing circuit.
- Change the same GPIO to an input without a pull-up.
- Measure the time until the input becomes LOW.
- Interpret shorter times as more reflected infrared light and longer times as less reflection.
This arrangement provides a useful relative reflectance measurement without using an analogue input.
For the Arduino UNO example below, power VCC from 5V. When using a 3.3V controller such as an ESP32 or Raspberry Pi Pico, power the module from 3.3V and use a normal 3.3V bidirectional GPIO. This keeps the timing circuit and GPIO operating at the same logic voltage.
Connections & Arduino UNO Wiring
The three connections are printed on the module. Follow the VCC, OUT and GND markings rather than relying on connector orientation.
| Module Pin | Arduino UNO | Function |
|---|---|---|
| VCC | 5V | Sensor and infrared LED supply |
| OUT | D2 | Bidirectional charge and timing connection |
| GND | GND | Ground |
Another normal digital input/output pin can be used by changing SENSOR_PIN in the sketch. The selected pin must be able to operate as both an output and an input.
Mounting the Sensor
Point the QRE1113 sensing face directly towards the surface. Start with the sensor approximately 3mm from the floor or target and adjust the height only after checking the readings on the actual material.
For cliff detection, position the sensor far enough ahead of the wheels that the controller has time to stop or turn before the robot reaches the edge. Faster robots require more physical and software margin.
Arduino UNO Basic Reflectance Test
No external Arduino library is required. This example uses standard Arduino digital I/O and the micros() timer.
const byte SENSOR_PIN = 2;
const unsigned long TIMEOUT_US = 3000;
unsigned long readQRE1113() {
// Drive the timing node HIGH briefly.
pinMode(SENSOR_PIN, OUTPUT);
digitalWrite(SENSOR_PIN, HIGH);
delayMicroseconds(10);
// Release the pin and measure how quickly it falls LOW.
pinMode(SENSOR_PIN, INPUT);
unsigned long startTime = micros();
while (digitalRead(SENSOR_PIN) == HIGH) {
unsigned long elapsed = micros() - startTime;
if (elapsed >= TIMEOUT_US) {
return TIMEOUT_US;
}
}
return micros() - startTime;
}
void setup() {
Serial.begin(115200);
Serial.println("QRE1113 digital reflectance test");
Serial.println("Lower value = more reflected IR");
}
void loop() {
unsigned long reading = readQRE1113();
Serial.print("Discharge time: ");
Serial.print(reading);
Serial.println(" us");
delay(100);
}
Expected Result
Open the Serial Monitor at 115200 baud. You should see a changing discharge time in microseconds.
| Sensor Condition | Typical Behaviour |
|---|---|
| Bright or strongly reflective surface | Shorter discharge time |
| Dark or weakly reflective surface | Longer discharge time |
| No nearby surface / cliff | Usually a very long reading, often reaching the 3000µs timeout |
Do not expect a universal number for black, white or a cliff. The useful measurement is the difference between the surfaces in your own installation.
Calibrating Line and Cliff Detection
1. Mount the Sensor First
Calibration should be performed with the sensor at its final height and angle. Moving the sensor after calibration changes the amount of reflected infrared light and can move the threshold significantly.
2. Record the Real Readings
Run the basic test and record several readings for each condition the robot must distinguish. For example:
- normal floor;
- black or coloured tracking line;
- floor edge or open space;
- any different floor materials the robot may encounter.
3. Choose a Threshold Between the Groups
If the normal floor produces much shorter readings than the open edge, choose a cliff threshold between the highest normal-floor reading and the lowest reliable edge reading. Leave as much margin as practical rather than choosing a threshold close to either group.
For a dark line on a lighter floor, the dark line will commonly produce the longer timing value. Your control program can therefore compare the measured time with a calibrated threshold to decide whether the sensor is over the floor or line.
Two materials that look equally black or white to your eyes can behave differently at the QRE1113's infrared wavelength. Always calibrate using the real floor, line or target material.
4. Test Under Real Lighting
Repeat the test under the lighting in which the robot will operate. Strong sunlight and other infrared sources can alter the phototransistor response. Mechanical vibration, floor texture and sensor angle can also increase variation.
Using More Than One Sensor
Multiple modules can be fitted across the front of a robot for wider line or edge coverage. Each digital capacitor-discharge module requires its own bidirectional GPIO. The simple timing method reads one sensor at a time, so allow for the total measurement time when several sensors are used.
Troubleshooting
Reading always stays near 3000µs
- Confirm VCC and GND are connected correctly.
- Confirm OUT is connected to the same GPIO defined by SENSOR_PIN.
- Move the sensor closer to a light reflective surface and try again.
- Check that the sensing face is pointing towards the target.
- Make sure your sketch changes the GPIO from OUTPUT HIGH to INPUT for every measurement.
Reading is always very low
- Move the sensor slightly farther from the target if it is almost touching the surface.
- Test with a dark, non-reflective surface and compare the result.
- Check for strong nearby infrared illumination or direct sunlight.
- Confirm you have the digital capacitor-discharge module rather than a different QRE1113 breakout circuit.
Black and white surfaces give similar values
- Adjust the sensor towards the approximately 3mm working distance.
- Keep the sensor perpendicular to the test surface where practical.
- Try the actual line and floor materials rather than assuming visible colour determines infrared reflectivity.
- Take several readings and compare their average or range before choosing a threshold.
Cliff detection triggers randomly
- Recalibrate with the sensor mounted in its final position.
- Increase the separation between the normal-floor readings and the software threshold where possible.
- Check for changes in floor material, seams, shadows, shiny patches or strong sunlight.
- Use multiple sensors when the robot needs wider edge coverage.
- Allow sufficient stopping distance for the robot's actual speed and weight.
A normal digitalRead() gives confusing results
- This version does not contain a conventional comparator producing a permanent binary output.
- Use the charge, release and timing sequence in the example sketch.
- Do not configure the measurement pin with INPUT_PULLUP because the timing circuit needs the GPIO released while the discharge is measured.
QRE1113 breakout boards are available with different analogue and digital circuits, and component values or PCB layouts may vary between manufacturers. This guide is for the 3-pin VCC/OUT/GND capacitor-discharge version. Reflective sensing is affected by surface material, mounting distance, angle and ambient infrared light, so calibrate the finished installation before use. A single reflective sensor is not a safety-rated fall-prevention device; use appropriate sensor coverage and stopping margin where a robot could be damaged by an edge or drop.