EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: jrmazur591 on September 11, 2014, 03:18:39 pm

Title: IR sensors and LED's
Post by: jrmazur591 on September 11, 2014, 03:18:39 pm
Hey Guys,

I am new to the forum and thought i'd get started by asking a question that has been stumping me for the past week or so.
I recently bought some IR LED's and Detectors from SparkFun. For your reference their sparkfun numbers are COM-09349(950nm) and SEN-10266.
I have tried a few difference configurations but can't seem to get them to work together. I had tried hooking the IR LED to just +5v and ground, along with a 330 ohm resistor and I have also tried using the PWM of the Arduino as well instead of the 5v. I have the ground pin of the Detector hooked to ground, the 5v pin hooked up to 5v and the OUTPUT pin of the detector goes into Analog input pin 0 on the Arduino. I have also tried using a Pull up resistor, 4.7k ohms on the OUTPUT pin of the detector line as well (i saw a video where they did that so i gave it a try). I also just tried Doing a pull down resistor config and I read in a sensor value of 124-125 but it also does not change when i put the IR LED next to it or try reflecting the IR light to it. I have also tried using different IR LED's. Sparkfuns COM-09469(850nm).

I have tried putting the LED on a separate board and then moving them closer together,hoping to see a different value read in by the detector, but still i just keep getting 1023 on the serial monitor. I have also tried putting them near each other and then lowering my hand above them hoping the deflection of the IR light will cause a change but still no luck, 1023.

I have also checked my IR led's to make sure they are all working and all are dropping the correct amount of voltage and they are not damaged or shorted out.
And yes I am placing them in the correct orientation. lol

I'm sure it is something simple that i am just overlooking but please help if you can!

After trying ALL of these options, no matter what i do i get a value of 1023 from the IR detector. Here is the code that i am using for my Arduino.

#define IRled 5
#define Sensor 0

void setup()
{
  Serial.begin(9600);
  pinMode(IRled, OUTPUT);
  pinMode(Sensor, INPUT);
  analogWrite(IRled, 255);  //can comment out this line if using just +5v to power.
 
}

void loop()
{
  int sensorValue;
  sensorValue = analogRead(Sensor);
  Serial.println(sensorValue);
  delay(1000);
}

I have also tried point my TV remote at it and seeing what that does and it does show me a different value but it is always the same value no matter what button i press. That i am assuming is just because the button i press sends a package of information not just one value and all the buttons packages start with the same value and I am just reading in that 1st value not the rest of the data sent.

Thanks for any help!
Title: Re: IR sensors and LED's
Post by: DanielS on September 11, 2014, 05:52:31 pm
For IR transmission to work, you need to modulate your transmitter since the receiver cannot distinguish continuous IR from ambient. You need to send bursts of pulses for the receiver to activate its output.
Title: Re: IR sensors and LED's
Post by: jrmazur591 on September 11, 2014, 07:30:51 pm
For IR transmission to work, you need to modulate your transmitter since the receiver cannot distinguish continuous IR from ambient. You need to send bursts of pulses for the receiver to activate its output.

Ahh okay, So I will have to use the PWM pins of the Arduino to control the IR LED.
Does anyone have some link or some sample code for doing this?

Basicly what I am looking to do is have a table full of colored LED's, IR LED's and IR Detectors. All inside a peg board and as you place an object, or hand above the LED's the IR light will be reflected back into the IR detectors and cause the LED's of that section to turn on. There are lots of examples of this on youtube but none really explain how to do the coding aspect, they just show the hardware.
Title: Re: IR sensors and LED's
Post by: jmoreland79 on September 11, 2014, 07:52:16 pm
Ahh okay, So I will have to use the PWM pins of the Arduino to control the IR LED.
Does anyone have some link or some sample code for doing this?

Basicly what I am looking to do is have a table full of colored LED's, IR LED's and IR Detectors. All inside a peg board and as you place an object, or hand above the LED's the IR light will be reflected back into the IR detectors and cause the LED's of that section to turn on. There are lots of examples of this on youtube but none really explain how to do the coding aspect, they just show the hardware.

You need to give more information such as a diagram of the design layout and what hardware, components, or MCUs you have available.

I can think of half a dozen ways to do what you're describing, but they're all depending on what you have available and how you want to implement it.
Title: Re: IR sensors and LED's
Post by: bobcat on September 11, 2014, 08:02:32 pm
The Sparkfun unit is an 38KHz decoder module. You cant just shine IR kight at it. see their instructions at https://learn.sparkfun.com/tutorials/ir-control-kit-hookup-guide (https://learn.sparkfun.com/tutorials/ir-control-kit-hookup-guide)
Title: Re: IR sensors and LED's
Post by: jGalt on September 11, 2014, 09:49:03 pm
It might be helpful (and interesting) to take a look at how common T.V. remotes work, since they use infrared. They all have protocols that they use. I did a project once where I had to decode the protocol that an IR remote was sending. The end result was that I could use any button I wanted on the remote as an input for any circuit that I built (writing the code to determine the PWM was a challenge though).

Anyways what previous people have told you is right..... another project I've done with infrared sensors actually had some circuitry built that would tell me if IR light was being constantly detected, so the circuitry that you build around your sensor is important.... because it determines the output your sensor will give you.

Also if you haven't heard this tip yet, you can use the camera on your phone to check if you've blown the IR light out. That's one reason why your sensor might not give you anything.
Title: Re: IR sensors and LED's
Post by: JoeO on September 11, 2014, 11:23:08 pm
Here is the bible for IR information:
http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html?commentPage=1 (http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html?commentPage=1)
Title: Re: IR sensors and LED's
Post by: macboy on September 12, 2014, 01:46:34 pm
You could read all kinds of information about IR remote controls, but I will try to boil it down.

The IR sensor/receiver detects IR light that is modulated (turned on and off) at around 38 to 40 kHz.  When this is detected, it output goes active (usually with these devices "active" is low/0V and "idle" is high/5V ... it is inverted logic). Constant, unmodulated IR does not trigger the receiver output. Why? Think of what would happen when it is exposed to sunlight, incandescent light bulb, or another bright light source which contains IR light.

The sending device (TV remote control for example) sends bursts of IR light modulated at 38 kHz. The "bursts" are a serial data stream, not UART serial, but one of several common (but specific to IR remotes) asynchronous serial protocols.  You can read up on RC5, SIRCS, NEC IR.  The pattern of pulses encodes a small amount of data, usually between 10 and 20 bits, which represents a command (device/button combination). But really you could send almost any serial data stream that you want.

To get up and running, try something very simple. Focus on the Rx side first. The IR module outputs a digital signal (on/off) so don't use an analog input, use digital. When the module outputs Hi, send character "H" to the serial port, and when it goes low, send a "L". Only send the character once when it transitions from H->L or L->H. Then when you press a button on your TV remote, you will see a string of HLHLHLHLHL... sent over the serial port, and it will stop when you release the button. Now you know that your receiver works.

Then you can move to the transmitter. Set up a PWM for about 38 kHz and 50% duty cycle. Just it run. This is the modulation signal. Connect it to the cathode of the IR LED. Connect the Anode to a digital output (through a series resistor). The IR LED is a diode and will only conduct in one direction so as you toggle that digital output on and off, the LED either transmits a 38kHz modulated signal, or nothing at all. This 38kHz modulated signal will be detected by your (verified functional as above) receiver. Turn the IR LED's digital output on... an H is received on your serial port. Turn it off... an L is received. Now you are on your way.