IR break sensor

Ok so i have copied a simple IR sensor code and I am having issues. No matter what i do including unplugging the led i get a 1 reading. whats wrong? attached is a pic of my project and an ugly diagram.

 //
#include <IRremote.h>
#define PULSE_TIME 1000

int RECV_PIN = 2;
IRsend irsend;
unsigned long time;
boolean send = true;

void setup()
{
Serial.begin(9600);
pinMode(RECV_PIN, INPUT);
irsend.enableIROut(38);
time = 0;
}

void loop()
{ 
if(millis() - time >= (PULSE_TIME/1000))
{
if(send)
{
irsend.mark(PULSE_TIME);
}
else
{
irsend.space(PULSE_TIME);
}
   
time = millis();
send = !send;
}
 
 Serial.println((int)digitalRead(RECV_PIN));

}

.

Thanks everyone for the help and ideas.

detector.png

20170406_235633.jpg

Is the IR led really on 5V always or connected to the IR emmiting pin that gets modulated?

Which Pin is the Emitting PIN?

On this page, in the Hardware Setup section is a table that lists the send pins for the different Arduino boards.

if your LED is always powered on (connected to 5V) why are you surprised that you always get a 1 on the other side?

what do you think those lines do ?

     irsend.enableIROut(38);
...
     irsend.mark(PULSE_TIME);
...
     irsend.space(PULSE_TIME);

Open the sketch found in File->Examples->IRremote->IRremoteInfo. If you upload and run this sketch it will give you all sorts of information on the ir library including the emitting pin. This is the pin that you should have the IR LED hooked up to. When I run IRremoteInfo on an UNO I see:

IR Tx Pin: 3

The TX pin depends on the timer you choose in the library and the type of arduino you have.

J-M-L:
if your LED is always powered on (connected to 5V) why are you surprised that you always get a 1 on the other side?

what do you think those lines do ?

     irsend.enableIROut(38);

...
    irsend.mark(PULSE_TIME);
...
    irsend.space(PULSE_TIME);

Ii also says one when i unplug the LED that's what surprises me. I will look into this more using the information you have all provided and see what i can do. Thanks so much.

I have the Duemilenove arduino and i have placed the LED + lead onto pin 3 from what i saw the is correct. And the detector is on Pin 2 witch also looked correct. Same result 1 all the time with or without the led on (unplugged) i also tried to block it. This is a simple thing what am i missing?

So i just tried this

 //
#include <IRremote.h>


int RECV_PIN = 2;
IRsend irsend;

void setup()
{
Serial.begin(9600);
pinMode(RECV_PIN, INPUT);
irsend.enableIROut(38); //38KHz
irsend.mark(0); //Send
}

void loop()
{
Serial.println((int)digitalRead(RECV_PIN));
}

It reads as a 1 out put no matter what however,

when i unplug the led lead from pin 3 it stays 1 until i plug it back in then it goes to 0. As long as i keep the detector covered it stays 0. Once i let the detector see the LED it goes back to 1. It will stay as 1 no mater what i cover up, but will go back to 0 if i unplug the led from pin 3 and plug it back in. Any thoughts?

Well it depends what you want to detect - IR is present all around you in nature - you and most of the thermal radiation emitted by objects near room temperature is infrared.

That why - to not confuse normal IR with generated IR - you use modulation at the emitter side and listen for that specific modulation at receiver side.

Any idea why this setup does not seem to work using the modulation? Could i have a bad library any thoughts?

would be good to understand what's you equipment... is your receiver tailored to react only to 38KHz modulation? if it's a generic IR receiver then read again post #10.

The library you are using is meant to send data, with modulation and demodulation and coding with mark and spaces, and to receive data using the same principle (detect the modulation, detect the mark and spaces).

You are just reading your digital pin and not caring about the 38Khz modulation so your sensor tells you "there's IR in the air".

The library is meant also to drive the sender or the receiver but not both at the same time. You might run into timing challenges when trying to decode

I am using these

This is the new diagram i am using and code

 //

#include <IRremote.h>


int RECV_PIN = 2;
IRsend irsend;

void setup()
{
Serial.begin(9600);
pinMode(RECV_PIN, INPUT);
irsend.enableIROut(38); //38KHz
irsend.mark(0); //Send
}

void loop()
{

 
irsend.enableIROut(38); //38KHz
irsend.mark(0); //Send
  
Serial.println((int)digitalRead(RECV_PIN));
 
}

detector.png

Please - with 23 post you should by now know how to post code... Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

use clickable links for links, embed images into your post rather than attachments... that will make the life of those who are trying to help a bit easier and you are likely to get better and faster answers..

all this is documented at the top of the forum - please read those 3 pinned threads:

New Useful links - check here for reference posts / tutorials
How to use this forum - please read.
Read this before posting a programming question

You should read about how to setup a receiver by looking at the datasheet. here is one for the tsop382 for example.

Notice the RC circuit with the Receiver

It almost looks like you're trying to flash a led at 38KHz and then detect the flash with a digital read.

With digital read you get either 0 or 1. Is your sensor open to any near-IR sources including red leds?

GoForSmoke:
It almost looks like you're trying to flash a led at 38KHz and then detect the flash with a digital read.

With digital read you get either 0 or 1. Is your sensor open to any near-IR sources including red leds?

I believe the sensor he has (VS1838B HX1838 Infrared Receiver) is filtering the modulated 38KHz signal and should hand over 0 or 1 appropriately as long as it's wired appropriately

Most users go for a small board with the proper R and C already wired.

Does that code have the led ON during the time that the sensor is read?

J-M-L:
Please - with 23 post you should by now know how to post code... Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

use clickable links for links, embed images into your post rather than attachments... that will make the life of those who are trying to help a bit easier and you are likely to get better and faster answers..

all this is documented at the top of the forum - please read those 3 pinned threads:

New Useful links - check here for reference posts / tutorials
How to use this forum - please read.
Read this before posting a programming question

You should read about how to setup a receiver by looking at the datasheet. here is one for the tsop382 for example.

Notice the RC circuit with the Receiver

I think i fixed the code up top so it has code[] at the front and end.

I did not use the rest of this circuit because every example i saw no one had the rest of the resisters and capacitors on there working examples. I will work on getting those items to see if it helps.

"It almost looks like you're trying to flash a led at 38KHz and then detect the flash with a digital read.

With digital read you get either 0 or 1. Is your sensor open to any near-IR sources including red leds?"

It is a detector that is suppose to detect at 38khz. And the counter part emitter pair. I thought the code i was using sent out a modulated 38khz IR beam and would see if the detector would detect that modulated IR beam. If it did it would send a 1 if not it would send a 0. Is that not what its doing?

On my arduino Duemilenove it should send a modulated signal on pin 3 and receive one on pin 2. Thats my understanding at least.