{"id":3798,"date":"2026-11-21T06:51:24","date_gmt":"2026-11-20T22:51:24","guid":{"rendered":"http:\/\/www.sportsdie.com\/blog\/?p=3798"},"modified":"2026-11-21T06:51:24","modified_gmt":"2026-11-20T22:51:24","slug":"how-to-code-arduino-for-ir-led-485d-c6c855","status":"publish","type":"post","link":"http:\/\/www.sportsdie.com\/blog\/2026\/11\/21\/how-to-code-arduino-for-ir-led-485d-c6c855\/","title":{"rendered":"How to code Arduino for IR LED?"},"content":{"rendered":"<p>What\u2019s good, makers and electronics hobbyists! If you\u2019ve ever messed around with remote controls, home automation triggers, or even that little buggy you control with a phone, you\u2019ve probably worked with IR (infrared) LEDs\u2014whether you realized it or not. And let\u2019s be real: coding Arduino to work with these tiny workhorses can feel super overwhelming at first, especially if you\u2019re still wrapping your head around serial communication or signal timing. But hey, I\u2019m an IR LED supplier, so I\u2019ve walked way too many folks through this exact process, and today I\u2019m breaking it down step by step\u2014no fancy jargon, no confusing textbook formulas, just what actually works. <a href=\"https:\/\/www.allightled.com\/ir-led\/\">IR LED<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.allightled.com\/uploads\/16197\/small\/3mm-red-led299da.jpg\"><\/p>\n<p>First off, let\u2019s 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\u2019s where my side of the business comes in\u2014we make IR LEDs tailored for Arduino projects, so you don\u2019t have to guess if your part is compatible. But we\u2019ll get to that later. Right now, let\u2019s dive into the setup.<\/p>\n<p>First, you\u2019ll need your basics: an Arduino board (I\u2019m using an Uno here, it\u2019s the most common, but this works for Nano, Pro Mini, whatever you\u2019ve got), an IR LED, a current-limiting resistor, a breadboard, some jumper wires, and your Arduino IDE set up on your computer. Wait\u2014why a current-limiting resistor? Oh, right\u2014IR LEDs (like most LEDs) draw too much current straight out of the Arduino\u2019s pin without one. For standard 5mm IR LEDs, a 220\u03a9 or 330\u03a9 resistor is perfect. If you skip this, you\u2019ll burn out your IR LED way before you test your code, and that\u2019s a waste.<\/p>\n<p>Now, the wiring: this is where most new folks mess up, so pay attention. Your Arduino\u2019s 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\u2014most consumer remotes use 38kHz, so PWM lets your Arduino toggle the pin on and off fast enough to hit that frequency. For Uno, that\u2019s pins 3,5,6,9,10,11. Let\u2019s pick pin 9, it\u2019s easy to remember.<\/p>\n<p>Wiring steps:<\/p>\n<ol>\n<li>Take your current-limiting resistor and plug one end into pin 9 on the Arduino.<\/li>\n<li>The other end of the resistor goes to the anode (the long leg, or the flat side of the plastic casing\u2019s indent) of your IR LED.<\/li>\n<li>The cathode (short leg, opposite side of the anode) of the IR LED goes to a GND pin on the Arduino.<br \/>\nWait\u2014double check that: anode to resistor to PWM pin, cathode to GND. Mixing those up won\u2019t break anything, but your IR LED won\u2019t light up. I\u2019ve seen so many folks flip this and panic, so just confirm before you move on.<\/li>\n<\/ol>\n<p>Once your wiring is done, open up the Arduino IDE. Now, here\u2019s the thing: you don\u2019t have to code the IR signal from scratch. That\u2019s 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\u2014it\u2019s the go-to, it\u2019s 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 &gt; Include Library &gt; Manage Libraries, then search for \u201cIRremote\u201d and install the one by shirriff\u2014 that\u2019s the most maintained, no glitches.<\/p>\n<p>Wait, quick pro tip from an IR LED supplier: make sure your IR LED is a 940nm part if you\u2019re using IRremote for most remote projects. 850nm IR LEDs are brighter for lighting, but 940nm is perfect for transmitting signals, which is what you\u2019ll use Arduino for. We stock both, but 940nm is your best bet for this project.<\/p>\n<p>Now, let\u2019s write the code. I\u2019m keeping this super simple: we\u2019ll send a basic NEC signal, which is the standard for most TV remotes, air con, etc. Copy this exactly, then adjust as needed:<\/p>\n<p>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.<\/p>\n<p>Wait, here\u2019s the code:<br \/>\n#include &lt;IRremote.h&gt;<\/p>\n<p>const int IR_LED_PIN = 9;<br \/>\nIRsend irsend(IR_LED_PIN);<\/p>\n<p>void setup() {<br \/>\nSerial.begin(9600);<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n\/\/ Send NEC signal: address 0x01, command 0x02 (super basic test code)<br \/>\nirsend.sendNEC(0x01, 0x02);<br \/>\nSerial.println(&quot;Sent IR signal!&quot;);<br \/>\ndelay(2000); \/\/ Wait 2 seconds before sending again<br \/>\n}<\/p>\n<p>Wait, what\u2019s sendNEC(0x01, 0x02)? That\u2019s the NEC protocol: the first number is the address, the second is the command. You can swap those numbers to send different signals\u2014if you want to control a TV, you\u2019d 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\u2019s 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\u2019ll spit out the address and command numbers. Easy peasy.<\/p>\n<p>Now, upload that code to your Arduino. Once it\u2019s done, point your IR LED at your phone\u2019s 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\u2019t, double check your wiring\u2014most likely the resistor was skipped, or the legs of the IR LED are flipped. I can\u2019t tell you how many times I\u2019ve had a customer message me saying their new IR LED isn\u2019t working, and it\u2019s just a flipped leg.<\/p>\n<p>Now, let\u2019s talk common issues, because even this simple setup can go wrong. First, range: if your IR signal only works a few inches away, that\u2019s 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\u2019re using a 36kHz signal instead of 38kHz, your remote won\u2019t pick it up. The IRremote library defaults to 38kHz, which is standard, but if you\u2019re using a different protocol, make sure you adjust that. Third, power: if you\u2019re using a lot of IR LEDs, you can\u2019t power them straight from the Arduino\u2019s 5V pin\u2014you need an external power supply, like a 9V battery or a 5V 2A adapter. The Arduino\u2019s pin can only supply around 20mA, so if you\u2019re running multiple IR LEDs, they\u2019ll be dim and unreliable.<\/p>\n<p>Wait, what if you want to do more advanced stuff? Like, control multiple devices, or turn an IR signal into a trigger? That\u2019s 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.<\/p>\n<p>Here\u2019s another pro tip from my side: IR LEDs don\u2019t last forever. If you\u2019re using them for a project that\u2019s going to run 24\/7, pick an IR LED with a long lifespan\u2014we 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.<\/p>\n<p>Wait, let\u2019s test a quick debug step if your code isn\u2019t working. Open the Serial Monitor in the Arduino IDE, set it to 9600 baud. If it says \u201cSent IR signal!\u201d every 2 seconds, the code is running, so the issue is likely hardware. If it doesn\u2019t say that, you messed up the code\u2014double check that you installed IRremote correctly, and that the pin number is right.<\/p>\n<p>Now, let\u2019s wrap this up. Coding Arduino for IR LEDs doesn\u2019t have to be complicated. You don\u2019t need to be a genius at signal timing, you just need the right parts, the right library, and a little patience. And if you\u2019re picking IR LEDs for your project, don\u2019t go for the random cheap ones on Amazon\u2014get parts that are tested for Arduino compatibility, so you don\u2019t waste time troubleshooting hardware issues when your code is perfect.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.allightled.com\/uploads\/202016197\/small\/germicidal-275-nm-uvc-led07481301845.jpg\"><\/p>\n<p>If you\u2019re working on a project\u2014whether it\u2019s a home automation remote, a robot, a security trigger, anything with IR LEDs\u2014and 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.<\/p>\n<p><a href=\"https:\/\/www.allightled.com\/dip-diode-led\/8mm-dip-led\/\">8mm DIP LED<\/a> References<br \/>\nArduino Official Documentation<br \/>\nIRremote Library for Arduino<br \/>\nIR LED Datasheets for Arduino-Compatible Parts<\/p>\n<hr>\n<p><a href=\"https:\/\/www.allightled.com\/\">Dongguan Zhiding Electronics Technology Co., Ltd.<\/a><br \/>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.<br \/>Address: No. 8, Xiaqiao Yinling Industry Zone, Dongcheng Dist., Dongguan, Guangdong, China<br \/>E-mail: sales@zhidingled.com<br \/>WebSite: <a href=\"https:\/\/www.allightled.com\/\">https:\/\/www.allightled.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What\u2019s good, makers and electronics hobbyists! If you\u2019ve ever messed around with remote controls, home automation &hellip; <a title=\"How to code Arduino for IR LED?\" class=\"hm-read-more\" href=\"http:\/\/www.sportsdie.com\/blog\/2026\/11\/21\/how-to-code-arduino-for-ir-led-485d-c6c855\/\"><span class=\"screen-reader-text\">How to code Arduino for IR LED?<\/span>Read more<\/a><\/p>\n","protected":false},"author":25,"featured_media":3798,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3761],"class_list":["post-3798","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-ir-led-49f7-c6f38b"],"_links":{"self":[{"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/posts\/3798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/comments?post=3798"}],"version-history":[{"count":0,"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/posts\/3798\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/posts\/3798"}],"wp:attachment":[{"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/media?parent=3798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/categories?post=3798"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sportsdie.com\/blog\/wp-json\/wp\/v2\/tags?post=3798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}