IRLib Tutorial part 1: Hardware set up

This is the first in series of articles on using my infrared remote library for Arduino. In this installment we’re going to show you how to set up the hardware and how to run a quick demo sketch. You can find out more about the library on my IRLib page.

In order to detect a single from IR remote control such as you might use for your TV or home entertainment system you need an IR receiver module. Typically I use a unit I get from Radio Shack. You can also buy a similar module from my favorite supplier Adafruit.com. See the links at the end of this post for places where you can buy all of the parts mentioned in this article.

Pin 1 (on the left as you looking at the lens) needs to be connected to a input pin of the Arduino. It can be any could be any pin that doesn’t conflict with anything else you’re doing with the device. All of the examples in the library assume you are connected to pin 11 so we suggest you use it. The center pin 2 connects to ground any right-hand pin 3 should connect to your +5V power supply. If you are using a different microcontroller that runs at +3V this device will work at that voltage.

The simplest output device is simply an infrared LED and a current limiting resistor. IR LEDs can be purchased from a variety of places. Again see the links at the bottom of this post for sources. You are limited to using PWM pins for output because we use the PWM feature to modulate the signal. The default pin to use on Arduino Uno or other ATmega328-based controllers is pin 3. This particular pin is connected to “timer 2” of the chip. However the Arduino Leonardo and other controllers based on the ATmega32u4 does not have a “timer 2”. On these devices the default is to use timer 1 and pin 9 for output. We will talk more later about other options for timers and how to use this library on other types of hardware. For now all you need to know is if you have an Uno you should use pin 3 or a Leonardo use pin 11. Connect a 100 ohm resistor in series with the LED. Make sure you get the polarity of the LED correct. The shorter of the two leads should connect to ground. The longer lead connects to the resistor which in turn connects to the Arduino. Here is a schematic for the simplest setup. Note this post was edited on 2/5/2014 to correct the polarity. After telling you to be sure to get it right, I had described it wrong. The schematic has always been correct but my description was wrong. Sorry about that.

Simple IR I/O Schematic

Simple IR I/O Schematic

That was the absolute simplest schematic however the output from the IR LED will be pretty weak because the output pins of Arduino cannot supply much current. You might want to consider adding an NPN transistor to drive the LED.

NPN Transistor Driving IR LED

NPN Transistor Driving IR LED

Here is a schematic using a PN2222 NPN transistor and a 470 ohm base resistor with the LED. WARNING: This circuit will drive the LED beyond its continuous current limits of 100 mA. However because we are only pulsing the LED for a brief period using a modulated signal we can get away with this. So you should only use the circuit if you are certain that the output pin is not going to be left on continuously for more than a fraction of a second.

Here is a simple sketch you can use to test if you are receiving IR signals. Is a stripped down version of the example sketch “IRrecvDump” that is in the examples subdirectory of the library.

/* Receiving IR signal and dump the details */
#include
//create a receiver object
IRrecv My_Receiver(11);//Use input pin 11

//create a decoder object
IRdecode My_Decoder;
void setup()
{
Serial.begin(9600);//We will read the output on the serial monitor
My_Receiver.enableIRIn(); // Start the receiver
}
void loop() {
//Loop until we get a signal and pass it to the decoder
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();//decode the signal
My_Decoder.DumpResults();//dump the results on the serial monitor
My_Receiver.resume(); //restart the receiver
}
}

Upload the sketch and start the serial monitor on the Arduino IDE. Point a remote control such as a TV remote at the receiver and press a button. It will dump the information about the signal received. If it’s a protocol with the library understands it will tell you which protocol and it will give you a hex number of up to 32 bits that is the code for that particular function.

To test your transmitter, first determine the 32 bit hex code and protocol that the library can decode. A good example would be the power off/on button of your device assuming that your protocol is supported. As an example I sent a power signal to my Sony DVD player. The dump program tells me that it is a 20 bit code that is Sony protocol and that the value is 0xa8bca. The following sketch is a version of the example “IRsendDemo” in the examples directory of the library.

/*Transmit a power code for Sony DVD*/
#include

IRsend My_Sender;
void setup()
{
Serial.begin(9600);
}
void loop() {
if (Serial.read() != -1) {
//send a code every time a character is
//received from the serial port
//Sony DVD power A8BCA
My_Sender.send(SONY,0xa8bca, 20);
}
}

You will need to substitute the protocol name, the hexadecimal code, and the number of bits for whatever device you are operating. After you upload the sketch type a character into the serial monitor and press enter. Every time you transmit a character from the serial monitor, it will transmit the code you have programmed into the “My_Sender.send(…)” Function call.

In the installments which follow we will explain more of the details of the library including a more advanced circuit for transmitting codes. However for now this should get you up and running.

As promised here are some links to the hardware mentioned in this post

In the next installment will show how to receive and decode IR signals and use them to do something useful such as control a servo.

Yet Another Show-and-Tell

Here the show-and-tell with Adafruit industries where I showed off a little circuit board I designed and some ray traced renderings of what the board will look like when it’s complete.

Adafruit Show-and-Tell sticker I earned for this presentation.

Adafruit Show-and-Tell sticker I earned for this presentation.

Assistive Technology at Both Ends of the Price Spectrum

