Hey there. I just got into my first Arduino project and ran into a snag I can't seem to move past. I'm trying to build a simple chronograph for airsoft rifles firing 6mm BBs that uses a tube with two IR LEDs aligned with two photo transistors that are recessed in their own little cups. The LED and transistors I'm using are a pair of Radioshack 276-142 (LEDs are standard, photo transistor is listed as a "20v, 25ma" unit.)
My chrono code is a bit longer, but here's my test code for a single sensor.
When monitoring the sensor over serial it's running between 495-501, if I disconnect the IR LEDs it drops to 0 so I'm positive I'm not getting any light leakage. If I stick my finger or a 6mm BB glued to a stick (real high tech here) it triggers, but if I shoot through it I get nothing. I've tried a number of AEGs that range from 280-350fps.
Is there anything I can do to increase the sensitivity of the transistors, or is it a problem with my chip (using a RBBB with the ATMega328p) not running fast enough to catch the blip?
Two things: I don't think your circuits are right. The 1k resistor should be from +5V to C, and the C signal should go to the analog input. The E should be connected to ground.
Second, phototransistors do take a bit of time to go high and low. If the pulse is too short, it might just be too fast for the transistor. Any idea how fast these BB's are travelling? Can you estimate for us how wide the pulse will be?
Thanks for the reply, I rewired the transistor as you had described than took a few shots through it and it worked! The way I had it wired previously was reading high and dropping when the light was blocked, now it's reading low and going high instead and must be reacting much quicker.
I need to head to bed, but I'll wire everything back up and try it with the full chrono code tomorrow and update after I find out how it works. Thanks again for the suggestion, I still have a lot to learn and am incredibly surprised I haven't killed this poor little Arduino clone yet. Actually, I got close last night and borked the boot loader but managed to build a functioning parallel flasher out of an old floppy disk cable and some left over pin headers.
Doing this with the analog inputs is introducing very large timing errors.
You want to do something like add a pair of comparators to speed up the conversion of the analog signals to digital inputs: you need to experiment a little to tweak the comparison threshold to define what's "on", but you don't need any more precision than that.