NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Sensors, Actuators, and Robotics » Inexpensive optical sensors: how to use?

April 01, 2010
by mosfet
mosfet's Avatar

Hi all,

I've found some optical sensors I'm considering using to sense the end of a range of motion, though they could be used to do countless things. They're a reflective optical sensor from Vishay, model TCRT1000.

Here's the datasheet: "Reflective Optical Sensor with Transistor Output" http://www.vishay.com/docs/83752/tcrt1000.pdf

My understanding:

Leads A and C(left) are the anode and cathode of an infrared emitter, an LED. Leads E and C(right) are the source and drain of a detector, a phototransistor.

When a reflective object gets close to the sensor, light from the emitter is reflected back to the detector, and its phototransistor begins to actuate, letting current flow from the drain to the source. The closer the reflective object, the greater the drain-source current, up to a point (closer than 1mm, the view factor of the reflective object and sensor starts restricting light from getting to the detector, making the current drop).

Questions/Thoughts:

Given that the detector gives off specific levels of current as reflective objects get close, how can this be used w/the NerdKit?

I'm a ultra-newbie, but it's my impression that the ATmega168's digital inputs read if voltage is high/5V or low/0V, and that the analog inputs read the level of voltage over the range 0-5V. I'm guessing both analog and digital inputs look like a voltmeter, an open circuit, in that they won't accept any (noticeable) current. Corrections or clarifications? I'm guessing a digital input of 4.5V would work, so what's the threshold, 3.5V or so?

So to use this optical sensor as an analog or digital input, would you just connect the source/pinE to both the input pin and a resistor to ground, such that the input pin sees voltage at the source/pinE as current flows through the resistor to ground? Calculate resistor size by R = Vdesired/Ispec'd.

For use as a digital input, say I'd want Vdesired = 5V, and Ispec'd = 0.1-0.2mA (seems like a safe range, datasheet page 4, upper left corner). Then R = 25-50kOhms?

What would happen if the source/pinE was connected to just an input pin? I'm guessing the input pin won't accept current (correct me if I'm wrong), yet the source/pinE is trying to output current. So does this just end up as voltage at the input pin? What's not clear is what kind of voltages to expect for any range of distances between sensor and reflective object.

And a dumb trailing question: why do they have 2 leads named C?

Thanks, mosfet

April 01, 2010
by bretm
bretm's Avatar

I don't think those are lead names, but abbreviations: A, C, E, C are Anode, Cathode, Emitter, Collector.

I wouldn't connect this to a digital input pin. You really want near 0V or 5V for those. Instead, if you want a digital result, you should use the Analog Comparator and connect it AIN0. Then you can pick whatever threshold voltage you want.

April 01, 2010
by mosfet
mosfet's Avatar

Thx bretm,

Ya, I figured A and C were named such for being the anode and cathode. I was unsure about the pair on the right, E and C; I saw emitter and collector mentioned in the datasheet, but was confused since the left pair of leads (A and C) themselves drive an emitter (infrared LED). I guess if I read-up on phototransistors it would've been more clear to me.

I was about to ask if an analog comparator takes an analog input -> a-to-d converts it -> compares it to some value. But just read something and it sounds like an analog comparator is likely more efficient without the a-to-d processing, and just takes 2 analog voltages and outputs 5v if 1st is higher and 0v if 2nd is higher.

So to generate appropriate voltage from the sensors output current, I'm assuming a resistor to ground is still needed? Sized so sensor's max current gives 5v? And where do I get the other voltage to compare to? Maybe 2.5V from a 5v voltage divider?

I'd be grateful to hear responses to my other questions. I'm sure the answers to some/many are in the ATmega168's datasheet, but it's pretty daunting at 400 pages, and I might not even recognize an answer if I found one.

April 01, 2010
by bretm
bretm's Avatar

Yes, the comparator just compares one voltage to another. 2.5V from a voltage-divider would be fine, but you may want it adjustable depending on what you're doing. A standalone comparator would output +5V or 0V, but this one is internal--it just sets a bit on an internal register to 0 or 1. It's the "ACO" bit on the ACSR register, so you would read ACSR & (1<<ACO).

And yes, connect the collector/emitter pair in series with a resistor. VCC -> resistor -> collector-emitter -> GND. Then connect AIN0 to the point between the collector and the resistor.

I'm not exactly sure the behavior you'll see, though. If the collector-emitter current is very low because it doesn't detect much light, then the current through the resistor will be low and the voltage drop across the resistor will be low, so the voltage drop across the collector/emitter will be near 5V. But this doesn't match up with the chart in the datasheet that shows the relationship between the collector-emitter current and the collector-emitter voltage. Just hook up a meter and see what happens, I guess. :-)

I'd start with a 10k resistor based on the values in the datasheet.

If you just connect the emitter to an input pin without a resistor, it would be an open circuit and current shouldn't flow. But I'm not sure how the AIN0 pin would behave if the Analog Comparator module is turned on. Usually those inputs are high-impedance also.

Feeding the anode/cathode pair with current can be done with an output pin and a series resistor, or just VCC if you don't ever need to switch it off.

April 01, 2010
by bretm
bretm's Avatar

Ok, I see how this is going to work now. Let's say you use a 10k resistor in series with the detector and then you measure the voltage drop across the detector. You're going to end up measuring something along the red line:

Sensor

The top end of this red line is at Vce=0.1, which means Vr=4.9 (because Vce + Vr = 5V), which means at R=10k the current must be 0.49mA.

The bottom end of this red line is at Ic=0.01, which means Vr=0.1V, which means Vce=4.9V.

Every other reading has to be somewhere along this line. As the brightness goes up, the Vce voltage will go down because the current and the voltage drop across R goes up.

If you run the LED at 10mA the voltage can't go below the green line (assuming the Kodak Neutral Card White Side), which is about Vce=0.3V. So you'll be measuring between 0.3V and 5V.

If you use a larger R, the red line will drop lower, leading to a slightly wider voltage swing.

That's my prediction, anyway.

April 02, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi mosfet,

In your original set of questions, you were curious about at what voltage levels a digital input is considered 0 versus 1. That's answered in our Buttons, Switches, and Pull-up Resistors section of one of our video tutorials. Quick summary is that <1.5V is guaranteed to read "0", >3.0V is guaranteed to read "1", and the actual transition is somewhere in between and varies between devices.

Bretm,

I like your approach with the graph, however I wanted to point out that the axes are log-log, so you can't just draw a straight line for the resistor.

Mike

April 02, 2010
by bretm
bretm's Avatar

That's a good point. It's actually not going to be anywhere near a straight line. I've added a purple line that should be right. It suggests that a 33k resistor might be a better choice for a good response range.

Post a Reply

Please log in to post a reply.

Did you know that microcontrollers have two different kinds of memory, program space (flash) and SRAM? Learn more...