QTR-8RC with arduino mega 2560

Hello there,

I was interested in knowing if it is possible to put two 8 bit sensors beside each other to detect lines. so the total bits being read would 16 bits. if it is possible what is the right way to code them? I connected the outputs of the sensors to pins 22-52 digital pins and also I have connected the 5 volts to the power supply and another ground from the power supply and also grounded the micro controller. I am getting garbage numbers. does this actually work?



Please try not to take this personally, but I am going to start out with a mini-rant: questions of the form “is it possible”, when not pertaining to something like theoretical physics, are a pet peeve of mine. I don’t truly believe that you think that somehow it is fundamentally impossible for two QTR sensors to function in proximity to each other, so I think what you are really asking is “does the sensor library support using multiple QTR sensors together?” or “can you help me figure out how to modify the library to use two sensor arrays together?” or “does a single Arduino Mega have enough processing power to read two sensor arrays?”. In general, most of the time you have to ask “is something possible” (e.g. is it possible to fly), the harsh answer is “for someone with the requisite skills (e.g. pilot training), yes; for you, apparently not”. So, if you are looking for a helpful response, please try to ask a more direct/appropriate question :slight_smile:

It looks like the QTR sensor library was designed to work with up to 16 individual sensors (or two 8-sensor bars), so it should just work if you get your program right. Can you post your full program and list your exact connections; I don’t know what “to pins 22-52 digital pins” means, but it sounds like you are connecting 16 sensor outputs to 30 digital pins. Do you mean that you are connecting to all of the even pins from 22 to 52, and if so, are you sure that you are connecting them to the pins you think you are (and not, say the odd pins from 23-53)?

Also, it’s not accurate to refer to these as “8-bit sensors”. The individual sensors on the board give an analog measure of the reflectance (as a function of pulse duration), so as long as you aren’t artificially using thresholds reduce the output of each sensor to binary, you have much more than eight bits of data.

- Ben

hey Ben,

No I don’t take this kind of thing personally. The reason I asked was because when I connect the outputs of the QTR-8RC to digital pins from 22 to 58, even or odd of the arduino mega 2560, I get inaccurate readings. When I have them connected to the pins 3 to 13 pwm digital pins, it gives me really accurate readings. I wanted to understand why this was happening but I might have been very vague with the question.
the line we have to follow in the maze is 6 cm to a max 10 cm in some intersections so the one array was not enough to cover the whole black line and have some outside white being read.

It seems like this should be a pretty simple thing to troubleshoot. Can you connect just one of the sensor outputs to pin 22 and the rest to pins that have worked for you in the past (i.e. 3 - 13)? I don’t know if you have two sensor arrays right now or were just asking about the potential of using two together, but for now let’s just keep it simple and use one array. Please post your full Arduino sketch, a list of all your connections (a picture might help), and good description of the output you’re getting (“inaccurate readings” is very vague; it would be more helpful to know that they jump around randomly, even when the sensor is not moving, or that they always read X, etc.).

- Ben