Circuits and Ideas Electronics Tutorials

Control PC or Laptop Like a TV PC remote Universal

Written by admin

Remote control of PC is nice when it’s plug and play. This tutorial describes a DIY method to control the PC remotely with minimum components and under 2 dollars. And MORE IMPORTANTLY its PLUG AND PLAY Device, so you don’t need any third party software to convert the IR signals to commands. The receiver itself will work as a Keyboard when plugged into the PC. Moreover it will work with any IR remote.

Components Required:

  1. Arduino UNO
  2. Digispark ATtiny85
  3. IR Receiver (TSOP 1738)
  4. Arduino IDE (software for programming)
  5. Some Time

Step 1:

 

The TSOP receiver has terminals VCC, GND and Output and they are as shown in image below. Connect it to the Arduino UNO board as

TSOP Output  —->   pin 2 on Arduino UNO
TSOP GND      —->   pin 3 on Arduino UNO
TSOP VCC       —->   pin 4 on Arduino UNO

Step 2:

 

  • Connect the Arduino Board to PC and program it with the Following Code
Program for Receiving the IR codes from the IR Remote
uint8_t situation = 0; // 3 > 1 or 0 received | 2 > Repeat previous code
uint8_t START = 0; // Detect if the transmission is started
uint8_t x = 0;
uint8_t BIT = 0; // Which bit is send (1/0)
uint8_t Id = 0; // What’s the remote ID
uint8_t Id_inv = 0;
uint8_t Data = 0; // Which key is pressed on the remote
uint8_t Data_back = 0; // Backup of the key for repeat
uint8_t Data_inv = 0;
uint8_t Repeat = 0; // pass first repeat

/* Variables for the pulse measurement */
uint16_t Time_old = 0;
uint16_t Time = 0;
uint16_t TimeDelta = 0;

/* Data received from the computer */
/* 1 > Caps lock changed */
/* 2 > Num lock changed */
/* 3 > Scroll lock changed */
uint8_t incomingByte = 0;

/* LED pins */
#define caps 24
#define numl 22
#define scrl 23

/*************************************
* This code is written by Your Tech Bhai
* For questions: youtube.com/yourtechbhai
* Website : www.yourtechbhai.com
*
* Microcontroller: Atmega 328
* Dev board: Arduino UNO
*
*************************************/
void setup(void) {
/* Interrupt for reading the IR code */
attachInterrupt(0, IR_Read, FALLING);

/* Serial connection to the computer software */
Serial.begin(9600);

/* Led pins as output */
pinMode(caps, OUTPUT);
pinMode(numl, OUTPUT);
pinMode(scrl, OUTPUT);
/* Led’s out */
digitalWrite(caps, LOW);
digitalWrite(numl, LOW);
digitalWrite(scrl, LOW);
/*ground and VCC for IR Receiver */
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
}

void loop(void) {
/* If something from the computer is received */
if (Serial.available() > 0) {

/* Read the incomming data */
incomingByte = Serial.read();
switch(incomingByte){
case 1: /* If 1 */
/* Caps Lock led on/off > off/on */
digitalWrite(caps, !digitalRead(caps));
break;
case 2: /* If 2 */
/* Num Lock led on/off > off/on */
digitalWrite(numl, !digitalRead(numl));
break;
case 3: /* If 3 */
/* Scroll Lock led on/off > off/on */
digitalWrite(scrl, !digitalRead(scrl));
break;
default:
break;
}
}
}

/* Function for reading the IR receiver using interrupts */
/* YOU DON’T NEED TO CHANGE ANYTHING HERE */
void IR_Read(void) {
Time = micros();
if (Time_old != 0) {
TimeDelta = Time – Time_old;
if ((TimeDelta > 12000)&&(TimeDelta < 14000)) {
START = 1;
x = 0;
situation = 1;
Id = 0;
Id_inv = 0;
Data = 0;
Data_inv = 0;
} else if ((TimeDelta > 10000)&&(TimeDelta < 12000)) {
situation = 2; // repeat
} else if ((TimeDelta > 1500)&&(TimeDelta < 2500)) {
situation = 3; //”1″
BIT = 1;
} else if ((TimeDelta > 1000)&&(TimeDelta < 1500)) {
situation = 3; //”0″
BIT = 0;
} else situation = 5;
if (situation == 3) {
if (x < 8) {
Id |= BIT;
if (x < 7) Id <<= 1;
x++;
} else if (x < 16) {
Id_inv |= BIT;
if (x < 15) Id_inv <<= 1;
x++;
} else if (x < 24) {
Data |= BIT;
if (x < 23) Data <<= 1;
x++;
} else if (x < 32) {
Data_inv |= BIT;
if (x < 31) {
Data_inv <<= 1;
} else {
Serial.println(Data);
Data_back = Data;
Repeat = 0;
}
x++;
}
} else if (situation == 2) {
if(Repeat == 1) {
/* Send received data to the computer */
Serial.println(Data_back);
} else {
Repeat = 1;
}
}
}
Time_old = Time;
}

Step 3:

 

  • Open the serial monitor in Arduino IDE. Press all the buttons on the IR remote one by one and you will see the codes appearing in the serial monitor window.
    Remember to press it only once.
  • Copy all the codes you have received into an Excel file and assign the name of the buttons to the codes for the reference purpose only. You will need it later.

