- Published: Saturday, 04 April 2009
- Written by Digital DIY
- Hits: 9697
Want to be able to transmit data effectively, reliably, and most importantly wirelessly? Well Infrared modulated UART could be the cheapest and most effective solution. This guide provides a great solution for remote control and wireless data communication, and while it only covers the fundamentals, the possibilities are up to you. With the circuits/products and programs listed below, I have been able to achieve over 20 meters of IR data communication.
This little example all came about when I wanted to make my own IR controlled applications, but the idea of a simple IR switch didn't really phase me, I wanted something that could transmit data back and forth. Taking a step sideways, I instantly thought about UART (a one wire serial protocol), and how it could be used with a concept like this.
Before I go much further, a quick burst on IR. Infrared has its flaws, the primary issue is line of sight, although the LED's I used proved to be extremely effective at dispersing IR (I could even transmit around corners). The other issue to consider - is the amount of Infrared found in ambient light from the sun. It is after all just another spectrum of light, one that can not be detected by the human eye. So how does one go about transferring data in a reliable manner that accommodates for ambient IR being present? Answer; modulation.
In this case, the modulated signal has a carrier of 38Khz, and turns on/off to encode the data. The result is bursts of 38Khz signals being transmitted. Building a reliable receiver would be a tough task, but why re-invent the wheel when there are Logic Output Infrared Sensors available to do the job for you. This device will remain a logic high until it detects a 38Khz signal, and then it will go low (0V) if a signal is present;
The next task is to somehow turn UART data signals into 38Khz modulated IR... Why don't we utilise the onboard Pulse Width Modulation built into almost every PIC? If you setup the PWM output for 38Khz and 50% Duty Cycle, then the next objective is to somehow turn it on/off at the same time a UART output is normally on/off. I can think of two methods, one is to use a Logic AND gate, placing the PWM signal on one input, and the UART TX on the other - the result would be Modulated UART with a 38Khz carrier. But you can do this without the requirement of external components by controlling the Tristate status (input/output) of the PWM Pin. By making the PWM pin an input, you are turning off the 38Khz signal, and of course enabling it again when returned to an output. Here's what a snippet of a modulated signal would look like;
Creating infrared light is simple, there are many types of LED's available to do the job. Make sure though, for best performance, that the Infrared LED's wavelength matches the receiver for optimal performance. To get the best range, also use a high quality and powered IR LED.
The Infrared LED can utilise much more current then the PIC can output, and there are a variety of methods to drive such devices. I prefer to use the ULN2003 or Logic Level MOSFET's for jobs like this. Note that the output of the PWM is tied down to earth with a 100K resistor. This is used to instantly shunt any residual voltage to earth when the pin is made an input - not so much required with the ULN2003, but is vital with MOSFET's. The 25ohm resistor in series with the LED was calculated by R = V/I where V = 5 (supply) - 1.6 (Vf of the LED) - 0.9 (Vf of the ULN2003) and I = 0.1 (If of the LED).
Therefore R = (5 - 1.6 - 0.9) / 0.1 = 25 ohm or greater
The module I modified can be downloaded at the bottom of this article. Now you can send/receive data just as if it were a normal UART connection, here's an example program:
Download the module: INTOSC8
Download the module: IR_UART
Download the module: PWM