If you connect a known
If you connect a known resistor between +5V and your analog input, and then connect your pot between the analog input and ground, you can read the analog voltage and use it to determine the ratio of the two resistors =)
That is interpreted wrong.
That is interpreted wrong. Reading the datasheet for the QRB1134, collector current for the device can be a minimum of 0.6 mA when coupled, which means the collector pull-up should be even higher. Max current is rarely seen.
Calculating to get greatest voltage swing on output : 5 volts - 0.4 volts (Vce-sat) = 4.6 volts to drop across the resistor. Ohms law V=IR rearranged to V/I=R ~ 4.6 / 0.0006 = 7666 ohms. I’d personally double the resistor to 15k, to allow more easy switching. Going lower would only lead to “analog” operation in when the micro reading this probably needs a digital signal.
Now for the resistor to the LED, to allow max output to be reflected appears to require 40 mA. Again, the forward voltage of the LED is a max of 1.7 volts in operation, so 5 - 1.7 = 3.3 volts, => V/I = R ~ 3.3 / 0.04 = 82.5 ohm, so around 100 ohms would be a better choice for an LED resistor, getting more light output.
In my line follower robot, I
In my line follower robot, I used QRE1113GR sensor and tried it first 10k pull-up resistor and it did not work. Then I tested 1k pull-up resistor, and it worked well.
It would be nice to get past
It would be nice to get past all these vague generalities like “it did not work”. I’d imagine that it did work, just not in the manner you were expecting. In electronics, extra factors need to be considered. Like specifically, what was the rest of the circuit? Did this feed directly into a micro and what type of input did it go to, ADC or GPIO or comparator? Even testing with just the circuit by itself can lead to different results than with it connected to the input of a micro. What was the input resistance of that input? Was it a 5 volt supply or a 3.3 volt or raw from the battery? Scope traces that have been presented can be helpful in trying to determine what “does not work” and why.
One possible trip up to operation of a circuit with an output going to a micro GPIO using a 10k or higher resistor is in the capacitor placed there. If only a 0.1 uF decoupler, then the larger resistor would have little trouble changing the voltage on that cap. If a larger cap, maybe an electrolytic of 10 uF, 50 uF or more was there, then the slowing of current delivery would have a slowing on switching at the input, possibly “not working”.
There are a number of example robots that use reflective sensors like these directly connected to a micro, built by folks that may or may not know any better. Whenever the sensor is put together as it’s own module that someone sells as a product they are liable for, some sort of output buffer appears to be used, to ensure better operation. I’d suggest that the main key is there, in getting some type of buffer to ensure good readable switching of the module.
Lynxmotion Line Tracker sensor V.3, using a 74HC14 Schmitt trigger
Pololu Encoder using Schmitt triggers on outputs
Lynxmotion single line detector using a comparator as a buffer
An exception to using a buffer Pololu QTR-1A reflectance sensor using the same QRE1113GR sensor with a 150 ohm LED resistor and a 47k (!!!) collector resistor. So why would a well known robot company sell a sensor that “didn’t work” because the collector resistor was too high?
I’m sorry my previous
I’m sorry my previous answer, I answered without thinking … I checked my schematics and pull-up resistor is 33k and the sensor is directly connected to the micro controller (PIC16F876) GPIO, this works well. The sensor was not working with the 1k resistor, but works with a 33k resistor. Sorry again my previous bad answers.
Still testing
Didn’t buy the pots yet (that will have to wait until the weekend). However I’ve been trying a lot of different combination of resistors and caps as well. None of them give me the readings I’d like to see. So far the best I’ve got was using a 30K (or rather 3 x 10K in series) pullup and a 220 Ohm LED resistor.
This is what a LOW reading look like with that setup:
And a corresponding HIGH reading:
So perhaps an even higher pullup would improve the setup further?! Unfortunately I've run out of high value resistors.
Still I can't help thinking that something is very wrong. It's NOT supposed to fluctuate THAT much!! In particular the HIGH readings shouldn't frequently drop to 0V nor rest on ~1V as you can see on the scope. I think I'm gonna buy another sensor (eg. the QRD1114).
Anyway thanks a bunch for all the input. You guys are great :D
Thanks
I thought the setup would be something like that. BUT I still don’t know how to calculate the resistance. I can’t use ohm law because I don’t know the current…or?
Ohm’s law for the high-side
Ohm’s law for the high-side resistor (fixed value): Ih = Vh/Rh
Ohm’s law for the low-side resistor (pot): Il = Vl/Rl
Where I is the current through the resistor, V is the voltage dropped across the resistor, and R is the resistance of the resistor.
As the two resistors are in series with nowhere else for the current to go, the same current must flow through both resistors. In math terms: Ih = Ir. This also means that we must have:
Vh/Rh = Vl/Rl
We can rearrange the above to form:
Vl/Vh = Rh/Rl
We also know that the voltage at the top of the high-side resistor is +5V (or whatever) and that the voltage underneath the low-side resistor is 0V. We know that the 5V must be completely depleted by both the resistors, in other words:
Vh + Vl = 5V
Or, to put it another way:
Vh = 5V - Vl
Now we can substitute the above into the equation from the previous section to get:
Vl/(5V - Vl) = Rh/Rl
Then we can shift this around to get:
Rl/Rh = (5V - Vl)/Vl
Rl = Rh×(5V - Vl)/Vl
Rl = Rh×(5V/Vl - 1)
Tada! We already know what Rh is because we chose a known resistor, and we can get a reading for Vl from the analog input. If you put both of those number into the last equation then the value of Rl can be determined. If you use a supply voltage other than 5V you just have to change the 5V in the last equation to whatever you’re using.
to work or not to work
In my case I’m feeding it 5V regulated from my Arduino. I’ve tried pullup values of 3.3K, 5K, 10K, 20K, 30K and LED resistor values of 110 or 220 Ohm. Best combination so far was 30K and 220 Ohm.
And you’re right that “doesn’t work” isn’t very useful at all. I’m not expecting to get a perfect square wave either but the extreme fluctuations I’m getting don’t leave me much to work with. For instance Rudolph can’t get his setup to “work” either but his readings look like this (without using any so called buffer):
Not quite a perfect square wave either yet the HIGHs and LOWs are CLEARLY distinguishable from eachother. Even if it's not enough to trigger an (interrupt) digital HIGH/LOW smoothly it's still something you can work with...unlike my readings.
BTW I also tried some higher value caps. I Didn't have any 1uF ot 10uF around so I used what I've got: a 33uF and 100uF electrolite. Didn't improve my readings at all just slowed down the transistion.
PS: This sensor board doesn't use any buffer either.
Cool!
thanks
So…
The saga of the messed up encoder continues…
I went shopping a bit and bought a 74HC14 Schmitt trigger, a pot for the pullup (1K - 100K) and some caps and stuff. Couldn’t find a pot suitable for LED resistor replacement though. Couldn’t find any QRD1114 sensors either (they tried to sell me a CNY70 instead?). Just like I couldn’t find most of the stuff I was looking for
Oh well I’ll try to replace the pullup resistor with the pot and see if I can find the optimal setting (thanks for the tip jklug80) while experimenting with different LED resistors and caps.
About the Schmitt trigger…I have no idea what to do with it just yet so I’ll probably be asking some (noob) questions over the weekend.
Aniss over and out
A few pot questions
I’ve now tried to hook up the pot instead of the pullup resistor. Just wanna double check that I’ve got it right…
The pot looks sorta like this:
* The pot has 3 legs. 1st is for power, 2nd is for ground and the 3rd (the middle one on the opposite side of the others) is the wiper. Is this correct?
* I suppose that it isn't polarized so it doesn't matter if I interchange the ground and the power pin?
* I suppose that the 1st replaces the high side of the resistor, while the 2nd is connected directly to the ground, and the wiper must replace the low sid?
* The pot has a range of 1K to 100K. When I hook it up and pull it to one extreme I get all zero readings no matter what I do with the sensor. I suppose this is when it's at its minimum (1K)?
* When I pull it to another extreme I get readings like this (fluctuating rapidly between 5V and 0V):
I suppose this is when the pullup resistor is 100K. Isn't it strange though that it doesn't just stay high instead of fluctuating like that?
That's it for now :)
• Yes, middle leg is the
• Yes, middle leg is the wiper. How you connect the other two depends on the application - if you just want a variable resistor then you often leave one leg disconnected.
• If it’s polarised then it’s not a resistor =)
• Are you talking about using it to bias the phototransistor for the IR detector? If so, you’ll want to connect one of the outer legs to V+ and the wiper to the top of the phototransistor, leaving the other leg out of the circuit altogether.
• It really depends how the whole circuit is wired up - either way you likely have a large resistance between the analog input and V+.
• Potentiometers often have poor contacts when they’re turned right to the limit, this may be the cause of the fluctuations.
The 74HC14 Schmitt Trigger Inverter is an IC that I’ve used many, many times. Very handy little IC. Go to Octopart.com or somewhere like that and grab a datasheet; if you have any questions after having a look there let me know.
Thanks!
As usually you’re the man…unfortunately I’m not so I’m still unclear about some things…
* OK! I only want a variable resistor!
* Didn’t think so…check!
* I’m simply trying to replace the pullup resistor with a variable one so I can fine tune the setup. So it seems I should NOT have connected the 3rd leg directly to the ground as I did (which means I spent an hour of testing with a flawed circuit).
* I’m using the exact same circuit as before only with the 10K pullup resistor replaced by a pot (1K - 100K):
* I'm afraid that isn't the case. If you look at the scope screenshots I've posted earlier you'll notice that I've been getting these EXTREME fluctuations all along (with the fixed resistor also). I haven't been able to get a pure high signal at any time. It constantly fluctuates between cero and a high voltage no matter what I've done. That seems to be my problem.
PS: I've allready got the datasheet for the 74HC14 and I found some examples on how to hook it up in similar setups. I'll be studying those and then probably I'll come back and ask a question or two :D
PPS: Are you SURE that it isn't the WIPER I should leave out of the circuit?
Ok, so to use a pot as a
Ok, so to use a pot as a variable resistor you want to connect one leg to V+ and the wiper to the top of the phototransistor (collector terminal). If you were to connect both outer legs and leave the wiper disconnected, you’d have a fixed resistor, with resistance equal to the maximum resistance of the pot.
OK
It’s just odd cause when I connect the pot directly to the Arduino (without the sensor circuit) connecting one outer leg to 5V and the middle leg to the analog in and leaving out the other outer leg (the ground) I get all high readings (as if it was a fixed resistor)…
Anyway I’ve been trying it like you said and still no luck. I’m about to give up on this cause my readings don’t make any sense no matter what I do. I’ve tried it with 3 different sensor units, all sorts of resistor values, caps etc etc and I just can’t get some readings that make sense.
Even when I block the sensor input completely (thus I’m supposed to get all high readings) I get readings like this:
1023
0
1023
0
999
0
1011
0
…etc…
And then suddenly I get:
220
220
220
220
…etc…
Until it drops back to the previous pattern. If you look at the scope screenshots you’ll notice that is the plateau where it sometimes rests in between the HIGH and 0 readings.
The low readings ALSO frequently rest on that exact same number: 220. Like it was some magical number. It doesn’t make any sense.
If you connect any resistor
If you connect any resistor between V+ and a very high impedance input (such as your analog input pins) then almost no current will flow through the resistor. Since almost no current flows, V = I/R = ~0V, which means no voltage is dropped across the resistor. Therefore the voltage is the same at both ends of the resistor, i.e. voltage at the input is ~V+.
Now, for the bit that doesn’t make any sense, your actual input readings… Something is seriously wrong there, I can’t think of any behaviour that the sensor circuit exhibits that could explain such wild readings especially when the sensor is blocked off. Noise from nearby circuitry? I really can’t say =/
The plateau at 220 is also very odd… if the sensor circuit was jumping around like that I can’t think why it’d be able to sit at a stable value to within ~4.9mV. Perhaps there’s something in the code to explain it, but in any case I can’t think of any obvious causes.
Geez!
OMG IT’S WORKING
I have no idea what was wrong before though because I started all from scratch again…that is rewrote the code and rewired the circuit on a different part of my breadboard using different resistors and mostly different jumper wires. So now I’m getting beatyful HIGH/LOW readings:
At some point I will try to find out what was wrong before but right now I'm more interested in seeing what I can do with these readings. :P
Thanks for your help and patience and sorry if I've wasted your time unnecessarily (TeleFox). If it makes you feel better it's nothing compared to the HOURS I've wasted myself probably because of some silly noob mistake :/
Most of the stuff I wrote
Most of the stuff I wrote was just generic electronics, worth knowing anyway. What resistor value/s did you use in the end? No doubt Rudolph and others using a similar circuit would be interested.
Also, what is the difference between the high and low voltages? The levels are quite nice, but of particular importance is how clean the transitions are, that should make processing the encoder pulses almost trivial.
Well…
The screenshot you see is based on a 220 Ohm LED resistor and a 20K pullup and a 1uF cap. I didn’t even try other resistor values yet to see if I can improve it but I did try it without the cap which gave pretty much the same result so I think I’ll just loose it alltogether.
The voltage levels differ A LOT according to the light in the room. In particular the HIGH signal changes over 1V when I turn on/off my lamp. And I didn’t even try it in daylight yet. I suspect this could be the source of Rudolph’s problems. He’s doing his testing/calibration with the servo open and when he closes it up everything changes.
Anyway each square in the background grid of my homemade oscilloscope represents 1V. The LOW signal is damn close to cero (around 0.1V) and the HIGH signal is around 3V when the lamp is on (as in the screenshot) and 4V when it’s off. But I may be able to improve on that with a little fiddleing around.
Allready now the signal is clean enough to make an encoder work using the analog readings But I think I’ll still try to connect the Scmitt-thingie to see if I can get it closer to a nice squarewave that can trigger a digital input steadily. This would be ideal because then I could use interrupts to detect the transitions.