Getting a digital IR reflectance sensor to work with Arduino

Hey

I’m making a project with several IR reflectanse sensors, but I’m new with this, so I hope I can get some help in here.
I’m stuck trying to get a QRE1113 Line Sensor Breakout board (digital) to work with my Arduino Mega 2560.
The code I have so far is:

int sensorpin = 22;
long start = 0;
long slut = 0;

int time = 0;

void setup() {

Serial.begin(9600);

}

void loop() {

pinMode(sensorpin, OUTPUT);
digitalWrite(sensorpin, HIGH);
delayMicroseconds(10);
start = millis();
pinMode(sensorpin, INPUT);
while(sensorpin, HIGH)
{

Am I on the right track? or?
This is only for one sensor, but what if I have to use several?

Hello.

Yes, you are generally on the right track, although you probably want to add:

digitalWrite(sensorPin, LOW);

after the line:

pinMode(sensorpin, INPUT);

do disable the internal pull-up, since a pull-up on that line could affect your readings.

You can read multiple sensors sequentially, or you can get fancy and monitor multiple sensors in parallel and store their output pulses in an array.

By the way, have you seen our Arduino library for qtr sensors? It is designed to work with our versions of these sensors, the QTR-1RC and QTR-8RC, but I expect it to work with your sensor as well. Even if you don’t use the library, you can look at the source code to see how we read the sensors.

- Ben

Hi Ben

Thanks for your quick answer! That’s great :slight_smile:
Yes I have looked at your library but I wasn’t sure that it would work for these sensors. But I’ll have another look.
Thanks again!

From the product name, it sounds like you’re referring to the board Sparkfun sells. The initially carried our QTR sensors before replacing them with their own copies, so I expect them to be very similar. Even if there are subtle differences (we use a generic version of the QRE1113 that we think works a bit better for the QTR’s intended application), our library provides a number of customizable parameters that let you tweak the performance to compensate.

- Ben

Yes that’s right… it’s the ones from Sparkfun.
But that sounds great. I’ve already been looking at the library and it seems very useful, so thanks again.
And by the way, this is a great site :slight_smile: