Lugh
Published © GPL3+

Turn On/Off TV Sound System Using the TV IR Remote Control

How to control a PC sound system connected to a TV using the IR remote control power button, so both TV & sound system are on/off together.

BeginnerFull instructions provided1.5 hours8,835
Turn On/Off TV Sound System Using the TV IR Remote Control

Things used in this project

Hardware components

IR receiver (generic)
×1
Relay Module (Generic)
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Infrared controlled relay with Arduino Nano

Mounted on PCB kit

Side

Top

Back

Done !

Code

Control a relay using an IR receiver with an Arduino Nano

Arduino
#include <IRremote.h>
#include <IRremoteInt.h>
//#include <stdio.h>

#define RELAY_OUT 5
#define IR_RECV 3

// Default relay LOW
int level = LOW;

unsigned int timeout = 0;

// Declare IR objects
IRrecv irrecv(IR_RECV);
decode_results results;

void setup() {
 // Initialize digital pin 5 as an output for relay control
 pinMode(RELAY_OUT, OUTPUT);
 // Turn the relay off to start (switch off sound system)
 digitalWrite(RELAY_OUT, level);

 // Setup serial
 //Serial.begin(9600);

 // Enable IR receiver
 irrecv.enableIRIn();
}

// The main loop will continue to run until the arduino loses power
void loop() {

 // Read IR receiver
 if(irrecv.decode(&results))
 {

  //char value[25] = "";
  //sprintf(value, "Pressed button: %d\n", results.value);
  //Serial.println(value);
   
  // If IR output matches the POWER or RED buttons
  // values should be updated with the one of your remote control
  if(results.value == 50153655 || results.value == 50139885)
  {
   //Serial.print("New level is: ");
  
   // Switch relay on/off
   if(level == LOW)
   {
    level = HIGH;
   }
   else if(level == HIGH)
   {
    level = LOW;
   }
   
   //Serial.println(level);
   
   // Update relay level
   digitalWrite(RELAY_OUT, level);
   timeout = 0;
  }

  // Receive the next value
  irrecv.resume(); 
 }

 // Wait for 500ms before reading next value
 delay(500);
 
 timeout += 1;

 // Automatic shutdown after 4h
 if(timeout >= 28800)
 {
  timeout = 0;
  level = LOW;
  digitalWrite(RELAY_OUT, level);
 }
}

Credits

Lugh

Lugh

1 project • 0 followers

Comments