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() {

void loop() {
	long timer = micros() - time;
		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

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

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

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

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

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

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
		digitalWrite(IRLEDPIN, LOW); //takes ~ 5uSec
		microsecs -= 26;

Remote Weather Station Installation

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.

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.

Ultrasonic Anemometer Part 1 – Math Concepts


With the first stage of the weather station project nearing completion I’ve decided to explore building some additional sensors to collect more readings. One of the things that I’ve been very interested in measuring is wind speed and direction. A device that measures wind speed is called an anemometer. Wind direction is usually measured with a wind vane.

There are a few problems with traditional designs of these instruments, especially with anemometers. One of the biggest problems is that they usually have a minimum wind speed threshold. If the wind is below this threshold the device will not be able to measure it. This is usually because the wind is not strong enough to spin a propeller of some kind. To overcome the problem of low speed wind measurements I’ve decided to go with a solid-state (no moving parts) alternative. This alternative involves measuring the difference in <a href="https://en have a peek at this web-site.wikipedia.org/wiki/Time_of_flight” target=”_blank”>time-of-flight (TOF) of a sound wave across a known distance.

The overall approach to measuring the wind speed using this method will be:

  1. Create a pulse of sound at point A
  2. Measure the time it takes to arrive at point B
  3. Create a pulse of sound at point B
  4. Measure the time it takes to arrive at point A
  5. Use the difference in the two times to determine wind speed

This method will determine the wind speed in along one axis. In order to get wind direction you must measure the wind speed along another axis, then use trigonometry to calculate overall speed and direction. To make these calculation easy we will measure the wind speed in the North-South direction and the East-West direction. In doing so the equation for overall speed is

Total Speed = SquareRoot(VNS2 + VEW2

where VNS is the wind speed in the North-South direction and VEW is the speed in the East-West direction. The formula is a direct application of the Pythagorean theorem. The equation for overall direction is

Angle = tan-1(VNS/VEW)

where tan-1 is the inverse tangent function. These equations are relatively simple because of the fact that we intend to make our wind speed measurements exactly 90 degrees apart. It would still be possible to calculate wind speed and angle if we had chosen another angel, but the math would not be as simple as this.

Now that the theory is out of the way, we will begin to actually implement this method in part 2 using some cool electronics and sensors.

OSHPark.com PCB Fabrication

OSHPark Purple PCBs

It wasn’t until the last few years that ordering small-batch printed circuit boards became so affordable for the average low-budget hobbyist. Over the last few years several US and Chinese companies have sprung up that cater to the small quantity of circuit boards that a hobbyist usually needs for their projects.

One of these companies is OSH Park. OSH stands for “Open Source Hardware”. OSH Park is based in Portland, OR where members of the local maker/hobbyist scene founded Dorkbot PDX, which grew into a PCB service, and eventually OSH Park.

The nice things about OSH Park is that they have no setup cost. You pay a flat $5.00/sq in. for your circuit boards. They send you three copies of the finished product with free shipping about two weeks after you submit the order. The result is a nice quality purple PCB, with gold plated pads.

I’ve been using them both at work for cheap prototyping, and at home for my own personal projects. This particular board is part of a weather station kit that I’m working on. More info will follow when it’s closer to being complete.

Calibrating Test Equipment

<img class="wp-image-148" src="http://n1qq.com/wordpress/wp-content/uploads/2015/10/simpson_260-3a_02-300×154.jpg" alt="Simpson 260 Multimeter" width="351" height="180" srcset="http://n1qq.com/wordpress/wp-content/uploads/2015/10/simpson_260-3a_02-300×154.jpg 300w, http://n1qq.com/wordpress/wp-content/uploads/2015/10/simpson_260-3a_02-720×369.jpg 720w, http://n1qq.com/wordpress/wp-content/uploads/2015/10/simpson_260-3a_02-224×115 generic lexapro.jpg 224w, http://n1qq.com/wordpress/wp-content/uploads/2015/10/simpson_260-3a_02.jpg 741w” sizes=”(max-width: 351px) 100vw, 351px” />
Simpson 260 – A classic multimeter

For the average hobbyist equipment calibration is not something that would be of any great importance. However, if you do commercial electronics it is usually a requirement that you have your test equipment professionally calibrated. This usually means your multimeter and other test and measurement equipment needs to be sent to a calibration facility on a regular basis. Usually once a year, give or take.

Different types of projects will demand different levels of calibration. However, this is an interesting topic. In my work experience I have often seen requirements that calibrated equipment be used for testing devices. However, tolerance is not always given in these requirements. A person could use a meter calibrated to within 50% and (I suppose) would meet the requirement, even though 50% is a laughable tolerance.

Costs will vary depending on the equipment being calibrated, level of precision, and turnaround time needed. For a simple multimeter (volt-ohm-amp) expect to pay around $50 for a simple calibration.

My usual experience with having calibration done on equipment involves sending a meter to a calibration lab. They usually send it back with a new sticker on it, but don’t make any adjustments. This is because modern meters are remarkably stable. Almost always the meters are still well within tolerance levels when I send them off for calibration, so they do not require any adjustment.

In the end the average ham radio operator, or amateur electronics hobbyist will not likely have a need to spend the money to have their equipment calibrated. However, it is not prohibitively expensive, and there is certainly value in knowing that your test equipment is giving accurate measurements.