Those of you who know me know that not only have I built a variety of gadgets both mechanical and electronic to help me deal with my disability, but that I also many years ago helped a friend of mine named Christopher Lee who had very severe cerebral palsy get access to a computer using software I wrote. With new inexpensive controllers like the Arduino and the new Raspberry Pi credit card size computer running Linux, the opportunities for making adaptive equipment for the disabled are going to go through a new resurgence not seen since the days in the late 70s early 80s when the only way to have a personal computer was to buy a bag of parts and fire them together yourself.

But an interesting phenomena is occurring. There seems to be a great disparity in the cost of these devices. On one hand we have the open source DIY maker community designing gadgets and giving away schematics and software for free. On the other hand we have people commercializing these projects and building businesses around them.

I’m all for people getting paid for their inventions even if the invention is designed with  altruistic motives such as helping the disabled, teaching underprivileged children,  or leveraging technology in undeveloped countries. I appreciate that some of these devices are in such small demand that the overhead to produce and sell them is great because they are built by hand and sold in small quantities. On the other hand some amazing work is being done in the DIY maker community that shares its designs and software for free and allows people to adapt it and further innovate it to meet their needs. It tends to make one wonder if the standard business model is really the best way to get products in the hands of people who need them.

Here are couple of examples… In previous installments of this blog I showed you how I showed off my IR remote control for my TV that was built with an Arduino microcontroller. My venue was Adafruit Industries weekly Show-and-Tell video chat via Google+ hangouts. This week’s hangout included a demonstration from a guy named Dino Tinitigan who had showed off some of his robotic projects in the past. But this time he showed a power wheelchair that can be controlled by tilting your head while wearing a helmet. Although he’s invested a lot of his own design work into it, it pretty much is built from off-the-shelf products the kind of which one could buy at Adafruit or other maker supply houses. He’s demonstrating that anyone with a little bit of maker ability and some time to spare can create incredibly useful technology. I don’t know if he is really creating this stuff as open-source hardware and software or if he intends to commercialize it but in either event he’s creating something and sharing it as a demonstration of what is capable and does not seem to be working out of a corporate model. Click here to see the Show-and-Tell video that demonstrates this.

At the opposite end of the spectrum is another device I stumbled onto today. It is called a Tecla device. Click here for details. It allows you to use pushbuttons or joystick or other adaptive devices to control touchscreen devices such as android and iOS phones and tablets. This is an amazing accomplishment even though it doesn’t allow 100% full access it does allow some use of such gadgets. It is Arduino-based so I understand the underlying technology. However it is only available as a commercial product and the cost is $289 Canadian. My initial reaction was Holy $#!+ That’s outrageous! On further review it probably is a reasonable price for a commercially built product with all of the capability it includes. It has a variety of interfaces that are designed to work with pushbuttons and input controls that meet an industry standard for adaptive devices. It includes the capability to use one’s wheelchair joystick as an input device. Given that it has to be designed to work with a wide variety of devices and it is a commercial enterprise I can understand the price. At the point when I can no longer use my iPod touch, I will probably be buying one of these at whatever price they want to charge for it. I’m sure the people behind it are decent people. They describe themselves as not just for profit. And I certainly have no trouble with doing well while doing good as it were. On the other hand… If I knew what I was doing I could build something similar for about $75 worth of parts.

There has to be a happy medium in here somewhere. Perhaps an open source design that demonstrates the basic functionality and would allow others to adapted as needed combined with a fully developed commercial product with all the bells and whistles for those who don’t have a friend who is a DIY maker aficionado to put it together for them.

Show and Tell Isn’t Just for Grade School

Adafruit Show-and-Tell sticker I earned for this presentation.

Adafruit Show-and-Tell sticker I earned for this presentation.

Either “Show-and-Tell” isn’t just for young gradeschool kids or people in the maker industry who like to tinker with electronic gadgets and computers are actually kids who never grew up. Each week the folks at Adafruit Industries host a video chat Google+ where gadget lovers and makers can show off the things they built with microcontrollers such as Arduino or small computers like a Raspberry Pi.

This week I took the opportunity to share my own creation which I call “A Remote Control Remote Control”. It’s a gadget I built so it’s easier for me to work a TV remote while I’m in bed. It’s based on the Arduino Uno microcontroller.

Typically during the live chat sessions participants hold up there gadgets and demonstrate them live on a WebCam but that wasn’t going to be practical for me so I decided to create a premade YouTube video to demonstrate my project. I then got on the WebCam live discuss it with the hosts.

Other projects included a educational prototyping board that a woman from Canada had created for her local school system. A guy who made a gag Christmas presents for a friend or relative. When you open the box and had blinking lights and the fish headed guy from Star Wars yelling “It’s a Trap!”. And what appeared to be about a 10 or 12-year-old kid who had an Arduino controller, the blinking LEDs, and a thermal text printer. I’m not really sure what it did but it was cool for a kid’s age. Another guy had a Arduino/Raspberry Pi controlled engraving machine that was pretty cool.

Here is the entire 30 minute online chat.

Here is the video that I showed at the beginning of the chat you want to see a better look at what I was doing then was available during the live presentation.

I will probably go back and share more of my projects including my IR remote control mouse and keyboard emulator. I’m also working on a remote that will replace the remote I use on my wheelchair. That will have to wait until after dad recovers from his pacemaker surgery. The chat is at 9:30 PM on Saturday nights and that won’t work with the guy I have coming in to put me to bed about that time.