Qtrx-hd-02rc

Hello Group!

First time posting here and I have a question regarding these new QTRX RC Output sensors. Am I able to use these like I did with the old QTR Digital Sensors? I used those sensors with an Arduino and using a simple High/Low activation. HIGH was OFF and LOW was ON and I used that to turn on and off LEDS. However the same code will NOT work with the new QTRX sensors. Can anyone tell me why and do I have to use the QTR libraries? The code I am using is below:

const int xing1 = 3;
int xingstate   = 0;

void setup() {
Serial.begin(9600);
pinMode(13,              OUTPUT);
pinMode(xing1,     INPUT_PULLUP);
digitalWrite(xing1,        HIGH);
}

void loop(){
xingstate = digitalRead(xing1);
Serial.println(xingstate);
if(xingstate == LOW){
digitalWrite(13, HIGH);
}
}

Hello.

Yes, you should be able to use our newer QTRX-HD and QTR-HD sensors like the older QTR sensors, and you can use the same QTR library to do so. For those newer dimmable -RC sensors, you should use the QTRDimmableRC class.

As for your code, it does not follow our intended procedure for reading the QTR RC sensors, so I do not expect it to work reliably. In particular, it looks like you are not driving the line high and then making it an input to measure how long it takes to go low. We recommend using our library, but if you do not want to, your code should follow the procedure outlined in the “Module Connections” section of the QTR sensors’ user’s guide. (That same procedure is also described under the “Interfacing with the outputs of the RC versions” section of the QTR sensors’ product pages.)

-Jon

Hello Jonathan,

Thanks for the reply. I did use the examples in the Arduino library and was successfully able to read/calibrate the sensors. However there isn’t anything in the library that shows how to use the gathered data to for example turn an LED on and turn an LED off. Can you point me in the right direction? Thanks!

I’m not completely sure what you’re asking, but if all you want to do is indicate whether a particular sensor reading is below a certain threshold, you could do something like this:

sensors.read(sensor_values);

if (sensor_values[0] < 500)
{
  digitalWrite(13, HIGH);
}
else
{
  digitalWrite(13, LOW);
}

-Jon

Thanks Jonathan,

I’ve got the whole threshold thing down. The question is how can I go from threshold to just plain LOW and HIGH? Since the threshold will be different in different lighted environments. I want to be able to use this same code:

sensors.read(sensor_values);

if (sensor_values[0] < 500)     // CHANGE THIS
if(sensor_values[0] == LOW) {   // TO THIS
{
  digitalWrite(13, HIGH);
}
else
{
  digitalWrite(13, LOW);
}

That’s the question. Now I am using the QTR library and doing calibrations first and getting readings just fine and using threshold does turn on and off the LED. Thanks for the help so far.

I recommend looking into the calibration functionality provided by our QTR library. Those functions are designed to provide a way to consistently scale the sensors’ outputs to a 0-1000 range, which should make it practical to hard-code a fixed threshold like 500. However, depending on how your sensor is mounted, it often works reasonably well to compare the raw sensor readings to a fixed threshold as well (for an example, see this program for our Zumo robot).

-Jon

Thanks Jonathan I will look into that. Will this be able to work in different lighting conditions? Basically trying to find a dynamic threshold to account for different lighted environments. Or is there a way to make these sensors behave digitally as in On and Off? Sensor Covered equals OFF and sensor not covered equals ON without trying to fine that threshold? Thanks for the help.

It could work for your application, though whether or not it does depends on how much your environment’s various lighting affects the IR reflectance of the surfaces the QTR sensor is exposed to. You can test this by making sure that during sensor calibration, you expose the QTR array to all of the various surfaces and lighting conditions that it might encounter.

These sensors are not designed to simply output a low or high voltage (i.e. provide a digital output) based on the presence or absence of a reflected object; instead, they are intended to be read with the procedure described in one of my earlier replies and in our documentation, with the timing of the signal providing information on how much reflectance the sensor is detecting, and this will be across a range (not just 0/low or 1/high). Because of that possible range of outputs, you need to define your own threshold to meaningfully distinguish between what you consider to be “covered” and “not covered” in your particular application.

-Jon