Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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 Red Hat’s blueprint for building an open IoT platform—open source from cloud to gateways to devices.

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);

    irrecv.blink13(true);
    irrecv.enableIRIn();
}

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

        irrecv.resume();
        delay(100);
    }
}


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.

Build an open IoT platform with Red Hat—keep it flexible with open source software.

Topics:
ir ,iot ,arduino nano ,tutorial ,iot application

Published at DZone with permission of Gonzalo Ayuso, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}