If you plug an infrared (IR) LED directly into an Arduino GPIO pin, you will be disappointed by the range. While the Arduino Uno R4 Minima is a capable 5V microcontroller, its GPIO pins are strictly limited to 8mA continuous current (with a 20mA absolute maximum). High-power IR protocols like NEC or Sony require pulsed currents of 100mA to 300mA to achieve reliable line-of-sight ranges beyond 10 feet. To bridge this gap, you must use a transistor driver circuit that allows the Arduino to handle the 38kHz PWM modulation while the transistor handles the heavy current lifting.

The Physics of IR Range: Why Direct GPIO Drive Fails

The range of an IR emitter is not determined by its continuous forward voltage, but by its pulsed forward current. When transmitting a 38kHz carrier wave, the LED is rapidly turning on and off. During the "on" phase (which lasts only microseconds), you want to push as much current as safely possible to maximize photon output. A direct GPIO connection bottlenecks this at ~8mA, resulting in a weak signal that fails to trigger a receiver across a standard living room.

By introducing an NPN transistor like the 2N2222A, we use the Arduino's weak 5V/4mA signal to switch a much larger current from the 5V rail directly through the LED. Below is the current budget and specification breakdown for the components used in this build.

Table 1: Component Specifications & Current Budget
Component Role Key Specification Max / Target Value
Arduino Uno R4 Minima (GPIO) PWM Signal Source Continuous Current Limit 8mA (Target: 4.3mA)
TSAL6200 (940nm) IR Emitter Pulsed Forward Current (tp = 100µs) 200mA (Target: 100mA)
2N2222A (NPN BJT) Low-Side Switch Continuous Collector Current (Ic) 600mA (Target: 100mA)
33Ω 1/2W Resistor Current Limiter Voltage Drop at 100mA 3.3V (Dissipates ~0.33W)
1kΩ 1/4W Resistor Base Limiter Base Current (Ib) 4.3mA (Ensures saturation)

Parts List & Pin Mapping

This build targets the Arduino Uno R4 Minima. The code and pinouts are also 100% backward-compatible with the classic Uno R3, Nano, and Mega 2560, provided you use 5V logic pins.

  • Microcontroller: Arduino Uno R4 Minima
  • IR LED: Vishay TSAL6200 (940nm, high power, 5mm package)
  • Transistor: 2N2222A (TO-92 package, NPN)
  • Resistors: 1x 33Ω (1/2W), 1x 1kΩ (1/4W)
  • Misc: Half-size breadboard, jumper wires
Table 2: Pin Mapping & Wiring Guide
Arduino Pin Connects To Notes
D3 (PWM) 1kΩ Resistor (Leg 1) Hardware PWM pin required by IRremote
5V 33Ω Resistor (Leg 1) Provides main current path for LED
GND 2N2222A Emitter (Pin 1) Common ground reference
D13 Onboard LED Used for visual TX feedback (no wiring needed)

Wiring the Transistor Driver Circuit

Follow these steps to assemble the low-side switch driver. Pay close attention to the transistor pinout and LED polarity.

  1. Place the 2N2222A Transistor: Insert the transistor into the breadboard. With the flat side facing you and the legs pointing down, the pins from left to right are Emitter (E), Base (B), and Collector (C).
  2. Wire the Base: Connect the 1kΩ resistor from Arduino Pin D3 to the Base (middle pin) of the transistor.
  3. Ground the Emitter: Connect the Emitter (left pin) directly to the Arduino GND rail.
  4. Wire the Collector & LED: Connect the Anode (long leg) of the TSAL6200 IR LED to one end of the 33Ω resistor. Connect the other end of the 33Ω resistor to the Arduino 5V pin. Connect the Cathode (short leg, flat edge) of the IR LED to the Collector (right pin) of the transistor.
⚠️ Bench Tip: The 1/2W Resistor Requirement
Do not use a standard 1/4W resistor for the 33Ω current limiter. While the 38kHz PWM duty cycle reduces the average power dissipation, the peak instantaneous power during the "on" pulse approaches 0.33W. A 1/4W resistor will overheat and drift in value, altering your IR range. Use a 1/2W resistor for thermal stability.

Complete IRremote Transmitter Code (Arduino Uno R4)

This code uses the industry-standard Arduino-IRremote library (v4.x). It transmits a standard NEC command every two seconds. Ensure you have the library installed via the Arduino Library Manager before compiling.

