Physical Computing


Links Links

Class Websites

(:source lang=arduino_cpp :)[@
image upload pmwiki-2.2.72, 2002072

 edit SideBar


The QRD1114 reflective object sensor is a very simple device. It is really just an LED mounted side by side with an infrared photo transistor. Light bounces off an object and is sensed by the photo-transistor. The photo-transistor has a filter for visible light so that the sensor is less affected by ambient light in the environment.

A layout of the parts, designed to show approximate placement of parts and wires.

Other similar devices

There are many devices available that work in a similar manner, and the schematics and code on this page should work for most of similar devices. A few of these devices that seemed interesting are listed below.

device cost sensing dist. (50% of max resp.)
Optek OPB733TR $2.00 2 - 12
Vishay TCRT5000 $1.80 1-7mm
Sharp GP2S700HCP $1 1-7mm
Optek OPB702 1.65 1-6mm

QRD wheel encoder build

  • The first step isn't shown explicitly
  • Cut a piece of "wired breadboard" 5 x 7 holes as shown
  • Cut the traces down both sides of the middle row of holes as shown
  • Use a multimeter on continuity (beep) setting to check to make sure that the pcb traces are really cut.
  • Solder in the QRD1114. Note that the small dot would be in the

lower left of the front of the sensor, if it was visible.

  • Note that the QRD index "dot" is not visible, but it would be in the lower left of the photo as shown.
  • Solder in the 1K and 10K resistors as shown
  • Bend over the 10K resistor lead and solder it to the bottom of the middle pin.
  • You will need to wait some time for your soldering iron to heat up the pin.
  • That pin is the +5V input in the schematic.
  • This photo doesn't show it, but solder the (blue/bare) wire in foreground where it comes through the pcb and at the pad next to the pins on the right end.
  • Add the yellow wire between the phototransistor voltage divider

(top right corner in the photo and the output pin. Note that there is no free hole near the voltage divider, so you will have to just solder the wire to the pin.

Test Code for QRD1114 wheel encoder proveout

Analog Read w Power Pins

There are several steps to using an encoder for feedback. The code below is used just to prove that your encoder works. Values generated should change from about 900 to 200 by bringing your hand close to the sensor. If this test doesn't work, you have likely made a wiring mistake or soldering problem with your sensor.

/* AnalogReadSerial
 Same as Arduino Sketch of the same name
 except adjacent pins provide power for a (fairly low-power < 20 mA) sensor.

 analogRead on   A0   // output pin
 +5V provided by A1   // +5V pin
 Gnd provided by A2   // GND pin

void setup() {
    // initialize serial communication at 9600 bits per second:

    pinMode(A1, OUTPUT);       // +5V
    digitalWrite(A1, HIGH);
    pinMode(A2, OUTPUT);       // GND


void loop() {
    // read the input on analog pin 0:
    int sensorValue = analogRead(A0);
    // print out the value you read:
    delay(100);        // delay in between reads for stability

Reading a rotary encoder with an interrupt

/* read a one channel rotary encoder with interrupts


#define encoder0PinA  2
#define encoder0PinB  4

volatile unsigned int encoder0Pos = 0;

void setup() { 

  pinMode(encoderPin, INPUT);             // encoder input

  // add power pins here if using the Arduino to power the encoder

 attachInterrupt(0, doEncoder, CHANGE);  // check the correct pin number for interrupt

  Serial.begin (9600);
  Serial.println("start");                // a personal quirk


void loop(){
// do some stuff here - the joy of interrupts is that they take care of themselves

void doEncoder() {

  if (dir == forward ) {    //  you'll need to define these aboe
  } else {

  Serial.println (encoder0Pos, DEC);

QRD1114 datasheet

Edit - History - Recent Changes - Search
Page last modified on March 22, 2013, at 01:05 PM