38kHz TV Remote Hacking

Arduino nano with a VS1838 IR reciever, and a IR LED.
Arduino nano with a VS1838 IR reciever, and a IR LED.
Arduino Nano

Most remotes used by TVs, DVD Players, and other consumer electronics use infrared light to send commands from the remote to the device being controlled. This is done because of the low cost and simplicity that infrared-based remotes offer.

The technology behind these remotes is simple. The transmitter consists of an infrared LED that is modulated at 38kHz. The LED is activated for varying amounts of time to send the information required to control the device.

An Arduino can be used to implement an effective remote control system. The following code was compiled on an Arduino. It performs the following functions:

  • Receive and decode standard remote-control commands
  • Print decoded commands over the serial port
  • Retransmitt the decoded commands using an infrared LED

The basic result is a infrared remote repeater. It will emulate any remote it can successfully detect by sending the received commands back out via the infrared LED.

Parts List:
  • VS1838B 38khz Reciever (From Ebay)
  • 940nm Infrared Led (From Ebay)
  • Arduino Nano Clone (From Ebay)
Arduino Code:
#define IRRX_GND 3
#define IRRX_PWR 4
#define IRRX_OUT 2
#define IRLEDPIN A3

byte bosePwr[4]   = {0xBA, 0xA0, 0x4c, 0xb3};
long time;
byte counter;
bool flag;
byte message[4];

void setup() {
	attachInterrupt(0,interrupt,CHANGE);
	pinMode(IRRX_GND,OUTPUT);
	pinMode(IRRX_PWR,OUTPUT);
	pinMode(IRLEDPIN,OUTPUT);
	digitalWrite(IRRX_GND,LOW);
	digitalWrite(IRRX_PWR,HIGH);
	Serial.begin(9600);
	Serial.println("Ready");
}

void loop() {
	long timer = micros() - time;
	if(flag){
		flag = 0;
		if(timer > 1400 && timer < 2000){ //Logic 1 addBit(1); }else if(timer > 450 && timer < 650){ //Logic 0 addBit(0); }else if(timer > 4000 && timer < 5000){ //START clearBits(); }else if(timer > 2000 && timer < 2500){ //REPEAT sendRpt(); clearBits(); } } if(counter >= 32){ //Recieve 32 or more bits successfully
		printBits();
		delay(50);
		sendCommand(message);
		clearBits();
	}

	if(timer > 10000 && counter > 0 && counter < 32){ //10ms Timeout
		Serial.println("Incomplete code");
		clearBits();
	}
}

void addBit(byte data){
	byte block = counter / 8;
	byte spot = counter % 8;
	byte mask = data << spot;
	message[block] |= mask;
	counter++;
}

void clearBits(){
	counter = 0;
	for(int i = 0; i < 4; i++){
		message[i] = 0;
	}
}

void printBits(){
	for(int i = 0; i < 4; i++){ byte low = message[i] & B00001111; byte high = (message[i] & B11110000) >> 4;
		Serial.print(high,HEX);
		Serial.print(low,HEX);
		Serial.print(" ");
	}
	Serial.println();
}

void interrupt(){
	if(!digitalRead(IRRX_OUT)) flag = 1;
	else time = micros();
}

void sendCommand(byte command[]) {
	sendHeader();
	for(int i = 0; i < 4; i++){
		sendByte(command[i]);
	}
	sendFooter();
}

void sendByte(byte data){
	byte mask = B00000001;
	for(int j = 0; j < 8; j++){
		if(mask & data) send1();
		else send0();
		mask <<= 1; } } void send1(){ send38KHz(560); delayMicroseconds(1690); } void send0(){ send38KHz(560); delayMicroseconds(560); } void sendHeader(){ send38KHz(9000); delayMicroseconds(4500); } void sendFooter(){ send38KHz(560); } void sendRpt(){ send38KHz(9000); delayMicroseconds(2250); send38KHz(2250); } void send38KHz(long microsecs) { while (microsecs > 0) {
		// 38 kHz -> 26 uSec (Duty cycle = 1/3)
		digitalWrite(IRLEDPIN, HIGH); //takes ~ 5uSec
		delayMicroseconds(6);
		digitalWrite(IRLEDPIN, LOW); //takes ~ 5uSec
		delayMicroseconds(10);
		microsecs -= 26;
	}
}

Remote Weather Station Installation

IMG_0292
QI2C485 in enclosure

Over the Thanksgiving holiday I was on vacation with family in Spokane where I installed an improved remote weather station. This entire operation is mainly a learning experience, but at the same time offers significant insight into the trends and patterns in the weather. The objectives of this mission were to design and build a weather station that offered accurate and precise weather reporting, in an package that could be deployed without too much difficulty at multiple locations around the world.

The foundation of the system is the processor board I recently finished: the QI2C485. I’ve been working on this board for a few months and after about 5 different revisions, I’ve finally completed the development of this board. The system was installed in Spokane. Following a few rounds of firmware adjustments and tweaks it has been successfully collecting data for a few days now.

Modularity was always on my mind when making this device. The main processor board (QI2C485) provides a lot of flexibility in this sense. It is essentially a RS485-I2C bridge, that has 2 I2C ports and 2 RS-485 ports. The RS-485 ports allow the board to be mounted a significant distance from any artificial heat sources, or other things that might affect weather readings. The I2C ports allow multiple sensor boards to be connected. Currently, a BME280 is connected to one of the I2C ports and is programmed to make temperature, pressure, and humidity readings every 15 minutes.

IMG_0294
Stevenson Screen

In the future, a combination brightness sensor and thermopile will be installed in the second port to make sky observations used to determine cloud conditions. Also in the works are wind speed, and rainfall sensors. The modularity of the process board will allow for easy addition of these sensors in the future, requiring only firmware modifications. The second RS-485 port on this board is designed to either terminate the RS-485 line, or allow it to pass through to other QI2C485 boards.

The QI2C485 host also includes a lightning detection circuit that will count electromagnetic pulses in the vicinity. All of this information is uploaded via a php script to an SQL database where it is currently stored for access later. It can be displayed via a php page on my website that is currently under development.

The future will likely hold an additional revision, and added modularity, but for now the current design will undergo a full test for the remainder of the cold Eastern Washington winter.