So I was trying to learn a little bit tonight with phototransistors. I've got a project where it will come into good use. So, after a little reading I came across this code:
///////////////////////////////////////////////////
//Project 5.01 Read the phototransistor
int photoTran = A1;
int reading = 0;
void setup(){
pinMode(photoTran,INPUT);
Serial.begin(9600);
}
void loop(){
reading = analogRead(photoTran);
Serial.println(reading);
delay(100);
}
///////////////////////////////////////////////////
For the most part it works. I played around with the delay some, moving it to 1000 and 500 to slow down the readings. At the kitchen table with the lights on the readings were consistantly 0. That was fine for me; my resistor value of 330ohm may be a little low, but again - this was just a learning experience.
When I shined a green laser pointer (approx 15mw) on the transistor i would get readings between 200 and 1000. Again - perfect for what I wanted to do. However when I fixed the position of the laser and transistor so they would not move, I would get readings in the 200 range; 3 or 4 times then 3 or 4 readings of zero. It was constantly going like that. Almost like the laser was being turned on and off (but it wasn't).
I would think shining a 15 mW laser directly on it would totally saturate the transistor and the voltage would be near 5V (1023). Try a resistor around 10k.
I'll have to get my multimeter out tonight and double check my resistor. My eyes aren't what they used to be and I'm not sure I read the bands correct! HA!
Groundfungus asked for a datasheet - and i really don't have one. I grabbed some old stock that I had laying around work to do some testing. Here is a Mouser link to the part - but it is obsolete. But their page does show some of the characteristics ...
As previously mentioned - it does appear to work; I'm just trying to understand why the serial monitor would show readings in the 200+ range for a few samples then zeros for a few samples. That's what is not making sense to me here.
I will likely end up abandoning this approach for my circuit and instead pick up and use a limit switch of some sort. I think that may end up being a little more reliable. However since I will need to use a phototransistor or a LDR in another part of the circuitry I am going to have to figure out this eventually.
TomGeorge:
If I was a phototransistor, I wouldn't be happy with any power laser being drilled into me.
Tom...
Tom
Thanks for the datasheet! Would love to know where you were able to find it!
I basically wanted to use the phototransistor to determine where my stepper motor was positioned. I'm using the stepper to fan out a laser, but I need to be able to determine where the rotation is on the stepper. I believe this method could work; but as mentioned earlier and after some thought last night I think I could do this easier with a limit switch and just have the mirror that's attached to the stepper trigger that switch. In doing so I can leave the laser off until the mirror is in the correct position to start the fan.
That thread started with this idea in mind. However last night when I tried using a phototransistor I ran into the issue of it only reading half the time. Not sure what was going on at that point I posted this thread.