Posts about... All (17) Android (2) Hooking Up Parts (10) Game Controllers (3) Robots (2)

How to Hook Up > IR Emitter and Receiver

An IR receiver can detect infrared light emitted from an IR LED. This post details how to hook up both parts as well as detect a break in the signal between the two, which would allow you to tell if something passed between them.

Parts

Steps

Code

After uploading the following code to your Arduino, open the Serial Monitor in the Arduino software. The score starts at 0 and every break will add 100 to the score. To test that you have wired the components correctly, hold your hand in between the LED and the receiver to block the signal for a second, remove it, and repeat while keeping an eye on the serial monitor.

If you do not already have the IRremote library, you can download it here. Unzip the folder and place it in the “libraries” folder in your Arduino project folder. (Tip: Create a new folder called “libraries” if it does not already exist.)

#include <IRremote.h>

#define PIN_IR 3
#define PIN_DETECT 2
#define PIN_STATUS 13

IRsend irsend;
int score = 0;
boolean busy = false;

void setup()
{
pinMode(PIN_DETECT, INPUT);
pinMode(PIN_STATUS, OUTPUT);
irsend.enableIROut(38);
irsend.mark(0);
Serial.begin(57600);
}

void loop() {

if(digitalRead(PIN_DETECT) == 1){
digitalWrite(PIN_STATUS, HIGH);
if(!busy){
score += 100;
busy = true;
}
}
else{
digitalWrite(PIN_STATUS, LOW);
busy = false;
}
Serial.println(score);
}