I recently purchased some IR LEDs and Receivers. I have experience with arduino but cannot seem to get the IR LED and receiver to work together. I hook the IR LED up as displayed on http://www.ladyada.net/learn/sensors/ir.html. The anode (longer lead) of the IR LED is hooked up to the 3v pin and the cathode to the ground pin. Here's the code I'm using:
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println(analogRead(0));
}
The IR receiver detects light when I shine my TV remote at it; the IR LED seems to do nothing - how can I properly hook it up and detect it?
I can't get the IR LED to light up at all - to test, I look at through my cell phone camera but don't see any light.
IR LED and Receiver
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: IR LED and Receiver
The tutorial shows it connected to pin 13. And don't forget the resistor!The anode (longer lead) of the IR LED is hooked up to the 3v pin and the cathode to the ground pin.
Your TV remote is sending out a modulated 38KHz signal. That is what the detector is expecting. Just connecting the IR led to 3v does not generate a signal that will be recognizedHere's the code I'm using:
...
The IR receiver detects light when I shine my TV remote at it; the IR LED seems to do nothing - how can I properly hook it up and detect it?
Follow through the entire tutorial. It has code and wiring examples that work: http://www.ladyada.net/learn/sensors/ir.html- how can I properly hook it up and detect it?
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: IR LED and Receiver
I followed the tutorial up to the camera and just set up my arduino as pictured above. I still can't tell if anything is going on. Thanks for your speedy help though!
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: IR LED and Receiver
Just below the camera you should see this wiring diagram:
Below that is the example code for pulsing the IR led:
Below that is the example code for pulsing the IR led:
Then we'll write a sketch which will pulse pin #13 on and off very fast in the proper code sequence
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: IR LED and Receiver
I have my LED and sensor as pictured above and changed the code to :
in order to take a sensor reading. It always appears as 1 even if I unplug the IR LED.
Code: Select all
int IRledPin = 13; // LED connected to digital pin 13
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the IR digital pin as an output:
pinMode(IRledPin, OUTPUT);
pinMode(2, INPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println("Sending IR signal");
SendNikonCode();
Serial.println(digitalRead(2));
delay(60*100); // wait one minute (60 seconds * 1000 milliseconds)
}
// This procedure sends a 38KHz pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
// we'll count down from the number of microseconds we are told to wait
cli(); // this turns off any background interrupts
while (microsecs > 0) {
// 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
delayMicroseconds(10); // hang out for 10 microseconds
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
delayMicroseconds(10); // hang out for 10 microseconds
// so 26 microseconds altogether
microsecs -= 26;
}
sei(); // this turns them back on
}
void SendNikonCode() {
// This is the code for my particular Nikon, for others use the tutorial
// to 'grab' the proper code from the remote
pulseIR(2080);
delay(27);
pulseIR(440);
delayMicroseconds(1500);
pulseIR(460);
delayMicroseconds(3440);
pulseIR(480);
delay(65); // wait 65 milliseconds before sending it again
pulseIR(2000);
delay(27);
pulseIR(440);
delayMicroseconds(1500);
pulseIR(460);
delayMicroseconds(3440);
pulseIR(480);
}
Sending IR signal
1
Sending IR signal
1
Sending IR signal
1
Sending IR signal
1
Sending IR signal
1
Sending IR signal
1
Sending IR signal
1
Sending IR signal
1
Sending IR signal
1
Sending IR signal
1
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: IR LED and Receiver
You are trying to transmit and receive at the same time. This is not possible (or at least not easily) and not very practical either. The whole point of IR remote is to transmit a signal to a remote receiver wirelessly.
Also, the received signal is not a simple digital (on/off) signal. It is a series of pulses. If you work through the rest of the tutorial, there is a section that goes through the receiver-side logic.
Also, the received signal is not a simple digital (on/off) signal. It is a series of pulses. If you work through the rest of the tutorial, there is a section that goes through the receiver-side logic.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: IR LED and Receiver
Is it possible to receive the pulse from another arduino?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: IR LED and Receiver
Yes. Set one up with the transmitter code & IR LED and the other up with the receiver & receiver code.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: IR LED and Receiver
Sorry to bother you with trivial questions, but I'm still having trouble. I'm using an arduino uno and a boarduino. On the boarduino, I hooked up the IR sensor to digital pin 2 and am using the IR decoder code: (again, it works with a remote)
On the uno, I have an IR led's anode hooked up through a resistor to digital pin 12 with this code:
Still nothing - not sure what's wrong.
Code: Select all
/* Raw IR decoder sketch!
This sketch/program uses the Arduno and a PNA4602 to
decode IR received. This can be used to make a IR receiver
(by looking for a particular code)
or transmitter (by pulsing an IR LED at ~38KHz for the
durations detected
Code is public domain, check out www.ladyada.net and adafruit.com
for more tutorials!
*/
// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN PIND
#define IRpin 2
// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000
// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20
// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing
void setup(void) {
Serial.begin(9600);
Serial.println("Ready to decode IR!");
}
void loop(void) {
uint16_t highpulse, lowpulse; // temporary storage timing
highpulse = lowpulse = 0; // start out with no pulse length
// while (digitalRead(IRpin)) { // this is too slow!
while (IRpin_PIN & _BV(IRpin)) {
// pin is still HIGH
// count off another few microseconds
highpulse++;
delayMicroseconds(RESOLUTION);
// If the pulse is too long, we 'timed out' - either nothing
// was received or the code is finished, so print what
// we've grabbed so far, and then reset
if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
currentpulse=0;
return;
}
}
// we didn't time out so lets stash the reading
pulses[currentpulse][0] = highpulse;
// same as above
while (! (IRpin_PIN & _BV(IRpin))) {
// pin is still LOW
lowpulse++;
delayMicroseconds(RESOLUTION);
if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
currentpulse=0;
return;
}
}
pulses[currentpulse][1] = lowpulse;
// we read one high-low pulse successfully, continue!
currentpulse++;
}
void printpulses(void) {
Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
for (uint8_t i = 0; i < currentpulse; i++) {
Serial.print(pulses[i][0] * RESOLUTION, DEC);
Serial.print(" usec, ");
Serial.print(pulses[i][1] * RESOLUTION, DEC);
Serial.println(" usec");
}
}
Code: Select all
// This sketch will send out a Nikon D50 trigger signal (probably works with most Nikons)
// See the full tutorial at http://www.ladyada.net/learn/sensors/ir.html
// this code is public domain, please enjoy!
int IRledPin = 13; // LED connected to digital pin 13
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the IR digital pin as an output:
pinMode(IRledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println("Sending IR signal");
SendNikonCode();
delay(60*1000); // wait one minute (60 seconds * 1000 milliseconds)
}
// This procedure sends a 38KHz pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
// we'll count down from the number of microseconds we are told to wait
cli(); // this turns off any background interrupts
while (microsecs > 0) {
// 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
delayMicroseconds(10); // hang out for 10 microseconds
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
delayMicroseconds(10); // hang out for 10 microseconds
// so 26 microseconds altogether
microsecs -= 26;
}
sei(); // this turns them back on
}
void SendNikonCode() {
// This is the code for my particular Nikon, for others use the tutorial
// to 'grab' the proper code from the remote
pulseIR(2080);
delay(27);
pulseIR(440);
delayMicroseconds(1500);
pulseIR(460);
delayMicroseconds(3440);
pulseIR(480);
delay(65); // wait 65 milliseconds before sending it again
pulseIR(2000);
delay(27);
pulseIR(440);
delayMicroseconds(1500);
pulseIR(460);
delayMicroseconds(3440);
pulseIR(480);
}
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: IR LED and Receiver
That code is written to use pin 13.On the uno, I have an IR led's anode hooked up through a resistor to digital pin 12 with this code:
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: IR LED and Receiver
Sorry - typo - it's on pin 13. Still nothing though.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: IR LED and Receiver
What resistor value are you using? How far away is the receiver, and are the receiver and transmitter facing each other with a clear line-of-sight?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: IR LED and Receiver
Also. If you had previously hooked it up without a resistor, it (or the pin it was connected to) may be damaged.
If you have a web-cam or other digital camera with an LCD display, use it to watch the led while you are transmitting. Most digital cameras are sensitive to IR light and you will be able to see the LED flashing if it is working.
If you have a web-cam or other digital camera with an LCD display, use it to watch the led while you are transmitting. Most digital cameras are sensitive to IR light and you will be able to see the LED flashing if it is working.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: IR LED and Receiver
I am using a brand new IR LED (opened after I read the post) with a 330ohm (orange, orange, brown, gold) resistor. The LED and resistor are almost directly adjacent to each other.
I have tried to use my iPhone's camera to see if the LED was on but saw nothing. With a webcam, I see a remote's IR LED light up but still nothing from the arduino pulse code.
I have tried to use my iPhone's camera to see if the LED was on but saw nothing. With a webcam, I see a remote's IR LED light up but still nothing from the arduino pulse code.
-
- Posts: 84
- Joined: Tue Nov 02, 2010 7:29 am
Re: IR LED and Receiver
I just got it working - thanks so much for the help. I shortened the IR pulse send delay (to 0.3 seconds) and am now getting this when connected:
Planning on making a laser tag project... so thank you very much.Heard 8-pulse long IR signal
count set to: 8
count set to: 8
count set to: 8
Heard 8-pulse long IR signal
count set to: 8
count set to: 8
count set to: 8
Heard 8-pulse long IR signal
count set to: 8
count set to: 8
count set to: 8
Heard 8-pulse long IR signal
count set to: 8
count set to: 8
count set to: 8
Heard 8-pulse long IR signal
count set to: 8
count set to: 8
count set to: 8
Heard 8-pulse long IR signal
count set to: 8
count set to: 8
count set to: 8
Please be positive and constructive with your questions and comments.