Build it step by step
0 of 6 doneWire the sender
Add the IR LED with its resistor on D3 of the first Nano.
Check the LED
View the LED through a phone camera: it shows as a faint purple flash when it sends.
Wire the receiver
Connect the VS1838B to the second Nano on D2.
Upload both sketches
Open the Serial Monitor at 115200 on the receiver.
Read the text
HELLO should appear every three seconds.
Test range and angle
Move apart and turn the LED to find how far and wide it works.
How do you build an infrared data link?
Send text between two boards using an IR LED and a 38 kHz IR receiver, like a TV remote. You need Arduino Nano × 2, IR LED 940 nm (5 mm), IR receiver VS1838B, Resistor 220 Ω, Breadboard 830 Tie Points × 2 and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Nano × 2
- OptoelectronicsBuy
- SensorsBuy
- PassivesBuyResistor 220 Ω × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Sender Nano D3 | 220 Ω resistor then IR LED anode | Transmit pin |
| IR LED cathode | Sender GND | Return |
| Receiver Nano D2 | IR receiver OUT pin | Receive pin |
| IR receiver VCC, GND | Receiver Nano 5V, GND | Power (check your module's pin order) |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "IRremote" by Armin Joachimsmeyer (version 4 or later) on both boards. The 220 Ω resistor keeps the LED near 15 mA; a TV remote pulses far harder, so you can lower it to 100 Ω for more range because the 38 kHz bursts are short. Many VS1838B modules differ in pin order, so check the printed labels or datasheet before powering. Do not point the LED at anyone's eyes from very close range for long periods.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// ---- Sender sketch (Nano 1): sends HELLO as NEC codes every 3 seconds ----
#include <IRremote.hpp>
const uint8_t ADDRESS = 0x10;
const char MESSAGE[] = "HELLO";
void setup() {
IrSender.begin(3); // the IR LED is on pin 3 of the Nano
}
void loop() {
for (const char* p = MESSAGE; *p; p++) {
IrSender.sendNEC(ADDRESS, (uint8_t)*p, 0); // one character per NEC frame
delay(120);
}
IrSender.sendNEC(ADDRESS, '\n', 0);
delay(3000);
}
/* ---- Receiver sketch (Nano 2) ----
#include <IRremote.hpp>
void setup() {
Serial.begin(115200);
IrReceiver.begin(2, ENABLE_LED_FEEDBACK);
}
void loop() {
if (IrReceiver.decode()) {
if (IrReceiver.decodedIRData.protocol == NEC && IrReceiver.decodedIRData.address == 0x10) {
Serial.write((char)IrReceiver.decodedIRData.command);
}
IrReceiver.resume();
}
}
*/Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Boards a hand apart facing each other | HELLO appears on the receiver |
| Receiver facing away | Nothing received |
| Blocking the beam | Message missing |
| Bright sunlight on the receiver | Shorter range |
If it does not work
Nothing received
Check the receiver pins and that the LED faces it.
Garbage characters
Weak signal. Move closer or lower the resistor value.
Camera shows no flash
LED is backwards or the sender is not running.
Works only very close
Use a lower resistor value and align the LED and receiver.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the infrared data link?
Arduino Nano × 2, IR LED 940 nm (5 mm), IR receiver VS1838B, Resistor 220 Ω, Breadboard 830 Tie Points × 2 and Jumper wires male to male (40 pcs, 20 cm).
How long does the infrared data link take to build?
About 90 minutes for a beginner maker, in 6 steps.
How do I know the infrared data link works?
Boards a hand apart facing each other: HELLO appears on the receiver. Receiver facing away: Nothing received. Blocking the beam: Message missing.
Nothing received: what should I check?
Check the receiver pins and that the LED faces it.
Garbage characters: what should I check?
Weak signal. Move closer or lower the resistor value.
Camera shows no flash: what should I check?
LED is backwards or the sender is not running.
Works only very close: what should I check?
Use a lower resistor value and align the LED and receiver.
