Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Noob help for QTR 1RC sensor


#1

Hello, I just recently got into using microcontrollers and sensors. I purchased four Pololu QTR 1RC infrared sensors and have ran the following setup:

Red wire - Teensy Microcontroller’s 5V to the VIN of the sensor
Black wire - Ground to ground
Yellow wire - Sensor’s OUT to pin 8 of the Teensy

I ran the example code but modified it to 1 sensor. From the raw values, I see on the serial monitor “2 2 2 2 2 2 2 2 3 2 2 2 2 3 2…” etc

Disconnecting the sensor continues this result.

Could anyone point me in the right direction as to what I’m doing wrong? Thanks

CODE: http://pastebin.com/kSbjWKz1


#2

Hello.

It is hard to tell from your picture, but it looks like the headers are not soldered to your Teensy. Soldering is necessary for a reliable electrical connection. If your headers are actually soldered in, or you get the same behavior after you solder your headers in, can you post pictures that clearly show your soldered joints?

-Jon


#3

Hi, thanks for the reply.

I have just soldered the 5V, GND, and pin 9 of my Teensy and have tested it with a multimeter to ensure the connection is proper. I have changed the code to pin 9. Unfortunately, I am still getting the same result. Does the sensor require a particular pin type?

Edit: I have tried this exact setup with a Smart Grayscale Sensor, and I was able to receive correct values for black and white.

Teensy Layout: https://www.pjrc.com/teensy/teensylc_front_pinout.png

Updated setup with serial monitor: http://imgur.com/a/6E0Mm

Red wire - Pin 9 to OUT of sensor
Yellow wire - GND to GND
Black wire - 5V to VIN


#4

After soldering it and testing it, I used an infrared camera to ensure that the IR led turns on, which it does. The IR led is perfectly fine but for whatever reason, the serial output reads 2’s and 3’s repeatedly regardless of whether the IR sensor is plugged in or not.


#5

It looks like in order to get our QTR library working with a Teensy, you will need to modify the QTRSensors.cpp file. This is because the ARM microcontrollers do not handle commands in exactly the same way AVR microcontrollers do. In particular, every time the code tries to command digitalWrite() right before pinMode(), you should swap the order of the two commands. For example, lines 434 and 435 show:

digitalWrite(_pins[i], HIGH); // make sensor line an output pinMode(_pins[i], OUTPUT); // drive sensor line high

and should, instead, be:

pinMode(_pins[i], OUTPUT); // drive sensor line high digitalWrite(_pins[i], HIGH); // make sensor line an output

It looks like this happens two more times inside QTRSensors.cpp: lines #114 and #123.

By the way, I just realized that your Teensy LC uses 3.3V logic and its pins are not 5V-tolerant. From your connections, it looks like you are powering the QTR-1RC with 5V from the Teensy. This is risky since OUT could then be 5V, which could permanently damage the I/O pin it is connected to on the Teensy LC. Instead, you might consider connecting the QTR’s 3.3V to VCC to power the QTR-1RC. This will make it safer to connect to your Teensy LC’s I/O, but it will also reduce the brightness of the IR LED. Alternatively, you might consider using a level-shifting circuit like this one.

-Jon


Is the Zumo Robot for Arduino Compatible with 3.3v I/O boards?
#6

Changing the .cpp file and the VCC fixed it, thank you so much!! :smiley:


#7

I am glad things are working now! We will look at updating the library to reflect that change so it works better for other people. By the way, the comments are also reversed on those two lines; this is something we also plan to fix.

-Jon