#include <Arduino.h>

// CRITICAL: Define the send pin BEFORE including IRremote.h
// Failing to do so will trigger a compilation #error directive in v4.x
#define IR_SEND_PIN 3
#include <IRremote.h>

const uint8_t STATUS_LED_PIN = 13;
unsigned long lastSendTime = 0;
const unsigned long SEND_INTERVAL = 2000; // Transmit every 2 seconds

void setup() {
  Serial.begin(115200);
  
  // Wait for serial monitor to connect (useful for R4 Minima / Leonardo)
  while (!Serial && millis() < 2500) {
    delay(10);
  }
  
  pinMode(STATUS_LED_PIN, OUTPUT);
  
  // Initialize the IR sender (uses hardware PWM on IR_SEND_PIN)
  IrSender.begin(); 
  
  Serial.println(F("IR Emitter initialized on Pin 3 (PWM)."));
  Serial.println(F("Sending NEC protocol (Addr: 0x00FF, Cmd: 0x19E6)..."));
}

void loop() {
  // Non-blocking timer for transmission interval
  if (millis() - lastSendTime >= SEND_INTERVAL) {
    lastSendTime = millis();
    
    // Send NEC command: Address, Command, Repeats (0 = no repeats)
    IrSender.sendNEC(0x00FF, 0x19E6, 0);
    
    // Visual feedback on onboard LED
    digitalWrite(STATUS_LED_PIN, HIGH);
    delay(50); 
    digitalWrite(STATUS_LED_PIN, LOW);
    
    Serial.println(F("TX: NEC 0x00FF / 0x19E6"));
  }
}

Debugging: The First Three Things to Check When It Fails

IR circuits are notorious for failing silently because human eyes cannot see 940nm light. If your receiver isn't triggering, check these three specific failure modes in order.

1. The Compilation Error: IR_SEND_PIN Not Defined

Symptom: The compiler halts with the exact error string: #error "IR_SEND_PIN must be defined before including ".
Cause: In IRremote v4.x, the library no longer defaults to Pin 3. You must explicitly declare the pin before the include statement.
Fix: Move #define IR_SEND_PIN 3 to the very top of your sketch, above #include <IRremote.h>.

2. The Silent Failure: Wavelength & Ambient Interference

Symptom: Code compiles, Serial prints "TX", but the receiver does nothing.
Cause: You are using an 850nm LED with a 940nm receiver, or compact fluorescent/sunlight is flooding the receiver with IR noise, drowning out your 100mA signal.
Fix (The Phone Camera Trick): Point your smartphone camera at the IR LED. Crucial detail: Use the front-facing (selfie) camera. Rear cameras have aggressive IR-blocking filters; selfie cameras usually do not. If you see a faint purple/white flash on your screen every 2 seconds, the emitter is working. If not, your LED is backward or the transistor is wired incorrectly.

3. The Range Issue: Transistor Saturation Voltage Drop

Symptom: Works at 2 feet, but fails at 10 feet.
Cause: The 2N2222A is not fully saturating, acting as a resistor instead of a closed switch, dropping voltage that should be going to the LED.
Fix: Measure the voltage between the Collector and Emitter (Vce) with a multimeter while the circuit is pulsing (use the Min/Max hold feature). If Vce is above 0.5V, your base current is too low. Drop the 1kΩ base resistor to 470Ω to force harder saturation.

Extending and Simplifying the Build

Depending on your final application, you may want to scale this circuit up for a home-brew universal remote, or scale it down for a quick prototype.

Simplify: Integrated Modules

If you don't need 20-foot range and just want to test logic on a desk, skip the discrete components and buy a KY-005 IR Transmitter Module ($1-$2). It includes the LED and a basic resistor on a breakout board. Warning: The KY-005 lacks a transistor driver and is wired directly to the GPIO, limiting its effective range to about 3 feet.

Extend: Multi-Amp LED Arrays

To blast IR signals through walls or across large warehouses, replace the 2N2222A BJT with a logic-level MOSFET like the IRLZ44N. This allows you to wire three or four TSAL6200 LEDs in parallel (each with its own 33Ω resistor) and pull 400mA+ from the 5V rail without overheating the switching element.

By respecting the current limits of your microcontroller and leveraging basic analog components, you transform a weak, short-range GPIO signal into a robust, room-filling IR transmission system. Always verify your pulse currents with a multimeter and rely on the camera-trick to save hours of blind debugging.