# 4.1 Infrared Emitter and Receiver

## Hardware Wiring

![Infrared Emitter and Receiver](https://2341898987-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LCFDbcteyTR3tQSs-5x%2F-LCFE4dCRQBMq1ajywfh%2F-LCFE9HUuK6smz06SaMU%2F005_infrared.jpg?generation=1526059550993513\&alt=media)

## Sketch

The code can be found at [Examples\_Arduino - sensor-kit-for-arduino - \_005\_IRRemote\_Emit - \_005\_IRRemote\_Emit.ino](https://github.com/LongerVisionRobot/Examples_Arduino/blob/master/sensor-kit-for-arduino/_005_IRRemote_Emit/_005_IRRemote_Emit.ino) and [Examples\_Arduino - sensor-kit-for-arduino - \_005\_IRRemote\_Receive - \_005\_IRRemote\_Receive.ino](https://github.com/LongerVisionRobot/Examples_Arduino/blob/master/sensor-kit-for-arduino/_005_IRRemote_Receive/_005_IRRemote_Receive.ino) .

### Emit

```
#include <IRremote.h>
IRsend irsend;
void setup()
{
  Serial.begin(9600);
}
void loop() {
  for (int i = 0; i < 50; i++) {
    irsend.sendSony(0xa90, 12); // Sony TV power code
    delay(40);
  }
}
```

### Receive

```
#include <IRremote.h>
int RECV_PIN = 11; //define input pin on Arduino
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}
void loop() {
  irrecv.decode(&results);
  Serial.println(results.value, HEX);
if (irrecv.decode(&results)) {
  Serial.println(results.value, HEX);
  irrecv.resume(); // Receive the next value
  }
}
```
