Is it possible to detect an LED light with this sensor?

... and if so, how? The sensor I've got is an IR Receiver Module. I'm wondering if this could be used to send a signal to the Arduino when an LED of specific wavelength has crossed it's field of vision.

If this is possible, is there any useful examples of such a thing? I cannot seem to find any relevant code samples or tutorials, finding only IR remote code (Which I'm pretty sure isn't what I want to be doing?)

Thank you!

It will detect an IR LED that is flashing at about 38 kHz. Other light sources should be ignored.

I'm wondering if this could be used to send a signal to the Arduino when an LED of specific wavelength has crossed it's field of vision.

No.
That sensor uses modulated light at 38KHz so unless the light is being turned on and off at that rate the sensor will not detect it.

johnwasser:
It will detect an IR LED that is flashing at about 38 kHz. Other light sources should be ignored.

Awesome! I'm sorry to be a pain, but would digitalRead be fast enough to detect this? Or will I need to somehow make a new way to read the data. I'm new to all this, sorry if this is an obvious Q :S

#2: Is it possible to use an Arduino to flash LEDs at that frequency? If I hooked up a second Uno with only code loaded that flashes the LEDs to the required wavelength, would that then make this possible?

Yes, digitalRead is fast enough.
Sensor output only changes state to LOW after a number of 38kHz pulses.
Attached is 38kHz transmit code.
Leo..

const byte IR_LED = 11; // IR transmitter LED with 100ohm (minimum) CL resistor

void setup() {
  pinMode (IR_LED, OUTPUT);
  TCCR2A = _BV (COM2A0) | _BV(WGM21);
  TCCR2B = _BV (CS20);
  OCR2A =  209; // ~209 = ~38kHz | ~219 = ~36kHz
}

void loop() {
}

Wawa:
Yes, digitalRead is fast enough.
Sensor output only changes state to LOW after a number of 38kHz pulses.
Attached is 38kHz transmit code.
Leo…

const byte IR_LED = 11; // IR transmitter LED with 100ohm (minimum) CL resistor

void setup() {
 pinMode (IR_LED, OUTPUT);
 TCCR2A = _BV (COM2A0) | _BV(WGM21);
 TCCR2B = _BV (CS20);
 OCR2A =  209; // ~209 = ~38kHz | ~219 = ~36kHz
}

void loop() {
}

Hey,

I see this code is for an IR LED; I don’t have one of those; is it possible to “hack” an IR remote and use it’s little light on the end as the IR light source?

EDIT: Or would something like this be good enough as the IR light source?

You could use the IR LED from a remote, but make sure that you use a current limiting resistor between it an Arduino output. The linked module will also need a current limit resistor installed. Limit the LED current to around 20mA unless you use a transistor driver. In the case where and driver is used, insure that the max forward current of the LED is not exceeded.

Not all IR detector decoders are suitable for a light barrier. If you want to make a system that detects pulsed IR beam breaks, you may need a different sensor.

EDIT: Or would something like this be good enough as the IR light source?

Yes but it is about four times the price as you can get similar ones and ten times the price of the components.

is it possible to "hack" an IR remote and use it's little light on the end as the IR light source?

Maybe, you need to hack it right and the LED has to be the same IR wavelength as the receiver.

@Wawa - while that code will indeed flash the LED at 38KHz those types of receivers will stop giving anything after about 40 pulses. So what you need to do is to flash the LED for a bit and then stop for a bit. When you do that the output of the IR receiver will output a steady logic level for both LED detected and the inverse for no LED detected. This is code that is modified to give the IR LED a bit of a rest and stop the receiver blanking out.

* Code to pulse pin 3 with a modulated signal
* Can be used to drive an IR LED to keep a TSOP IR reciever happy
* This allows you to use a modulated reciever and a continious beam detector
* By Mike Cook Nov 2011 - Released under the Open Source licence
*/
 volatile byte pulse = 0;

ISR(TIMER2_COMPB_vect){  // Interrupt service routine to pulse the modulated pin 3
    pulse++;
  if(pulse >= 8) { // change number for number of modulation cycles in a pulse
    pulse =0;
    TCCR2A ^= _BV(COM2B1); // toggle pin 3 enable, turning the pin on and off
  }
}

void setIrModOutput(){  // sets pin 3 going at the IR modulation rate
  pinMode(3, OUTPUT);
  TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); // Just enable output on Pin 3 and disable it on Pin 11
  TCCR2B = _BV(WGM22) | _BV(CS22);
  OCR2A = 51; // defines the frequency 51 = 38.4 KHz, 54 = 36.2 KHz, 58 = 34 KHz, 62 = 32 KHz
  OCR2B = 26;  // deines the duty cycle - Half the OCR2A value for 50%
  TCCR2B = TCCR2B & 0b00111000 | 0x2; // select a prescale value of 8:1 of the system clock
}

void setup(){
  setIrModOutput();
  TIMSK2 = _BV(OCIE2B); // Output Compare Match B Interrupt Enable
}

void loop(){
// do something here
}

Alright, so I would load that code onto the arduino which controls the light source, and on my other arduino, what sort of code would I run to "signal" it's detected the light source? Is there an example library for this (I can't seem to find an example in the IDE)

Edit: The second arduino is the one with the receiver sensor in OP; arduino one is running the IR light source (either hacked remote or expensive transmitter)

what sort of code would I run to “signal” it’s detected the light source?

Just a simple digitalRead ( enable internal pull up ) of the pin you connect the IR receiver’s output to. It will give one logic state with light being received and the other logic state when it is not seen.

Hey,

I've written this real basic code to test if the IR receiver is receiving; the onboard led on the sensor lights up (which indicates its read a target) but I cant seem to get it working. Is it because an analog pin can't be used; although I don't think theres any difference when it's set to INPUT_PULLUP? Shouldn't when it receive the PULLUP logic state be flipped to LOW (hence displaying the text shown)?

const int IRpin = A2;
int irState = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(IRpin, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  irState = analogRead(IRpin);
  if(irState == LOW){
    Serial.println("It's lit");
  }
  else{
    Serial.println("fugg");
  }
  Serial.println(irState);
  delay(1000);
}

Thanks for any help.

Do not use an analogRead call on a pin you are using as a digital input, just use a digitalRead.

Grumpy_Mike:
Do not use an analogRead call on a pin you are using as a digital input, just use a digitalRead.

So digitalread will work even on an analog pin configured as an input?

Yes.
The same goes for digitalWrite when used as an output.

Using analogRead overrides any previous pin mode, and you will not get a LOW and HIGH from it.

Alright, thank you for the info, I'll keep that in mind in future. One final question; I should be looking for the IR sensor to return LOW when it's configured on an analog pin as INPUT_PULLUP; when it receives, it will invert its default HIGH state to LOW right? It won't just stay HIGH?

Edit: Got it working, this is the right way to do!

When there is no light detected that chip has its output high, when a pulse of IR light is detected the output goes low.
The configuration and pull up has nothing to do with what you will read.

It is vital that you get into the habit of reading the data sheet for any device you want to use.