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.

Basic Electronics » Problem with NPN Phototransistor

December 21, 2010
by Ralphxyz
Ralphxyz's Avatar

Let me say at the top I really do not know what I am doing.

I am "trying" to use a NPN Phototransistor as a pulse counter. On (HI) when IR detected off (LOW) when not.

All measurements taken at C (Collector) NPN Phototransistor.

    +5v ---- 1000Ω Resistor ----(Anode) LED (Cathode)-----(Collector) NPN Phototransistor (Emitter)----------------- Gnd
                                                                       |   |

    +5v -------------------------------------------------------(Anode) IR LED  (Cathode)--- 150Ω Resistor --------- Gnd

First of all the NPN Phototransistor allways has voltage at the Collector!! Why?

With the IR LED NOT powered I measure 3.45v.

With the IR LED POWERED I measure 2.83v.

If I completely cover the NPN Photoresistor I measure 3.35v and the LED has just the slightest glow.

While the voltage is close to constant (+- 1v) the current obviously drops.

The Phototransistor/LED pair are from Radio Shack part number 276-0142.

Is this what I should be seeing.

I want to send a high (pulse) to the Nerdkit to count. I am attempting to make a Anemometer so I need to count revolutions.

Thanks once again for the help,

Ralph

December 21, 2010
by Ralphxyz
Ralphxyz's Avatar

Damm senior moment, I had the NPN Phototransistor reversed.

I still need help in understanding what I am seeing!

IR off -162mv.

IR on - .46v.

Do I need a op-amp to send the pulse to the Nerdkit?

Would I need to boost the pulse to 5v? I am going to use a mcu counter for 10 seconds counting the pulses.

Or at least that is what I thinkI am going to do.

Thanks again for the help,

Ralph

December 21, 2010
by mongo
mongo's Avatar

Nope... You need a PNP transistor. But since you have an NPN, here is what to do.

To get the LED to light with the IR, connect the anode to the positive rail. A resistor to the cathode and the other side of the resistor to the collector. Connect the emitter directly to the negative rail. NPN transistors act just opposite of the signal. So it is effectively, an inverter.

To swap it around, you can add another one in line similar to that one but in this case, collector of the photo transistor through a 10K resistor to the base of a regular transistor. That would re-invert the signal output at the collector. Make sure you have a resistor from the positive rail to the collector.

If you use a PNP transistor, simply reverse the power supply and the output would be high for on, low for off, at the collector.

December 21, 2010
by mongo
mongo's Avatar

Hmmmmm... I just looked at the first post. You have it the way I mentioned. Hmmmm...

December 21, 2010
by Ralphxyz
Ralphxyz's Avatar

How do I talk with the Nerdkit mcu counter pin?

I have a clear transition -.46v (IR LED ON) to -162mv (IR LED OFF).

If I connect the Collector to the ADC it is low (at -.46v) so I need to boost -.46v to > +1v (posible +5v).

Is there a different way to wire up the NPN Phototransistor to show positive voltage?

Ralph

December 21, 2010
by mongo
mongo's Avatar

There is. It's a TTL driver. The difference is that a TTL chip has internal pull up resistors at the inputs. You will need to do it in 2 stages so a high input gives a high output.

The circuit I described earlier should do the trick.

December 22, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Ralph,

Did you see our IR LED and phototransistor example?

Try to measure the voltage across your 1K resistor, as this will directly show you the current that the phototransistor is allowing to flow.

You may also want to increase the value of the 1K resistance (try even 10K or 100K) as this will directly multiply the sensitivity of the sensor. This boosts the sensitivity to your signal, but also boosts the response to any ambient light, and may also slow down the frequency response of the sensor, which may matter depending on how fast your anemometer is spinning!

Measuring the voltage across the phototransistor itself generally isn't the most useful measurement to make. You should really look at the phototransistor as a "light-controlled current source", where the current it allows to pass through it depends on the received light level. An ideal current source sinks or sources the same current regardless of the voltage across it. The phototransistor isn't a perfect current source, but for a wide range of inputs, the actual voltage across it has no effect on the light-dependency (until the sensor saturates).

My suggestion would be to try taking the LED out of the phototransistor current path (just to make sure nothing else is saturating), and then measure the voltage from end to end of your 1K resistor both with and without light. Then, increase the value of the 1K resistor until you get a large enough signal.

Mike

December 22, 2010
by Ralphxyz
Ralphxyz's Avatar

Hi MIke thanks for the reply and thank you Mongo for your help (so far :-).

I am just now looking at the IR LED and phototransistor example Thermin project.

I really was not measuring the voltage across the phototransistor (at least I do not think I was) I just used C (Colector) as a reference point. I was measuring C to Gnd.

I have since remove the LED (which illustrated the current strength by bright or dim).

