As an Amazon Associate we earn from qualifying purchases.
Most homes already have a TV remote sitting on the sofa. With a few cheap parts and an Arduino, that same remote can switch a light or a fan on and off. You do not need a special remote or a smart home hub, because the remote you already own sends infrared signals that a small receiver can read.
The video below shows a working version of this project. It uses an ATmega328 (Arduino), a relay and a TSOP infrared receiver, among other parts. This article explains how the idea works, what you need and how to build it safely.
How a TV remote can control a light and fan
A TV remote has an infrared LED inside. When you press a button, it blinks out a pattern of pulses that is unique to that button. The pattern is usually sent on a carrier of about 38 kHz, which helps the receiver ignore ordinary room light.
A TSOP-type infrared receiver picks up those pulses and passes a clean digital signal to the Arduino. The Arduino decodes the signal into a number, compares it with the codes you have stored, and then switches a relay on or off. The relay is what actually turns the light or fan on, since an Arduino pin cannot power mains appliances directly.
In short, the chain looks like this:
- You press a button on the remote.
- The TSOP receiver detects the infrared pulses.
- The Arduino decodes the button code.
- The Arduino sets a pin high or low.
- A relay module switches the light or fan.
Parts you need
- Arduino board with an ATmega328 chip (an Uno or Nano works well).
- TSOP infrared receiver (for example a 38 kHz type) to read the remote.
- Relay module with at least two channels, one for the light and one for the fan.
- Any TV remote that you do not mind using. An old or spare one is ideal.
- Jumper wires and a breadboard for testing.
- 5 V power supply for the Arduino and relay module.
- Enclosure, terminal blocks and proper mains-rated wire for the final installation.
Step-by-step build
1. Connect the infrared receiver
A TSOP receiver has three pins: output, ground and supply. Connect the supply pin to 5 V, ground to ground, and the output pin to a digital input pin on the Arduino. Check the datasheet for your exact part, because the pin order differs between models.
2. Read the button codes from your remote
Install an infrared library for Arduino, such as IRremote, and load a simple example sketch that prints received codes to the Serial Monitor. Point your remote at the receiver and press the buttons you want to use. Write down the code for each one.
Pick buttons that are easy to remember, such as number keys 1 and 2, or the red and green buttons. Different remotes send different codes, so you must read the codes from your own remote rather than copy them from someone else.
3. Wire the relay module
Connect the relay module’s supply and ground to the Arduino, then connect each input pin to a free digital output pin. Many relay modules switch on when the input is pulled low, while others switch on when it is high. Test this on the bench with nothing connected to the relay’s mains side.
4. Write the control logic
The program is simple. It waits for a code, checks which stored code it matches, and flips the state of the matching relay. This turns each button into a toggle: press once for on, press again for off.
- Code 1 toggles the light relay.
- Code 2 toggles the fan relay.
- Any other code is ignored.
Many remotes send a repeat signal while a button is held. Add a short delay or ignore repeat codes so the relay does not flicker on and off when you press for a moment too long.
5. Connect the light and fan
Only do this step once everything else works on the bench. The relay acts as a switch on the live wire of each appliance. The neutral wire does not go through the relay. If you are not comfortable working with mains wiring, ask a qualified electrician to do this part.
Safety tips for mains wiring
- Disconnect the power before touching any wiring.
- Use a relay module rated for the voltage and current of your appliance.
- Keep the low-voltage Arduino side and the mains side physically separated.
- Place the circuit in a closed, insulated enclosure so no live terminals are exposed.
- Use correctly sized wire and secure terminal connections, and add a fuse on the supply line.
- Test first with a low-power bulb before connecting a fan.
Troubleshooting common problems
The Arduino does not respond to the remote
Check the receiver wiring first, since swapped pins are the most common cause. Then confirm that your remote works by pointing it at a phone camera. Many phone cameras show the infrared LED as a faint flash when you press a button.
The relay clicks but the appliance does not switch
Check that the live wire runs through the relay’s common and normally open terminals. Also confirm that the relay is rated for your load.
The relay triggers by itself
Electrical noise or a weak power supply can cause random switching. Use a stable 5 V supply, keep wires short and add a small capacitor near the receiver’s supply pins.
Ways to extend the project
Once the basic setup works, there are several upgrades you can try. You can add more relays for other appliances, use a display to show the current state, or store the on and off states so they survive a power cut.
On/off switching is only the start. If you want real speed control, you will need a different approach, such as triac-based fan speed control or a similar method for fan speed control with Arduino. Those methods adjust how much power the fan receives instead of just cutting it.
You can also move beyond infrared. A Wi-Fi version lets you use a phone from anywhere in the house, as shown in our Wi-Fi controlled fan and light project. For a short-range radio alternative, see our Arduino wireless remote control project. If you want to see this idea applied to other appliances, our post on device control using a TV remote covers it.
Frequently asked questions
Can I use any TV remote for this project?
In most cases, yes. Any remote that sends infrared signals can work, but each one uses its own codes. You need to read the codes from your remote with a test sketch and use those in your program.
Will pressing buttons also change my TV channel?
It can. If you use the same remote you use for your TV, buttons like channel or volume will affect the TV too. Choose buttons that your TV ignores, or use a spare remote from a different device.
Does the remote need a clear line of sight?
Infrared needs a fairly direct path to the receiver, though reflections off walls can help. Mounting the receiver where you normally point the remote gives the most reliable results.
Is it safe to control a fan or light with an Arduino?
It is safe when done properly. Use a relay module rated for your load, keep mains wiring enclosed and insulated, and do not touch live parts while powered. If you are unsure, get help from a qualified electrician.