[solved] Problem with IR receiver VS1838B

Hi everybody
i’m using a IR led and IR receiver VS1838B on a Arduino uno board
i send a 38kHz signal to the led and count it with VS1838B using falling interrupt
the code works, but i get count even if i block ir light from the led, the only way of stopping the count is to detach the led…
i even tried to replace the led with a 100ohm resistor, still counting
but if i replace it with a 22k resistor it stops
any ideas?
here is the code:

#define PIN_TX 11
#define PIN_RX 2

volatile int count;

void setup() {
  pinMode (PIN_TX, OUTPUT);
  pinMode (PIN_RX, INPUT);
  attachInterrupt(digitalPinToInterrupt(PIN_RX), falling, FALLING );
  Serial.begin (9600);
  count = 0;
}

void falling() {
  count++;
}

void on(unsigned int len) {
  for (int i = 0; i < len; i++) {
    tone(PIN_TX, 38000);
    delayMicroseconds(600);
    noTone(PIN_TX);
    delayMicroseconds(900);
  }
}

void loop() {
  on(10);
  Serial.println(count);
  delay(1000);
}

thanks

It sounds like the circuit is not properly grounded, so you are picking up electrical interference. Please post a wiring diagram, with components and pins clearly labeled. Hand drawn is fine. Image posting guide

Please post the image properly, in line.

A LED must have a current limiting resistor.
Without that both LED and pin will burn out.

Are you hoping to count 38kHz pulses with a 3-pin IR receiver? Forget about that.
The 3-pin receiver de-modulates that pulse train, and will output a constant LOW (= 38kHz present).
Leo..

The resistor is not in the image i posted, but is present.
I dont send continuous 38kHz signal, but packets of 600us at 38k and 900us empty, and the receiver counts it properly.
The problem is that even if break the ir beam the receiver still keeps counting...

jremington:
Please post the image properly, in line.

joypadd:
The problem is that even if break the ir beam the receiver still keeps counting...

Normal behaviour.
The signal is probably bouncing off the walls/ceiling, reaching the receiver that way.
3-pin receivers are quite sensitive, and a distance of 10-50meters can be easilly achieved if you have a decent LED current (~20mA).
Try reducing the IR LED current by increasing the value of the CL resistor.
Try a 10k resistor.
A short tube (heatshrink) on the IR LED could also help.
Leo..

It's not this case, because i even tried to replace the led with a 100ohm resistor, still counting
but if i replace it with a 22k resistor it stops

There appear to be a couple of problems with your circuit.

I don't see a current limiting resistor for the LED. Failure to use one (150 Ohms minimum) will destroy the port output circuit.

Do you know about the bridge problem with some breadboards? There is no connection across the gap in the horizontal strips, where you have marked "gnd" and "5V" in the image.

The resistor is not in the photo, but is present
Cant get what you men with bridge problem, but the circuit works well, if i detach the tx led i can receive pulses from a TV remote, the only problem is that when i connect the ir led the receiver seems to read pulses even if i break the ir beam, even putting a simple resistor instead of the led the receiver keeps counting...

The resistor is not in the photo, but is present

Why did you even bother to post a poor quality picture of the wrong circuit? You are the one asking for help.

Post a complete, correct, hand drawn wiring diagram, with component values and part labels.

sorry, but when i made the photo it was on the blue wire on the bottom, but i accidentally crop the pic too much...
i didnt think it could be the cause of my problem so i didnt draw it...
anyway this is the hand drawn schematic


now i also tried to connect the led and the receiver with a coaxial cable with the outer cable connected to ground, to see if it was catching interference, but still no luck

On many breadboards, there is no connection across the gap outlined in red below. Check continuity of all connections with your multimeter.

gap.png

gap.png

Change the 100 ohm resistor to 5.6K

Suggest you ‘not’ use interrupts for this, but instead ‘use’ a drop out timer.

On many breadboards, there is no connection across the gap outlined in red below. Check continuity of all connections with your multimeter.

ah, ok. checked, connections are all correct

Change the 100 ohm resistor to 5.6K
Suggest you 'not' use interrupts for this, but instead 'use' a drop out timer.

ok for the resistor
what you mean with "drop out timer"?
i tried this: removed interrupt and used the following code to see if the receiver is reading the beam:

tone(PIN_TX, 38000);
delayMicroseconds(300);
digitalWrite(PIN_LED, !digitalRead(PIN_RX));
delayMicroseconds(300);
noTone(PIN_TX);
delayMicroseconds(450);
digitalWrite(PIN_LED, !digitalRead(PIN_RX));
delayMicroseconds(450);

it receive beam correctly (led flashes when the beam is on), but still keeps flashing when i block the beam

but still keeps flashing when i block the beam

Then your sensor is either bad or you are still receiving some IR from the LED (as mentioned in a post above).

Adjust the value of your series IR LED resistor.

With a clear path to the receiver, when the receiver stops detecting, record the value of the resistor.

Lower this value until the receiver starts working again, use this as the current limiting resistor.

what you mean with "drop out timer"?

A 'Drop out Timer' is one that gets restarted every time you see a pulse.

If pulses disappear, the timer finishes and some action is taken.

No interrupts are needed.

the receiver "reads" the beam even if i replace the ir led with a resistor...
it seems good because if i remove the led and send a ir beam with a tv remote the receiver flashes only then i press a button on the remote
seems like sending a signal to the led (or even the resistor) interferes with the receiver, but dont know how to handle it...

Try putting a .1uF ceramic capacitor across the power pins on the IR receiver.

Is this your actual wiring?

the only difference is that i replaced the long wires to the led and from the receiver with coaxial cables and connected the outer to gnd and now the resistor is near the led
tried with the capacitor, no difference