unable to read ir sensor value

Hi there.

I've built the following circuit diagram:
.

The problem is, when I check the value on Analog 0 using the serial monitor, I get a reading of about 1020-1027.

does anyone knows what seem to be the problem?

You can't possibly get readings up to 1027!!

The Arduino ADC (analog to digital converter) is 10 bit resolution.

That means that the maximum value is 2^10-1 = 1023, corresponding to the max voltage (which is 5V unless you have set the reference to something else)

The high readings you're getting could be because the pullup resistor you're using is fairly high. 47K is quite a bit. I'm using 10K in a similar circuit.

Have you tried placing a white surface in front of the sensor. This should make the readings drop if the circuit is set up right.

Could it be that you've placed the IR LED in the place of the IR Transistor? In a lot of cases they do look similar.

changed the resistor to 10k, now I get a reading from 0 to 5, it seems like the IR Transistor doesn't effect from the near-by IR led, only when I cover it with my hand it gets from 5 to 0..

so, my guess is that now the IR led doens't really does it job.. (even though I see a tiny red light from it!)

Any ideas??

Hmmm...not sure

  • Have you tried using different LEDs and phototransistors? It could be a flawed component.

  • You are aware that the range will only be a few millimeters?

  • Have you mounted the components close together so that the light from the LED will be reflected into the phototransistor (when you place a white surface a few millimeters from it)?

  • There is no "IR Transistor"!! There is an IR LED and a PHOTOtransistor. The latter should pick up the light from the 1st.

  • Are you sure your cicuit is set up right.

  • Are you sure you're reading from the right analog in?

  • What is the reading when you DON'T cover it with your hand? Remember that it gives a LOW reading when light IS reflected and a HIGH reading when it isn't. Not the other way around as you may think..

Some progress - The problem was the wrong polarity (connected the phototransistor wrong).

now when I COVER the phototransistor I get a reading of about 200-300, when UNCOVERED i get a reading of about ~900.

when I turn of the light in my room, it drops to 0 as you said.

Problem is that the IR LED doesn't effed whatsoever on the phototransistor, I tried to move it closer/cover/uncover, you name it, it's like it doens't excist.

Use a digital camera to tell if the IR LED is functioning at all. The CCD is sensitive to IR wavelengths and it will show you the LED lit if it is.

Problem is that the IR LED doesn't effed whatsoever on the phototransistor

when I COVER the phototransistor I get a reading of about 200-300, when UNCOVERED i get a reading of about ~900

It sounds like it's working to me?! I presume this is in a dark room since you later said:

when I turn of the light in my room, it drops to 0 as you said.

??? :-/

YAY!!
It's working!
The second problem was the IR LED resistor, I changed it to 1 Khoms so the led will light well, and it did the trick.

When I reflect white paper I get ~30
Black paper is about ~10

Thank you ALOT!

Ok! glad you made some progess...

Just a few notes:

  • The higher resistor for the LED the LESS light it will emit. So a lower LED resistor would produce stronger light!!

  • A difference of 20 (30 vs. 10) is very little. It should be more. You should check out various resistor values (both resistor) to find the optimal combinations. Like I mentioned earlier a good way of doing this could be replacing the resistors with potmeters so you can dial in the optimal settings. Easier than rewiring the circuit over and over. Also you'd wanna experiment with different distances between the sensor and the reflecting surface.

  • Ambient light will allways be a problem so you should try it in both a lit up and a dark room when you're trying to find the optimal settings/resistor values. And keep in mind what the conditions will be like in the end application.

You're almost there mate :wink:

Ok, now I get a difference of 400 to about 650!
(changed the led positions and resistors)

Still rather little...I'm getting something like ~7 vs. ~900 (depending on light conditions).

Keep tweaking ... like I said you're almost there :wink:

PS: Are you sure you set the scope to the right COM port when you tried it? I really can't figure out why it wouldn't work?! Also the Arduino serial monitor cannot be open at the same time by the way...

The question is how to get those values that you'r getting?
Do you have any idea about the specific resistors? what are the rules to the sensitivity of the phototransistor? can't I accidently destroy it using wrong resistor?
Thanks!

can't I accidently destroy it using wrong resistor?

You can destroy the LED if the value is too low. But according to the diagram you had 150R which is about the right value. But you got more light when you changed it to 1K so that suggests you didn't have 150R in the first place.

what are the rules to the sensitivity of the phototransistor

Not sure what you mean here. The photo transistor will cause a current to flow from collector to emitter depending on the amount of light. That current affects the voltage on the output as the current flows through the resistor. So the higher the resistor the more change in voltage you will see for the same change in light levels.

Hi, first post here!

Newbie to electronics and the Arduino.

I have a Duemilanove and I'm trying to build this very same circuit for obstacle avoidance, but I can't get it to work. I've spent the whole day trying to figure out what may be the problem, but so far no luck.

I've changed the 150 resistor in the first post to a 330 and 1k. The 47k has been replaced with a 10k resistor. I'm using a generic IR Led and Phototransistor - the electronics shop where I bought them didn't told me if they had a specific name or model, just that they were generic.

The code I'm using is this:

void setup() {
 Serial.begin(9600);
 pinMode(1, INPUT);
}
void loop() {
    int val = analogRead(1); // read sensor input from analog input 1
    Serial.print(val); // send the value to scope
    Serial.print(" ");
    delay(500); // wait 1 millisec
}

So far when I turn off the light near my desk, I always get a reading of 1023 using the Serial Monitor. If I turn the light on, it goes down to 1017, so I know something is happening.

I've already verified that everything is correctly connected, on the right pins, right polarity, etc.

Could you please, please help me!? I'm about to loose my mind! :cry: