Pages: [1]   Go Down
Author Topic: unable to read ir sensor value  (Read 1625 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 214
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 24, 2009, 06:23:06 pm by Aniss » Logged

Oregon USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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??
« Last Edit: November 24, 2009, 06:48:15 pm by eranglr » Logged

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 214
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..
« Last Edit: November 24, 2009, 06:59:51 pm by Aniss » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Oregon USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 214
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote
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:

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

???  :-/
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 214
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink
« Last Edit: November 24, 2009, 07:33:58 pm by Aniss » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, now I get a difference of 400 to about 650!
(changed the led positions and resistors)
« Last Edit: November 24, 2009, 07:47:21 pm by eranglr » Logged

Buenos Aires
Offline Offline
Full Member
***
Karma: 0
Posts: 214
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Keep tweaking ... like I said you're almost there smiley-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...
« Last Edit: November 24, 2009, 07:59:42 pm by Aniss » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34572
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Quote
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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
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!  :'(

« Last Edit: June 18, 2010, 06:56:01 pm by yeahsure » Logged

Pages: [1]   Go Up
Jump to: