Verified by our editorial teamDatasheet verified

Arduino Home automation

9 min readShare: XLinkedInRedditWhatsAppCopy link This project lets an Arduino press the buttons of a battery-powered radio remote control. Send a letter from your computer over USB, and the Arduino briefly “presses” the matching ON or OFF button, so remote-controlled sockets switch lights, heating or other equipment. Optocouplers keep the Arduino electrically separate from the […]

Avatar of Ibrar Ayyub
By Ibrar Ayyub
Published April 23, 2013
At a glance
CategoryHome Automation Projects
DifficultyIntermediate
IncludesCode, Diagrams, Datasheets
UpdatedNovember 24, 2026
Reading timeabout 9 min
On this page
9 min read

This project lets an Arduino press the buttons of a battery-powered radio remote control. Send a letter from your computer over USB, and the Arduino briefly “presses” the matching ON or OFF button, so remote-controlled sockets switch lights, heating or other equipment. Optocouplers keep the Arduino electrically separate from the remote, and LEDs show which channel is active. The same idea works with any simple remote whose buttons just connect two contacts.

HOW THIS PAGE WAS CHECKED

Datasheet verified by us. The Arduino pin current limits quoted here were checked against the ATmega328P datasheet (pages 308 and 323). The sketch was compiled for an Arduino Uno with the Arduino toolchain. The optocoupler and LED values are typical figures, so check them against the datasheet of the parts you buy.

IN SHORT
  • Each remote button gets one Arduino pin, a resistor, an LED and one optocoupler channel. Four channels (ON and OFF each) use pins 2 to 9.
  • Send H and the Arduino pulses pin 3 for one second: channel 1 ON. Send h and it pulses pin 2: channel 1 OFF.
  • The Arduino only touches the remote’s low-voltage button contacts. Never connect it to mains wiring.
  • Use about 220 Ω instead of 47 Ω in the LED branch. A 47 Ω resistor pushes the pin close to its 40 mA absolute maximum.
4 channels
ON and OFF each
8 pins
Arduino pins 2 to 9
1 second
length of each button press
40 mA
absolute maximum per Arduino pin

How it works

A battery remote has a row of buttons. Each button is a pair of contacts on the circuit board that the button’s rubber pad connects when you press it. The Arduino cannot be wired straight to those contacts without risking the remote’s electronics, so each button is replaced by the output side of an optocoupler: a small chip with an LED on one side and a light-sensitive transistor on the other. When the Arduino lights the LED, the transistor conducts and connects the two contacts, exactly as a finger would. Nothing electrical passes between the two sides, only light.

  1. The computer sends a letter over USB at 9600 baud.
  2. The sketch looks the letter up in a list and finds the pin for that button.
  3. The pin goes HIGH for one second. Current flows through the resistor, the indicator LED and the optocoupler LED.
  4. The optocoupler’s transistor connects the remote’s contacts for that second, the remote sends its radio code, and the socket switches.
Safety. Only the battery-powered remote is connected to this circuit. The sockets and lamps on the other side of the radio link run on mains. Do not open or modify the sockets, and do not connect the Arduino to any mains wiring.

What you need

Arduino Uno or similar board
Battery remote with 4 channels (ON/OFF buttons) and matching remote sockets
Dual optocouplers, 8-pin DIP (4 of them)
8 resistors, 220 Ω
8 indicator LEDs (optional but useful)
Stripboard or prototype board
Ribbon cable and header pins
Enclosure
Soldering iron, solder, cutters

The original build used a HomeEasy HE300 controller with HE302S remote sockets, and four RS 308-613 dual optocouplers. A dual optocoupler holds two channels in one 8-pin package, so one chip covers the ON and OFF buttons of one channel.

Wiring one channel

Arduino Pin 3 (ON)Pin 2 (OFF)GND 220 ΩLED220 ΩLED Dual optocoupler 1 (LED A +)2, 3 (LED cathodes)4 (LED B +) Remote, channel 1 Pin 8: ON trackPins 6 and 7: commonPin 5: OFF track Repeat for channels 2 to 4 on pins 5 and 4, 7 and 6, 9 and 8 (one more optocoupler each)

From To Why
Arduino pin 3 220 Ω resistor, LED, optocoupler pin 1 Presses the channel 1 ON button
Arduino pin 2 220 Ω resistor, LED, optocoupler pin 4 Presses the channel 1 OFF button
Optocoupler pins 2 and 3 Arduino GND (next to pin 13) Return path for both LEDs
Optocoupler pins 6 and 7 (joined) The common contact of the channel 1 buttons on the remote Shared side of both buttons
Optocoupler pin 8 The ON contact of the remote Output for the ON button
Optocoupler pin 5 The OFF contact of the remote Output for the OFF button
If a channel does not react, swap its two output wires. The optocoupler’s transistor conducts in one direction only. If the remote does not respond, reverse the two output wires for that button. A multimeter on the remote’s button contacts shows which side is more positive.

Why 220 ohms, not 47

In each branch the current passes through three things in a row: the resistor, the indicator LED (about 2 V for a red LED) and the optocoupler’s LED (about 1.2 V). With a 5 V pin and the typical drops, the current is (5 – 2 – 1.2) divided by the resistor:

Resistor Current per pin (typical) Against the ATmega328P limits
47 Ω about 38 mA Close to the 40 mA absolute maximum per pin, and above the 20 mA at which the datasheet guarantees the output voltage
220 Ω about 8 mA Well inside both limits, and enough to drive most optocouplers

The datasheet gives 40 mA as the absolute maximum DC current per I/O pin and 200 mA for the VCC and GND pins (datasheet p. 308). A pin is guaranteed to hold at least 4.2 V while supplying 20 mA at 5 V, and the sum of the source currents on each port group must stay under 150 mA (datasheet p. 323). Only one channel is pressed at a time in this sketch, so the totals are no problem. The current figures above are typical values; check the forward voltage and the required LED current in the datasheet of the optocoupler you buy.

Absolute maximum is not a design target. The 40 mA rating is a stress limit, not a working current. Staying at or below 20 mA per pin leaves a safe margin.

Building the board

  1. Solder the optocoupler sockets and resistors on stripboard, and a row of header pins that plugs into the Arduino’s digital headers. Cut the tracks between the two sides of each optocoupler.
  2. Solder the LED branches: pin, resistor, LED, optocoupler LED pin. Put the LEDs where you can see them through the enclosure.
  3. Join optocoupler pins 2 and 3 together and run them to GND.
  4. Join pins 6 and 7 of each optocoupler and connect them to the common contact of that channel on the remote’s circuit board. Connect pin 8 and pin 5 to the ON and OFF contacts.
  5. Before connecting the Arduino, check for short circuits between neighbouring tracks with a multimeter.

The sketch

The sketch keeps two parallel lists: the command letters and the pins. When a letter arrives, it finds its position, raises the matching pin for one second and lowers it again. Adding a fifth channel means adding two letters and two pins to the lists. The sketch compiles for an Arduino Uno to 2,142 bytes.

// duino4projects.com
// Serial commands press the buttons of a battery-powered remote through optocouplers.
// Capital letter = channel ON, small letter = channel OFF. Send one character per command.
//   H / h  channel 1 (heating)       pins: ON = 3, OFF = 2
//   S / s  channel 2 (security)      pins: ON = 5, OFF = 4
//   G / g  channel 3 (garden lights) pins: ON = 7, OFF = 6
//   L / l  channel 4 (lamp)          pins: ON = 9, OFF = 8
const unsigned long PULSE_MS = 1000;   // how long each "button press" lasts

const char commands[] = "HhSsGgLl";
const byte pins[]     = { 3, 2, 5, 4, 7, 6, 9, 8 };   // same order as the commands

void setup() {
  Serial.begin(9600);
  for (byte i = 0; i < sizeof(pins); i++) {
    pinMode(pins[i], OUTPUT);
    digitalWrite(pins[i], LOW);
  }
  Serial.println(F("Ready. H/h S/s G/g L/l"));
}

void loop() {
  if (Serial.available() > 0) {
    char c = Serial.read();
    for (byte i = 0; i < sizeof(commands) - 1; i++) {
      if (c == commands[i]) {
        digitalWrite(pins[i], HIGH);   // LED and optocoupler LED on: the remote "button" is pressed
        delay(PULSE_MS);
        digitalWrite(pins[i], LOW);    // released
        Serial.print(F("Sent "));
        Serial.println(c);
      }
    }
  }
}
Send Channel Pin pulsed Result
H / h 1 (heating) 3 / 2 ON / OFF
S / s 2 (security) 5 / 4 ON / OFF
G / g 3 (garden lights) 7 / 6 ON / OFF
L / l 4 (lamp) 9 / 8 ON / OFF

Open the Arduino serial monitor at 9600 baud, type H and press Send. The channel 1 ON LED lights for one second, the sketch prints “Sent H”, and the socket switches on.

Controlling it from your computer

Anything that can write a character to the serial port can drive the board: the serial monitor, a script on a schedule, or a program that reacts to the time of day or a light sensor. For example, a scheduled task that sends G at sunset and g at 23:00 switches the garden lights without you being there. To reach it from outside the house, use a VPN or a trusted remote-access tool for the computer, and do not expose the serial port or the computer directly to the internet.

When something does not work

Symptom Likely cause Fix
LED lights but the socket does not switch Output wires on the wrong polarity, or wrong contacts Swap the two output wires of that button. Check the contacts with a multimeter on the remote’s button.
Nothing happens when a letter is sent Wrong port or baud rate, or the letter is the wrong case Select the Uno’s port, set the monitor to 9600 and send a capital letter for ON, a small letter for OFF.
Remote works by hand but never from the Arduino Pulse too short or the remote needs a longer press Raise PULSE_MS in the sketch.
Arduino resets when a command is sent The serial monitor opened the port and reset the board Wait for the “Ready” message before sending the first command.
Socket switches on its own Neighbouring remote or another remote using the same code Re-pair the socket with the remote.

Project variants: Arduino home automation with remote control

Related projects: other ways to switch things at home

Quick answers

Can I use relays instead of optocouplers?
Yes, small signal relays can close the remote’s contacts too, but they need a transistor driver and a flyback diode and click on every press. Optocouplers are silent and need only the LED current.
Can I add more channels?
Yes. Add a command letter and a pin to each list in the sketch, and add one more optocoupler channel on the board.
Is this safe on mains?
The Arduino and the board never touch mains. They connect only to the low-voltage buttons of a battery remote, and the sockets do the mains switching. Do not open or modify the sockets.
Why does each press last one second?
Remotes send their radio code while the button is held. One second is long enough to be sure the code is sent, and short enough to feel immediate. Change PULSE_MS if your remote needs longer.
Can I read back whether the light is on?
No. A remote sends commands only, so the Arduino cannot tell the real state. Keep track of it in your own script, or add a sensor such as a light-dependent resistor at the lamp.

Check your own build

Test each channel in turn with the remote in your hand: press the real button once to see the socket respond, then send the same letter from the serial monitor and confirm the same result. Test ON and OFF for all four channels before you close the enclosure, and check the resistor values against the table above.

Project resources and downloads

Share this project
X
LinkedIn
Reddit
WhatsApp

Scroll to Top