IR Receiver Problems

I'm trying to use two IR lights and receivers to keep count of how many people walk in/out of a room. When the first person enters and the last person exits, I have a servo wired to turn the lights on/off. I'm having problems with my receivers though, they don't seem to sensitive. I can hold my hand three inches in front of it and it still shows nothing is there. It reads high when nothing is there and low when an object is detected. I have the sensors wired to 5V and ground on the right pin and middle pin (looking from the back) and a 220 ohm resister and a digital pin on the left pin. The IR light is wired from a digital pin toning out at 38kHz, a 220 ohm resistor, and then ground. If I wave something in front of it really fast, I might get a low signal for one reading out of 10.

This is my receiver:
http://www.parallax.com/Store/Sensors/ColorLight/tabid/175/CategoryID/50/List/0/SortField/0/Level/a/ProductID/177/Default.aspx

This is my code:

#include <Servo.h>
Servo lightswitch;

void setup(){
  Serial.begin(9600);
  pinMode(8, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(10, INPUT);
  Serial.print(12, BYTE);
  Serial.print(17, BYTE);
  Serial.print(128, BYTE);
  Serial.print("IR Status=");
  Serial.print(148, BYTE);
  Serial.print("IR Status2=");
  Serial.print(22, BYTE);
  pinMode(7, INPUT);
  lightswitch.attach(3);
}
void loop(){
  int i=0;
  tone(8,36700);
  int IRstatus= digitalRead(7);
  delay(50);
  tone(12, 36700);
  int IRstatus2= digitalRead(10);
  Serial.println(IRstatus);
  delay(100);
  Serial.print(138, BYTE);
  Serial.print(IRstatus);
  Serial.print(159, BYTE);
  Serial.print(IRstatus2);
  Serial.print(168, BYTE);
  Serial.print("Person Count=");
  Serial.print(181, BYTE);
  Serial.print(i);
  delay(50);

  if (digitalRead(7)==LOW){
    delay(250);
    digitalRead(10);
    delay(50);
    digitalRead(10);
    delay(50);
    digitalRead(10);
    delay(50);
    digitalRead(10);
    delay(50);
    digitalRead(10);
    delay(50);
    digitalRead(10);
    delay(50);
    if(digitalRead(10)==LOW){
      lightswitch.writeMicroseconds(1300);
      i++;
  }
  }
if (digitalRead(10)==LOW){
    delay(250);
    digitalRead(7);
    delay(50);
    digitalRead(7);
    delay(50);
    digitalRead(7);
    delay(50);
    digitalRead(7);
    delay(50);
    digitalRead(7);
    delay(50);
    digitalRead(7);
    delay(50);
    digitalRead(7);
    delay(50);
    
    if(digitalRead(7)==LOW){
      lightswitch.writeMicroseconds(1700);
      i--;
}
}
}

Thanks for your help.

That receiver needs modulated IR light, what are you doing to modulate it?
Also it is designed for recieving pulses so not only do you have to modulate the IR you also have to pulse it at about 1mS intervals. Then it will work like you expect.
See this thread:-
http://arduino.cc/forum/index.php/topic,63718.0.html

Ok, I changed the wiring, still not responsive. I looked at that other post, and came to the conclusion that I need to pulse the light. How do I go about doing this in a way where I can still read for the reflections? The methods in the other thread didn't make much sense to me. Thanks again for your help.

The methods in the other thread didn't make much sense to me.

Sorry that is the way to do it. You will have to try and understand what is being done. Ask about the bits you don't understand.

KE7GKP:

I need to pulse the light.

Yes, the receiver will only respond to modulated IR light.

Pulse, not modulate. As you said, I got the modulation down (tone(8, 38000))

How do I go about doing this

In your very first post, you said:

The IR light is wired from a digital pin toning out at 38kHz

So we thought that you had that covered.

in a way where I can still read for the reflections?

I don't understand that part of the question. What does "read for the reflections" mean?

The light is shooting straight out, and when something is moved in front of the light/sensor combo, the IR light is reflected back to the sensor, so I am looking for IR reflections.

Grumpy_Mike:

The methods in the other thread didn't make much sense to me.

Sorry that is the way to do it. You will have to try and understand what is being done. Ask about the bits you don't understand.

Thanks for your help here. What I don't quite understand is what someone said in the other post (may have even been you) about pulsing the light. It said to place 38kHz on one pin and 500 Hz on another and place the IR light "between" them. What does that mean to place the light "between" two pins? Also, and this may be totally unrelated, but would the pulseOut() command be useful here? Or would I lose control over the frequency by doing that? My main problem is getting a 38kHz IR light of some sort pulsed in a way the sensor can receive it effectively. Thanks for your patience and your help.

It said to place 38kHz on one pin and 500 Hz on another and place the IR light "between" them.

It was not me but Udo Klein that said this.
It is simple, you have your emitter and resistor in series. You connect one end to one pin and the other end to the other pin. Then the emitter only lights up when one pin (the one connected to the anode) is high and the other is low. So when the low frequency pin is in the right state the LED flashes on an off at the rate of the high frequency pin. When the low frequency pin is in the wrong state the whole thing is off no matter what the other pin does. Hence the light pulses at the low frequency, but when it is on it is really being turned rapidly on and off.

If you have one pin producing a rapid change (38KHz) with the tone command (will tone actually produce ultrasonic sound?) then get one of the PWM pins. Change the PWM frequency to 500 Hz (or just try it as it is because some pins default to around this value) and wire up the IR emitter (and resistor) between those pins. Note the resistor needs to be such that the current is limited to below 40mA. If this does not give you enough range then arrange a transistor to switch them, possibly in an H-bridge configuration.

Hmmm. Interesting. So there's no ground going to the emitter? Or is one of the frequencies going to the ground pin along with ground? Sorry I don't understand this, it's a whole new concept to me.

Yes one pin acts as the ground and the other acts as the supply.
It is quite normal for a pin to act as a ground it is called sinking current if you want to look it up. A pin acting as a source of + volts is known as sourcing current and although you might think it is more normal it is the less common situation in digital electronics.

Ok cool. I'll give that a shot. Thanks so much for your help.

It still doesn't work :confused: I have one pin putting out 38khz (tone(pin number here, 38000)) then another pin putting out 500 hz (tone(pin number here, 500)). That didn't do anything, so I added my ground back and it's doing about the same thing as before. Do I have to use certain pins for this? I'm using digital pins 7, 8, 10, and 11. Sorry I keep coming back.

How can I use that to tone two IR lights? I'm still confused.

I need to do more than power two LED's, I need to power to Infrared LED's at a certain frequency.