Using the same setup as the IR LED and phototransistor:

With IR LED ON I measure 4.90v (ADC: 1019 of 1024 from tempsensor program_

With IR LED OFF I measure .65 - .66v (ADC:135 to 140)

Will the mcu (ATmega168) see .65v as a low (off) if not how can I make a off out of .65v as far as the mcu is concerned?.

I do not think I want to use external components or to much code as I imagine the led is going to be very rapidly flashing and I want the mcu to keep up.

Here is a question for you math whizzes.

I have a 1.5" diameter disk which gives me a 2.355" circumference what will be the speed of the disk in a 10 mph wind? What about a 60mph or 100mph wind?

What will the RPM be?

Ralph

December 22, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Ralph,

Check out page 304 of the ATmega168 datasheet (Electrical Characteristics). The maximum V_IL = 0.3 * Vcc , and the minimum V_IH = 0.6 * Vcc. That means that when operating at 5.0 volts supply, any voltage 1.5V or lower is guaranteed to read as a digital 0, and any voltage 3.0V or higher is guaranteed to read as a digital 1. (The voltages in the middle / the location of the actual 0 to 1 transition point may vary from individual ATmega168 chip to chip.) So, in summary, I think you can connect your signal directly to a digital input, although you probably want to use some software "debouncing" to prevent unintended multiple transitions on each edge.

As far as your anemometer setup, what does your disk look like? (Post a photo!) If it's something like a cup type anemometer you can do some math relating to drag coefficients, but in any case, I'm not sure that you can really avoid calibrating it against a "known" wind speed.

Mike

December 22, 2010
by Ralphxyz
Ralphxyz's Avatar

Hi Mike thanks, I knew there was a cutoff value somewhere I was thinking it was .5v so this should be great with 4.9v ON and .65v OFF. I should get a good pulse, now will the phototransistor be fast enough to catch the flash?

Here ya go with a first peak at my anemometer, Ta Dah:

I hope to do a Instructables on the construction and programing (I'll give lots of credit to the Nerdkit of course).

My faithful Dremel 395 Type 5 died after 15 years and I just could not stand the thought of throwing it out until just the other day I actually threw it in my trash can. In the mean time I have been thinking about installing a wind turbine and thought I needed to get some wind speeds. I had bought a anemometer through Amazon (sight unseen of course) and received this little 3" x11/4" device with a 1" wheel. I never got it to work. So I was thinking I aught to just make a anemometer and use the Nerdkit for the electronics. Then I started thinking that I would have to come up with a shaft and bearings to mount the cups on. I puzzled on this for two or three days before it hit me "Duh!!" I have my old Dremel that has a shaft and bearings and is good for 30,000 rpm so I put it together.

I haven't the slightest idea what I am doing other than I am good with my hands and I am pretty mechanical by nature. Everything is just set and built by eye but notice the anemometer balances on the end of the dremel so I must have the balance pretty close.

The cups are some stainless soup ladles from the local 95¢ store.

The anemometer is 18" in diameter, I wasn't sure for rpm (speed) calculations if I would use the anemometer or the disk on the shaft with the phototransistor (1.5").

For speed calibration I'll mount the anemometer on a pole and mount that on my truck and then tool on down the road coming and going I should get a average speed/pulse reading. It's amazing just Google MPH to RPM and you get all sorts of calculators so I be able to figure out hertz.

Of course I could easily mount a magnet on the disk and use a Hall Effect sensor if the phototransistor cannot keep up.

So far so good, I am sure I will have more questions on pulse counting and interrupts etc.

So far I am using the tempsensor project ADC reading to see the IR LED ON/OFF. I do not believe I need to use the ADC for puse counting, time to re-read the specsheet.

Ralph

December 22, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Very clever with the soup ladles!

As a rule of thumb, the rotational speed at the cups should be very roughly 1/3rd of the wind speed. (See this presentation which sets up a force balance between opposing cups and gets to the square root of the ratio of drag coefficients for each side of the spoon. Importantly, and possibly incorrectly, it assumes that there is no drag at all due to the rotor / bearings / etc! It makes lots of other assumptions that are probably wrong too, but it's a good place to start before doing any calibration.)

If the thing measures 9" from center to the middle of one spoon, then: 10mph/3 = 3.33 mph. 3.33mph(5280 feet/mile)(12 inches/foot)/60(minutes/hour) = 3517 inches per minute. Divide by the circumference: (3517 inches/minute)/(9*pi inches/revolution) = 124 RPM. So 10mph wind will yield about 124 RPM, 60mph will yield 743 RPM, and 100mph wind will be 1243 RPM.

At the highest rate, 1243 RPM, that's still only 20 counts per second (assuming you have one reflective and one non-reflective part per cycle). That's totally slow enough to count whether you end up using a digital input or the ADC.

Mike

December 22, 2010
by Ralphxyz
Ralphxyz's Avatar

Excellant, actually the efficiency of the wind turbine does not matter if I only want to measure wind speed.

Once I have it all working and calibrate it to mph it doesn't matter if it is 1/3rd or 1/15th it will just be what it will be.

It will always be proportional.

If I was trying to generate power (which I have thought of doing) then the efficiency would be important.

Thanks for the calculations and formula this all works out great.

Thanks again Mongo and Mike and all the rest of you who were hoping I'd get my answers.

Ralph

December 23, 2010
by mongo
mongo's Avatar

I have two cup anemometers here. One is on my weather station and the other is going on the wind turbine project. I have checked them with a different style of anemometer and a tachometer so I have the reference numbers.

Not using optos though, instead, I am using a hall effect sensor.

December 24, 2010
by Ralphxyz
Ralphxyz's Avatar

I think the opto will work. I have enough space within the body of the Dremel to use two optos and a hall effect can also be added so I have a great platform to experiment and learn on.

I was thinking about using two optos in order to not have to use any debounce code, noise cancelling. My thinking is if both sensors see some activity then it must be a positive action so count it as a event.

Speaking of Noise Cancelling has any one used ICNC1 in the TCCR1B register to activate noise canceling page 137 in the datasheet?

15.11.2 TCCR1B – Timer/Counter1 Control Register B

•   Bit 7 – ICNC1: Input Capture Noise Canceler
Setting this bit (to one) activates the Input Capture Noise Canceler. When the noise canceler is activated, the 
input from the Input    Capture pin (ICP1) is filtered. The filter function requires four successive equal 
valued samples of the ICP1 pin for changing its output. The Input Capture is therefore delayed by four 
Oscillator cycles when the noise canceler is enabled.

Here is another math quiz how long is "four Oscillator cycles" @ 14,745,600Mhz?

Will my phototransistor's pulse last four oscillator cycles?

I have a hard time comprehending something happening 14 million times a second to say nothing about how long four cycles will last.

So using Mike's calculations "At the highest rate, 1243 RPM, that's still only 20 counts per second"

I am using a slotted disk, the slot is about the size of a normal led (5mm) so how long will the Phototransistor be exposed to the IR LED?

The slotted disk is about 38.1mm in dia. (not the anemometer the sensing disk) giving a 119.69mm circumference.

5mm is about 4% of 119.6 so the phototransistor will be lit approximately 4% of a revolution.

That is about as far as I can go, my head is swimming ...

Help!!

Thanks again,

Ralph

December 24, 2010
by Ralphxyz
Ralphxyz's Avatar

I just couldn't leave this alone please check my logic and subsequent math.

"four Oscillator cycles" @ 14,745,600Mhz

If I am getting 20 counts (revolutions) per second than 1/20th of 14,745,600 means there will be 737280 cycles per revolution.

The slot is approximately 5mm wide on a 31.5mm (diameter) rotor giving a 98.96mm circumference.

The 5mm slot is approximately 5% of the circumference meaning the Phototransistor will be lit for 5% of a revolution.

5% of the 737280 mcu cycles will mean that the Phototransistor will be lit for 36864 mcu cycles.

There "should" not be a problem, it appears there will be lots of time to capture the 4 Oscillator cycles.

Is this correct I am assuming a Oscillator cycle is a mcu clock tick.


Now can I use PIN 14 (PCINT0/CLKO/ICP1) PB0)? As my counter pin?

Will there be a problem with the bootloader code? I think the bootloader only cares if PIN 15 is to Ground

so it "should" not matter, correct?

My obsessive nature forces me to question things like this, thanks everyone for the help and understanding.

Ralph

December 28, 2010
by Ralphxyz
Ralphxyz's Avatar

Boy Mike you really threw me with your math:

"If the thing measures 9" from center to the middle of one spoon, then: 10mph/3 = 3.33 mph. 3.33mph(5280 feet/mile)(12 inches/foot)/60(minutes/hour) = 3517 inches per minute. Divide by the circumference: (3517 inches/minute)/(9*pi inches/revolution) = 124 RPM. So 10mph wind will yield about 124 RPM, 60mph will yield 743 RPM, and 100mph wind will be 1243 RPM."

C=d*π (183.14159)not C=r*π (93.14159) "the thing measures 9" from center to the middle of one spoon" <-- thats radius!

The Diameter is 18" the radius is 9" so that should be 3517 / 18 * 3.14159=62rpm.

This is even slower so there "should" not be a problem with pulse capture timing.

Ralph

Post a Reply

Please log in to post a reply.

Did you know that you can use printf and scanf functions to talk to your computer from your USB NerdKit? Learn more...