1

What's the best way to wire a QRB1114 IR sensor to an Arduino Uno? I'm attempting to use it as a white-line-on-black-background line detector. Google shows many different ways wire it to an Arduino, but I'm using this one because of its simplicity.

However, when I tested the circuit using the AnalogInput example code, I'm not getting the expected behavior. It registers a reading of 0 for both white and black backgrounds (I'm using white and black electrical tape as test surfaces), and occasionally registers between 5-10 if there's nothing in front of it at all.

What is the most likely problem? Is this circuit an improper way of wiring the sensor? Is my sensor defective? Is the code not reading it properly?

This is my test code:

#define BUTTON_PIN 2
#define LED_PIN 13

const int IR_SENSOR_PIN = A0;
int sensorValue = 0;

void setup() {
    Serial.begin(9600);
    pinMode(LED_PIN, OUTPUT);
}

void loop() {
    sensorValue = analogRead(IR_SENSOR_PIN);
    Serial.println(sensorValue);  
    delay(1000);
}
2

It was a dumb programming/wiring problem on my end. As I discovered from this description, the signal pin needs a pullup resistor. Since my circuit doesn't have that, I need to enable the pullup resistor on A0, which I wasn't doing.

After modifying my code to do that, the sensor works as expected.

  • Good find. Depending on the range (white vs black surface) you get from analogRead you might want to use a different value (external) resistor. – Gerben Oct 26 '14 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.