Arduino 101 meetup prep – day 4 – reflective infrared sensor

7May2009 – old stuff that may still be useful

Here’s a reflective infrared light sensor I salvaged from a printer.  In that application they are typically used to detect the presence of paper, which is way more reflective than the dark plastic insides of the printer.  These can useful for detecting light and dark surface transitions in projects like line-following-robots.  Only 2 resistors are required to hook this up to the Arduino…

You find these in all sorts of machines that handle paper including faxes and photocopiers too.  The sensor is usually on a small PCB to facilitate mounting in its host machine.

Lacking a data sheet you can usually guess that the clear LED is the IR emitter and the dark LED is the phototransistor.  Then you can use your multimeter diode function to figure out anode and cathode.  But they made it way easier than that for us…

Clearly marked part numer (ON2179), logo is Panasonic, and “83” is probably the manufacture date.  Google quickly turns up the data sheet, which tells you all sorts of interesting stuff, including the pinout of the sensor…

and gives a little test circuit that provides a basic idea of how to hook it up

So I sketched out the circuit you want, and how the pins on the sensor relate to the pads on the PCB

and following the late-night-circuit-building protocol, I tried this out on a breadboard first before hooking it to the Arduino

and noted that while infrared light is invisible to humans, it is very visible to the digital camera

and this all looked good so I replaced the original wires which had a connector that didn’t fit the Arduino, added my two resistors, and a little heat-shrink tubing

and did another test with the multimeter, moving the sensor back and forth from the highly reflective white paper to the black and not-so-reflective antistatic foam

so over the paper, the IR reflects much better, turning on the transistor, and putting out around 3V via this emitter follower (which is just a certain way a transistor can be used)

and moving the sensor over the dark foam, the transistor isn’t turned on as much leading to an output voltage of around 0.3V

so with everything working, I hooked up the sensor to the Arduino

Wrote a little sketch (below) that borrows heavily from our previous read-the-potentiometers work and observed the terminal output as I moved the sensor over various light and dark surfaces and at different distances from the surface.

In the course of playing with lots of different infrared sensors over the years, I worked on:

  • edge-detecting for a robot (table-edge, that is), which lead to the discovery that changes in ambient room lighting can really mess with the values from your sensor
  • adaptive reflective IR proximity sensing (mouthful), where I used PWM to vary the brightness of the emitter and periodically recalibrate and adapt to changing ambient light
  • and then off into the wonderful world of IR remote controls for TV’s, Air Hog indoor helicopters, and, oddly enough, the Waterloo uptown parking garage access system (since converted to RF).

That’s a wrap on my Arduino 101 meetup prep.  Thursday is the big MakeKW meeting at Zeke’s on King St. (please come out, socialize, fill out the space survey, and have fun) and then the Arduino meetup is on Friday at the Laurentian Zehr’s community room.  I’ll be coming later to that event (after 8pm), but I’m sending all these sensors with my good friend Cheryl, so they’ll be available early for borrowing.

Hey, if you have anything you’d like to hook up to your Arduino, but you’re not sure how, bring it along to one of these meetups and we’ll have a look.  We never did get to the Hall sensor (disk drive), or rotary sensor (computer mice), or temperature sensor (PC power supply), or R/C car.  Opportunities ahead…

DW

Arduino code:


/*
Read voltage on analog pin 0 from reflective IR sensor and send over serial port to host pc
Author: Darin White
Date: 2009-05-06
*/

long i=0;
int val0=0;
int irPin0 = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  val0 = analogRead(irPin0);
  
  Serial.print(val0);
  Serial.print("\n\r");
  delay(1500);
}
  
This entry was posted in arduino and tagged , , . Bookmark the permalink.

One Response to Arduino 101 meetup prep – day 4 – reflective infrared sensor

  1. Pingback: Arduino 101 meetup prep – day 5 – optical limit switches | makebright

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>