IR Transmitter Sensor
The IR Transmitter Sensor project demonstrates how to use an Arduino Nano to transmit IR signals. The project uses the IRremote library to send IR codes, which can be used to control various devices such as TVs, DVD players, and other IR-controlled electronics. This example sends Sony IR codes when a command is received via the serial monitor.
How It Works
An infrared transmitter module such as the KY-005 carries a 940 nm IR LED. It is the sending half of the remote-control link that every television uses, and on the Arduino Nano it lets a project imitate a remote handset.
Consumer IR does not simply switch the LED on and off. The data is modulated onto a 38 kHz carrier: a logical mark is a burst of 38 kHz flashes, a space is darkness. Receivers are tuned to that carrier and ignore anything else, which is how a remote works in a sunlit room. Because sunlight and fluorescent lamps carry no 38 kHz component, they are filtered out.
On top of the carrier sits a protocol that defines how long marks and spaces encode bits. NEC is the most common: a 9 ms leading burst, a 4.5 ms space, then 32 bits where a one and a zero differ by space length. Sony SIRC, RC5 and Samsung variants all differ in timing, which is why libraries ask which protocol to send.
Components Needed
- Arduino Nano
- IR LED
- 220Ω Resistor
- Jumper Wires
Wiring to the Arduino Nano
Connect S to D9, the middle pin to the 5 V rail and − to GND. The IRremote library takes over a hardware timer to generate the 38 kHz carrier, and that timer dictates which pin can be used — on the Arduino Nano the library's default output pin is the safe choice.
The KY-005 includes a series resistor sized for roughly 20 mA, giving a useful range of two to three metres. For longer range, drive the LED through a transistor at higher current; IR LEDs tolerate large pulsed currents because the duty cycle is low.
Aim matters more than power. IR LEDs have a beam angle of about 20–30°, so pointing the emitter at the receiver gains more range than increasing current.
| Module pin | Arduino Nano pin | Function |
|---|---|---|
| S (signal) | D9 | Carrier output — must be a PWM-capable pin |
| Middle | 5V | Supply |
| − (GND) | GND | Common ground |
Build and Upload
Connect the Arduino Nano to your computer via USB.
Open the Arduino IDE and paste the provided code.
Upload the code to the Arduino Nano.
Once the code is uploaded, open the serial module.
Enter '1' or '2' and press enter. The Arduino will send the corresponding IR code.
Point the IR LED at the device you want to control and observe the response.
Example Code
Sending an NEC remote code with the IRremote library. Upload it with the board set to Arduino Nano and open the Serial Monitor at 9600 baud.
#include <IRremote.hpp>
const int IR_SEND_PIN = 9;
void setup() {
Serial.begin(9600);
IrSender.begin(IR_SEND_PIN);
Serial.println("IR transmitter ready");
}
void loop() {
// NEC: 16-bit address, 8-bit command, no repeats
IrSender.sendNEC(0x0102, 0x34, 0);
Serial.println("sent NEC 0x0102 / 0x34");
delay(2000);
}
Applications
A infrared transmitter turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:
- Replacing a lost remote control for a television, projector or air conditioner
- Scheduling appliances — turning a projector off automatically at a set time
- Short-range one-way data links between two microcontrollers
- Home-automation bridges that convert WiFi commands into IR commands
- Line-of-sight triggers for cameras and lighting rigs
Working with the Arduino Nano
The Arduino Nano is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.
The Nano shares the Uno’s ATmega328P but adds A6 and A7, which are analog-input only and cannot be used as digital pins.
Its DIP footprint drops straight into a breadboard, which suits permanent sensor builds.
Older clones use the CH340 USB bridge and may need that driver plus the "ATmega328P (Old Bootloader)" processor option.
| Arduino Nano characteristic | Value | Why it matters here |
|---|---|---|
| Logic voltage | 5 V | Matches most hobby modules directly |
| ADC resolution | 10-bit (0–1023) | Sets how finely an analog reading can be resolved |
| Analog inputs | A0–A7 (eight channels, two more than the Uno) | Determines how many analog sensors can share the board |
| PWM outputs | D3, D5, D6, D9, D10 and D11 | Needed for brightness, speed and tone control |
| I²C pins | A4 (SDA) and A5 (SCL) | Fixed by hardware — wiring copied from another board may not match |
| Interrupt pins | D2 and D3 only | Required for counting fast or asynchronous events |
| Serial | a single hardware UART shared with USB | Monitor runs at 9600 baud by default |
Troubleshooting
Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:
- Nothing happens — capture the original remote first with a receiver module; guessing the protocol rarely works.
- Range is under a metre — the LED is current-starved, or the emitter is not aimed at the target.
- It works at 20 cm but not across the room — drive the LED through a transistor rather than straight from a GPIO.
- The code sends but the appliance ignores it — many devices need the frame repeated two or three times.
- IR LEDs emit no visible light. To confirm the LED is firing, view it through a phone camera, which sees 940 nm as a faint purple flicker.
- Code written for an ESP board gives odd analog values — the Arduino Nano uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
- An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Nano I²C is on A4 (SDA) and A5 (SCL).
Taking It Further on the Arduino Nano
Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Nano specifically:
The Nano’s DIP footprint makes it the natural choice once a breadboard prototype becomes a soldered build. Mount it on female headers rather than soldering it down, so the board can be recovered if the project is retired.
With A6 and A7 available in addition to A0–A5, the Nano can read two more analog sensors than an Uno. Remember that those two pins are analog-input only — they cannot be used with digitalWrite or as digital inputs.
For battery-powered builds, the Nano’s regulator and USB bridge dominate idle current. Powering the 5V pin directly from a regulated supply and removing the power LED substantially extends runtime.
Notes and Practical Limits
Always capture before you transmit. Point the original remote at a VS1838B receiver, record the protocol and value the library reports, then replay exactly that. This turns guesswork into a two-minute job.
The 5 V supply drives the emitter harder than a 3.3 V board would, which is why Arduino-based IR projects usually outrange ESP-based ones.