Go Down

Topic: Very Basic Project, Need Guidance (Read 2030 times) previous topic - next topic

Mohrad

Now all I am reading is 0's. I ran a pull down resistor to ground form the emitter of the phototransistor and tapped in with the analog pin in between the resistor and the transistor. My circuit looks like this:


GoForSmoke

Try this:

Connect the long leg of the phototransistor (the collector) to +5V.
Connect the short leg (emitter) to a 1k resistor.
Connect the other end of the resistor to ground.
Connect the emitter to the analog pin.

It can be done with a phototransistor, a 1k resistor, 3 jumper wires and a breadboard.

Don't worry about 5V going directly to analog in as analog in is high impedance. You want 5V able to go to the pin.

Now what do you read?

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Mohrad

I'm still reading all zeros unless i literally attach 5v to the analog pin.

Here is my code:

const int analogInPin = A1;

int sensorValue = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  sensorValue = analogRead(analogInPin);
  Serial.print("Sensor Value = ");
  Serial.println(sensorValue, DEC);
  Serial.print("\n");
  delay(1000);
}

GoForSmoke

I could be wrong but setting a const int to A1.....
See what happens if you do this.

Code: [Select]

const int analogInPin = A1;

int sensorValue = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.print("pin ");
  Serial.print(analogInPin);
  sensorValue = analogRead(A1);
  Serial.print("Sensor Value = ");
  Serial.println(sensorValue, DEC);
  Serial.print("\n");
  delay(1000);
}
[/quote]

Other than that you have conductive the long leg of the phototransistor to +5V, the short leg to pin A1 and a 1k resistor between A1 and ground, if the transistor and A1 haven't been fried should be good.

You can test the parts. Put the phototransistor long leg to 5V, the short leg to a 220 ohm resistor, the other end of the resistor to the long leg of a led and the short leg of the led to ground. Then change light and dark on the phototransistor, the led should go on and off.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Mohrad

Wow....It all comes down to simply looking at the back of the radio shack package that the IR Phototransistor came in which labels the collector as the short leg and the emitter as the long leg. After flipping it around, everything works perfectly. Thank you for your guidance in this project so far, it is much appreciated!

Go Up