What’s good, makers and electronics hobbyists! If you’ve ever messed around with remote controls, home automation triggers, or even that little buggy you control with a phone, you’ve probably worked with IR (infrared) LEDs—whether you realized it or not. And let’s be real: coding Arduino to work with these tiny workhorses can feel super overwhelming at first, especially if you’re still wrapping your head around serial communication or signal timing. But hey, I’m an IR LED supplier, so I’ve walked way too many folks through this exact process, and today I’m breaking it down step by step—no fancy jargon, no confusing textbook formulas, just what actually works. IR LED

First off, let’s get one thing straight: not all IR LEDs are made equal. If you grab a random one from a box, it might not work with your Arduino, or it might be too dim for what you need. That’s where my side of the business comes in—we make IR LEDs tailored for Arduino projects, so you don’t have to guess if your part is compatible. But we’ll get to that later. Right now, let’s dive into the setup.
First, you’ll need your basics: an Arduino board (I’m using an Uno here, it’s the most common, but this works for Nano, Pro Mini, whatever you’ve got), an IR LED, a current-limiting resistor, a breadboard, some jumper wires, and your Arduino IDE set up on your computer. Wait—why a current-limiting resistor? Oh, right—IR LEDs (like most LEDs) draw too much current straight out of the Arduino’s pin without one. For standard 5mm IR LEDs, a 220Ω or 330Ω resistor is perfect. If you skip this, you’ll burn out your IR LED way before you test your code, and that’s a waste.
Now, the wiring: this is where most new folks mess up, so pay attention. Your Arduino’s 5V pin is your power, GND is ground, and then you need a PWM (pulse-width modulation) pin on your Arduino. Why PWM? IR signals work on specific frequency bursts—most consumer remotes use 38kHz, so PWM lets your Arduino toggle the pin on and off fast enough to hit that frequency. For Uno, that’s pins 3,5,6,9,10,11. Let’s pick pin 9, it’s easy to remember.
Wiring steps:
- Take your current-limiting resistor and plug one end into pin 9 on the Arduino.
- The other end of the resistor goes to the anode (the long leg, or the flat side of the plastic casing’s indent) of your IR LED.
- The cathode (short leg, opposite side of the anode) of the IR LED goes to a GND pin on the Arduino.
Wait—double check that: anode to resistor to PWM pin, cathode to GND. Mixing those up won’t break anything, but your IR LED won’t light up. I’ve seen so many folks flip this and panic, so just confirm before you move on.
Once your wiring is done, open up the Arduino IDE. Now, here’s the thing: you don’t have to code the IR signal from scratch. That’s a mistake a lot of newbies make, writing lines and lines of timing code just to send a single signal. Instead, use the IRremote library—it’s the go-to, it’s free, and it works with almost every common IR protocol (NEC, Sony, RC5, even the old remotes from the 90s). To install it, go to Sketch > Include Library > Manage Libraries, then search for “IRremote” and install the one by shirriff— that’s the most maintained, no glitches.
Wait, quick pro tip from an IR LED supplier: make sure your IR LED is a 940nm part if you’re using IRremote for most remote projects. 850nm IR LEDs are brighter for lighting, but 940nm is perfect for transmitting signals, which is what you’ll use Arduino for. We stock both, but 940nm is your best bet for this project.
Now, let’s write the code. I’m keeping this super simple: we’ll send a basic NEC signal, which is the standard for most TV remotes, air con, etc. Copy this exactly, then adjust as needed:
First, include the library, define the IR pin, make an IRsend object. In setup, start serial communication (for debugging, just in case), then in loop, send a signal every 2 seconds.
Wait, here’s the code:
#include <IRremote.h>
const int IR_LED_PIN = 9;
IRsend irsend(IR_LED_PIN);
void setup() {
Serial.begin(9600);
}
void loop() {
// Send NEC signal: address 0x01, command 0x02 (super basic test code)
irsend.sendNEC(0x01, 0x02);
Serial.println("Sent IR signal!");
delay(2000); // Wait 2 seconds before sending again
}
Wait, what’s sendNEC(0x01, 0x02)? That’s the NEC protocol: the first number is the address, the second is the command. You can swap those numbers to send different signals—if you want to control a TV, you’d use the address the TV uses, and the command for power, volume up, whatever. How do you find those numbers? Use the IRrecv example, that’s in the library, to read signals from your existing remote. Plug an IR receiver (like the TSOP1838) into your Arduino, run the IRrecv demo, point your remote at it, and it’ll spit out the address and command numbers. Easy peasy.
Now, upload that code to your Arduino. Once it’s done, point your IR LED at your phone’s camera (yes, your phone camera picks up IR!) and open the camera. You should see a little blinking light when the code runs. If you don’t, double check your wiring—most likely the resistor was skipped, or the legs of the IR LED are flipped. I can’t tell you how many times I’ve had a customer message me saying their new IR LED isn’t working, and it’s just a flipped leg.
Now, let’s talk common issues, because even this simple setup can go wrong. First, range: if your IR signal only works a few inches away, that’s probably your IR LED. Some cheap IR LEDs only have a 5m range, but the ones we supply have up to 20m, which is way better for home automation. Second, frequency mismatch: if you’re using a 36kHz signal instead of 38kHz, your remote won’t pick it up. The IRremote library defaults to 38kHz, which is standard, but if you’re using a different protocol, make sure you adjust that. Third, power: if you’re using a lot of IR LEDs, you can’t power them straight from the Arduino’s 5V pin—you need an external power supply, like a 9V battery or a 5V 2A adapter. The Arduino’s pin can only supply around 20mA, so if you’re running multiple IR LEDs, they’ll be dim and unreliable.
Wait, what if you want to do more advanced stuff? Like, control multiple devices, or turn an IR signal into a trigger? That’s easy, too. For example, if you want to send two different signals, you can add a button: when you press button 2, send volume up, when you press button 3, send power. The same IRremote library works for that, just add a button pin and a digitalRead check.
Here’s another pro tip from my side: IR LEDs don’t last forever. If you’re using them for a project that’s going to run 24/7, pick an IR LED with a long lifespan—we make parts with 100,000 hour lifespans, which is way better than the 50,000 hour cheap ones. Also, avoid running your IR LED at full current all the time; that will cut its lifespan in half. If you need more brightness, use multiple IR LEDs wired in parallel, not one big one.
Wait, let’s test a quick debug step if your code isn’t working. Open the Serial Monitor in the Arduino IDE, set it to 9600 baud. If it says “Sent IR signal!” every 2 seconds, the code is running, so the issue is likely hardware. If it doesn’t say that, you messed up the code—double check that you installed IRremote correctly, and that the pin number is right.
Now, let’s wrap this up. Coding Arduino for IR LEDs doesn’t have to be complicated. You don’t need to be a genius at signal timing, you just need the right parts, the right library, and a little patience. And if you’re picking IR LEDs for your project, don’t go for the random cheap ones on Amazon—get parts that are tested for Arduino compatibility, so you don’t waste time troubleshooting hardware issues when your code is perfect.

If you’re working on a project—whether it’s a home automation remote, a robot, a security trigger, anything with IR LEDs—and you need the right parts, or you have questions about wiring or code, hit me up to chat through your needs. We can hook you up with the perfect IR LED for your Arduino project, no hassle, no hidden fees.
8mm DIP LED References
Arduino Official Documentation
IRremote Library for Arduino
IR LED Datasheets for Arduino-Compatible Parts
Dongguan Zhiding Electronics Technology Co., Ltd.
Dongguan Zhiding Electronics Technology Co., Ltd. is one of the most professional ir led manufacturers and suppliers in China, specialized in providing high quality customized products. We warmly welcome you to wholesale bulk ir led in stock and get free sample from our factory.
Address: No. 8, Xiaqiao Yinling Industry Zone, Dongcheng Dist., Dongguan, Guangdong, China
E-mail: sales@zhidingled.com
WebSite: https://www.allightled.com/