IR sensor help

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


Try this:

void setup()

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

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

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

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

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?

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:

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.

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

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

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?

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

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

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.

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.

Check out Figure 10 in this document on how to wire up a photodiode with a resistor:

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

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

K tried that ...

I used a 10k ohm resistor to start, then switched to two 47k ohm resistors in series for 94 k ohms, and always was 1023 reading with slight variations to 1022 and 1021 randomly. I pressed my tv remote and got no reaction. Here is how I have it set up...

  • 5v _____ 94 ohm ______ cathode ________ A5 anode_______ground I believe this is exactly what you mean.

Just using this simple code...

int Receiver =0;

void setup()

{ Serial.begin(9600); } void loop() { int Receiver = analogRead(A5); Serial.println(Receiver); }

What do you mean by "cathode - A5 - anode" ?!?

You have to measure between the photodiode and the resistor (identified by "Vout" in the paper I linked).

And why don't you try the simplest possible setup (i.e. no reverse voltage) if you are having troubles? You can always change it later if you do need the reverse voltage.

The 2 are separate..

  • 5v _____ 94 ohm ______ cathode ________ A5 is separate This is everything attached to the cathode

only thing attached to the anode of the photodiode is ground. I tried reverse and it seems to be working better though. I am also getting other photodiodes ( daylight filtering ) from mouser today.

Hope those help too.

Ill be back with more questions very very soon.

anode_______ground I believe this is exactly what you mean.

No that is not what I said please re read what I put.

And why don't you try the simplest possible setup (i.e. no reverse voltage) if you are having troubles? You can always change it later if you do need the reverse voltage.

No if there is only a reverse diode across the analogue input then the input impedance is too high for the sample and hold on the input. You need an impedance of about 10k to prevent any apparent cross coupling in the multiplexer

I think you misunderstood me Mike, by simplest possible setup I was referring again to driving the photodiode in short circuit mode (i.e. cathode - resistor - anode) and reading the voltage across the resistor.