Pages: 1 [2]   Go Down
Author Topic: Very Basic Project, Need Guidance  (Read 1777 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:



* Scan 2.jpeg (59.55 KB, 636x876 - viewed 6 times.)
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4773
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4773
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Pages: 1 [2]   Go Up
Jump to: