Pages: [1] 2   Go Down
Author Topic: IR sensor help  (Read 1826 times)
0 Members and 1 Guest are viewing this topic.
Sioux Falls
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I want to set up an IR receiver that will calibrate to the environment... ( check to see how much ir light is in the environment) and then set that as the new zero level, so if the other IR receiver receives a little more ir light than that new zero ( threshold), then an led will turn on.  To test this, I simply have 2 of the exact same infrared receivers hooked up the exact same way with the exact same resistors to analog 0 and 5 on the arduino.  The 2 receivers are not more than 1 inch apart and are at the same level vertically.  The problem is they are receiving vastly different ir values?? why?


here is the code and the resulting values..... 

int Calibration;
int Receiver;


 void setup()

{
  int Receiver = analogRead(A5);
  int Calibration = analogRead(A0);
  Serial.begin(9600);
  Serial.println("Calibration Input = ");
  Serial.println(Calibration);
  delay(1000);
  Serial.println("Receiver Input = ");
  Serial.println(Receiver);
  }

void loop()
{}
 
 
 here are the values..


Calibration Input =
133
Receiver Input =
359
Calibration Input =
141
Receiver Input =
377...


HOW COULD THEY BE SO DIFFERENT?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25876
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this:
Code:
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int Receiver = analogRead(A5);
      Receiver = analogRead(A5);
  int Calibration = analogRead(A0);
      Calibration = analogRead(A0);
  Serial.println("Calibration Input = ");
  Serial.println(Calibration);
  Serial.println("Receiver Input = ");
  Serial.println(Receiver);
  delay (1000);
}
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Sioux Falls
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tried that... here are the results... no good


Calibration Input =
35
Receiver Input =
140
Calibration Input =
29
Receiver Input =
142
Calibration Input =
24
Receiver Input =
136
Calibration Input =
28
Receiver Input =
134
Calibration Input =
31
Receiver Input =
141
Calibration Input =
22
Receiver Input =
138
.. They change which is obviously good because they respond to slight changes in ir light in the environment, but the values are too much unlike each other.  Makes no sense.  I tried switching the receivers, but get the exact same results, also tried switching the inputs to different places with the same results... smiley-sad
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25876
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the source of light?
Is it incandescent, fluorescent or natural?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Sioux Falls
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

incandescent.  It is nighttime here, just a computer screen and my light on.. but I need it to work in any amount of any kind of light

btw here are the actual results from your code.. it sort of works but what about the zeros after the first reading?

Receiver Input =
39
Calibration Input =
18
Receiver Input =
15
Calibration Input =
0
Receiver Input =
0
Calibration Input =
0
Receiver Input =
0
Calibration Input =
0
Receiver Input =
0
Calibration Input
Logged

Sioux Falls
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, Id like to take either 10 or 100 samples within about a second with one sensor in the setup() part and take the average reading as a threshold.. then in the loop take a constant reading to compare to the threshold.
Should I use a for loop for that?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 110
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is it you are trying to achieve?
Because if you sample during the setup you will not need 2 different sensors and you will not be able to adjust to ambient light changes.
Where does the light you do want to detect come from?

For getting a threshold during the setup you can simply do something like:
Code:
void setup()
{
     int threshold = 0;
     for(int i = 0; i < 100; i++)
     {
          threshold += analogRead(A0);
     }
     threshold = threshold / 100;
}
You might want to add a small delay in the loop to sample over a longer period of time to get a more average reading if necessary.

Hope that helps.
Tom
Logged

Sioux Falls
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Tom, I am trying to make an IR Receiver (photodiode )light up an LED when  it senses IR light that reflects off of something from the IR emitter close by.  All leds will be facing vertically, and eventually they will all be covered so not affected by each other.  I want the IR receiver to take in a bunch of readings when the program starts up to set the ambient light as a new zero.. (threshold maybe?) and then when the IR receiver detects a certain amount of light above that the LED will turn on.  I know this uses a lot more than I do right now, but I want to start with the basics in order to get here.....

http://www.youtube.com/user/grahmaustin#p/a/u/2/h5n0rw8wo14

just bare bones for me right now.. then multiplexing and what not will come into effect.  thanks
Logged

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

Quote
I tried switching the receivers, but get the exact same results,
By that do you mean that the same channel shows up high or the same sensor is high.
If you swap the sensors do the readings swap?

You also need to be a bit more descriptive about the sensors (type and link to data sheet) and how they are wired up (schematic). It could be you have an error or it could be that the two sensors are just that different in sensitivity. What does the data sheet say about the sensitivity?
Logged

Sioux Falls
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, i switched the receivers, and the same analog port had the same readings.. here is the receiver..... LTR-209 . ... mouser product
Logged

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

And how have you got it wired up and what value are the resistors.
It sounds like you have this bit wrong.
Logged

Sioux Falls
Offline Offline
Jr. Member
**
Karma: 0
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ive tried different values of resistors.  But equal for each sensor.  So...


I have a wire from A0 on the arduino to a 1k resistor (ive also tried 500 ohm and 10k ohm), the resistor to the positive of the ir photodiode, from the negative of the diode it goes to arduino ground.  I have the exact same setup for the other sensor to A5. 
Logged

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

If I understand what you have done correctly that is wrong.

A0 should go to a resistor and the cathode of the photo sensor. Then the anode should go to ground and the other end of the resistor to +5V. Use a 10K resistor to start and if you want to improve the sensitivity (but also increase the noise) make the resistor a larger value, say 100K.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 110
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Check out Figure 10 in this document on how to wire up a photodiode with a resistor:
http://saaubi.people.wm.edu/TeachingWebPages/Physics252_Spring2007/Week10/Chapter10_OpAmpCircuits.pdf

You won't even have to apply a reverse voltage to the photodiode unless you want/need it to react faster to light changes. But since in your case the limiting factor will probably be the analogRead or the upcoming multiplexing you should be fine without it.

If that doesn't help then show us a complete diagram on what and how you wired things up.

Good luck!
Tom
Logged

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

Well figure 12 is what I told him to do only the resistor is swapped round, that won't make any difference.
Logged

Pages: [1] 2   Go Up
Jump to: