Over a million developers have joined DZone.

Controlling Your Bedside Lamp With a TV Remote

DZone's Guide to

Controlling Your Bedside Lamp With a TV Remote

Want to squeeze some more use out of your TV remote? With a board and an IR receiver, you can make it turn your lamp on and off.

· IoT Zone ·
Free Resource

Download The Comparative Guide to Rules Engines for IoT to learn what are the most common automation technologies used in the IoT domain for application development

I recently got a new Arduino board (the Arduino Nano) and I wanted to hack a little bit. Today, I'm going to play with an IR receiver. My idea is to use my TV’s remote and switch on/off one bedside lamp, using one relay. It’s a simple Arduino program. First, we need to include the IRremote library.

#include <IRremote.h>

#define IR 11
#define RELAY 9

IRrecv irrecv(IR);
IRsend irsender;
decode_results results;

unsigned long code;

void setup() {
    pinMode(RELAY, OUTPUT);
    digitalWrite(RELAY, LOW);


void loop() {
    if (irrecv.decode( & results)) {
        unsigned long current = results.value;
        if (current != code) {
            code = current;
            switch (code) {
            case 3772833823:
                digitalWrite(RELAY, HIGH);
            case 3772829743:
                digitalWrite(RELAY, LOW);


Normally, IR receivers have three pins: Vcc (5V), Gnd, and signal. We only need to connect the IR receiver to our Arduino and see which hex codes use our TV’s remote. Then we only need to fire our relay depending on the code.

The circuit:

The hardware:

  • 1 Arduino Nano
  • 1 IR receiver
  • 1 Relay
  • 1 Red led
  • a couple of pull down resistors

The source code is available on my GitHub.

See how CEP engines, stream processing engines, flow based programming engines and other popular rule-based technologies perform against seven IoT-specific criteria.

ir ,iot ,arduino nano ,tutorial ,iot application

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}