Step 4:

 

  • Install the Trinket HID combo Library from this LINK in the Arduino IDE.
  • Change the Codes in the following program with the ones you have received.
  • Program the ATtiny 85 with the program.
Program for ATtiny Receiver
/**** Define Remote control keys ****/
#define Power 72
#define mode 88
#define mute 120
#define playpause 128
#define prev 64
#define next 192
#define eq 32
#define vol_down 160
#define vol_up 96
#define key_0 224
#define rpt 16
#define usd 144
#define key_1 80
#define key_2 216
#define key_3 248
#define key_4 48
#define key_5 176
#define key_6 112
#define key_7 0
#define key_8 240
#define key_9 152
/************************************/

#include “TrinketHidCombo.h”

uint8_t situation = 0;
uint8_t START = 0;
uint8_t x = 0;
uint8_t BIT = 0;
uint8_t Id = 0;
uint8_t Id_inv = 0;
uint8_t Data = 0;
uint8_t Data_back = 0;
uint8_t Data_inv = 0;
uint8_t Repeat = 0;
uint8_t sended = 0;

uint16_t Time_old = 0;
uint16_t Time = 0;
uint16_t TimeDelta = 0;

void setup(void) {
/* Use INT0(P2) on the Digispark */
attachInterrupt(0, IR_Read, FALLING);

pinMode(1,OUTPUT);
digitalWrite(1,LOW);

TrinketHidCombo.begin();
}
/*************************************
* This code is written by Your Tech Bhai
* For questions: youtube.com/yourtechbhai
* Website : www.yourtechbhai.com
*
* Microcontroller: ATtiny85
* Dev board: Digispark
*
*************************************/
void loop(void) {
if(sended == 1) {
/* Assign functions to the buttons */
if(Data_back == vol_up) {
TrinketHidCombo.pressMultimediaKey(MMKEY_VOL_UP);
} else if(Data_back == vol_down) {
TrinketHidCombo.pressMultimediaKey(MMKEY_VOL_DOWN);
} else if(Data_back == next) {
TrinketHidCombo.pressMultimediaKey(MMKEY_SCAN_NEXT_TRACK);
} else if(Data_back == prev) {
TrinketHidCombo.pressMultimediaKey(MMKEY_SCAN_PREV_TRACK);
} else if(Data_back == mute) {
TrinketHidCombo.pressMultimediaKey(MMKEY_MUTE);
} else if(Data_back == Power) {
TrinketHidCombo.pressSystemCtrlKey(SYSCTRLKEY_POWER);
} else if(Data_back == key_0) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_0);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_1) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_1);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_2) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_2);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_3) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_3);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_4) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_4);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_5) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_5);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_6) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_6);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_7) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_7);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_8) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_8);
TrinketHidCombo.pressKey(0, 0);
} else if(Data_back == key_9) {
TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_9);
TrinketHidCombo.pressKey(0, 0);
}
sended = 0;
} else {
TrinketHidCombo.poll();
}
}

/* Read the IR code */
void IR_Read(void) {
digitalWrite(1,HIGH);
Time = micros();
if (Time_old != 0) {
TimeDelta = Time – Time_old;
if ((TimeDelta > 12000)&&(TimeDelta < 14000)) {
START = 1;
x = 0;
situation = 1;
Id = 0;
Id_inv = 0;
Data = 0;
Data_inv = 0;
} else if ((TimeDelta > 10000)&&(TimeDelta < 12000)) {
situation = 2; // repeat
} else if ((TimeDelta > 1500)&&(TimeDelta < 2500)) {
situation = 3; //”1″
BIT = 1;
} else if ((TimeDelta > 1000)&&(TimeDelta < 1500)) {
situation = 3; //”0″
BIT = 0;
} else situation = 5;
if (situation == 3) {
if (x < 8) {
Id |= BIT;
if (x < 7) Id <<= 1;
x++;
} else if (x < 16) {
Id_inv |= BIT;
if (x < 15) Id_inv <<= 1;
x++;
} else if (x < 24) {
Data |= BIT;
if (x < 23) Data <<= 1;
x++;
} else if (x < 32) {
Data_inv |= BIT;
if (x < 31) {
Data_inv <<= 1;
} else {

/* DO SOMETHING HERE */
sended = 1;

Data_back = Data;
Repeat = 0;
}
x++;
}
} else if (situation == 2) {
if(Repeat == 1) {

/* DO SOMETHING HERE */
sended = 1;

} else {
Repeat = 1;
}
}
}
Time_old = Time;
digitalWrite(1,LOW);
}

Step 5:

 

  • Connect the TSOP receiver to the ATtiny85 as follows.

TSOP Output  —->   pin P2 on ATtiny Board
TSOP GND      —->   pin Gnd on ATtiny Board
TSOP VCC       —->   pin +5v ATtiny Board

  • Connect it to the PC and you are all good to go.

You can also check the video tutorial below.

Comments

comments

About the author

admin

11 Comments

  • Pretty great post. I just stumbled upon your blog and wanted to mention that I’ve really loved browsing your blog posts. After all I will be subscribing in your feed and I’m hoping you write once more soon!

Leave a Comment