interestingfellow:
OldSteve....I'm sorry for being a noob and asking noob things, but I'm stuck.
After tinkering quite a bit with the salvaged components unsuccessfully, I decided to eliminate potential problems 1 at a time. I bit the bullet and bought an IR emitter/detector set from radiocrack and I still can't get this breadboard and sketch to work. I tried both common emitter and collector arrangements that you provided above, and am going insane trying to figure out why it won't work.
AND, I did read several sources on my own trying to figure it out, but I'm still missing something.
When I use the code below:
void setup() {
pinMode(4,INPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(digitalRead(4));
delay(100);
}
In common collector configuration, I get only "1" (high) over the serial monitor unless I unplug the phototransistor, and then it changes to "0".
In common emitter configuration, I get only "0"(low) in the serial monitor. . The only way I can see a change in serial monitor is if I unplug the sense wire to pin 4 and short it to the vcc rail.
I have verified that the IR led is emitting using my phone camera.
I have verified polarity of the emitter and the detector.
I have tried only 1 150ohm resistor driving the emitter to make it brighter.
I have tried 47k, 1k, and 150ohm on the detector in both configurations.
And, of course, I have tried it with the lights in the room on and off.
I used a hotel keycard in the paper sleve to block the emitter.
I also tried removing the emitter completely.
And I still get the same results.
Wth am I doing wrong?
For one thing, an IR LED has a Vf of about 1.2V to 1.5V. Allowing for 1.2V, that means there will be 3.8V across the resistance.
An IR LED should be driven with much more current than a standard LED. Most want about 100mA continuous.
3.8V/100mA=38 ohms. So for maximum brightness from a constantly on IR LED you could be using a 39 ohm resistor, instead of the pair of 150 ohm resistors. At the moment, you only have 11mA going through the LED.
(You should double-check the datasheet of the IR LED, for Vf and for continuous current rating, then select a resistor accordingly.)
I can't see your photo-transistor well, but you say "flat=cathode". A photo-transistor doesn't have a cathode, only a collector and an emitter, (if it's 2-pin). still, assuming you have the emitter to ground, with a resistor to +5V, and the output taken off the collector, it should go low when exposed to IR.
And although weak, I would have thought that since the IR LED and the IR photo-transistor are so close together, it would still work. Try a much smaller resistor on the IR LED, between 39 ohms and 100 ohms, (check the datasheet first for specs), and change the 47K resistor on the photo-transistor to 4K7, or even 2K2. 47K is a bit too high a value.
I don't know what else to suggest if that fails. This is so simple, that if connected properly nothing can really go wrong, unless the phototransistor has been shorted/overloaded and is dead. Did you buy several? If so, try another. If not, you should have.
Putting 150 ohms on the collector as a load resistor wasn't a good idea. That's 33mA, and they're not typically rated anywhere near that high. Good chance it is dead. Edit: Correction, it's probably not dead - since in CE configuration, it stays low, it's staying switched 'on'. A dead transistor usually goes open and would stay high with a pullup resistor.
Don't just try random values on things - everything must be calculated, according to the datasheets.
Of course, this setup, even when working, is no good for any practical purpose, since it's not immune to ambient light/remote controls/fluorescent lights.
Ideally, you would drive the IR LED with a 38kHz or 40kHz carrier, modulate that carrier with codes, then use an IR receiver to 'demodulate' the carrier leaving just the codes (inverted). That's how an IR remote control does it.
By coincidence, I'm working with an IR LED and a receiver myself today, making an IR homing beacon and receiver for my robot car. (Using a 38kHz carrier and demodulating receiver.)