QRD1114 Optical Detector Hookup Guide

Pages
Contributors: jimblom
Favorited Favorite 6

Example Code

Here is a simple Arduino example based on the circuit above. Copy and paste this into your Arduino IDE, then upload!

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE.

If you have not previously installed an Arduino library, please check out our installation guide.

language:c
/******************************************************************************
QRD1114_Proximity_Example.ino
Example sketch for SparkFun's QRD1114 Reflectance Proximity Sensor
  (https://www.sparkfun.com/products/246)
Jim Lindblom @ SparkFun Electronics
May 2, 2016

Connect a QRD1114, 330 resistor and 10k resistor as follows:

QRD1114 Pin ---- Arduino ---- Resistors
    1              A0      10k Pull-up to 5V
    2              GND
    3                      330 Resistor to 5V
    4              GND

As an object comes closer to the QRD1114, the voltage on A0 should go down.

Development environment specifics:
Arduino 1.6.7
******************************************************************************/
const int QRD1114_PIN = A0; // Sensor output voltage

void setup() 
{
  Serial.begin(9600);
  pinMode(QRD1114_PIN, INPUT);
}

void loop() 
{
  // Read in the ADC and convert it to a voltage:
  int proximityADC = analogRead(QRD1114_PIN);
  float proximityV = (float)proximityADC * 5.0 / 1023.0;
  Serial.println(proximityV);
  delay(100);
}

After uploading, open your serial monitor, and set the baud rate to 9600 bps.

While you monitor the voltage outputs in the serial monitor, move your hand towards the sensor's head. You should see the voltage dip from ~4.8V to less than 0.2V. Keep moving in and out to get a feel for the sensor's viewing distance.

Serial monitor example

After testing it out with your finger, try testing other objects. In addition to distance, the output voltage also depends on the object's color and reflectance. As an example, here's a very unscientific comparison we did between black and white sheets of paper:

Voltages, distances, and colors

The sensor is much more sensitive to the white paper than the black. The black surface absorbs more light from the LED, meaning less is reflected back to the phototransistor. Try doing some science of your own to test out your sensor's behavior!