gramo
New Member
**broken link removed**
I put together a guide on how to transmit data via IR, and thus far I have been able to get in excess of 20 meters with the project **broken link removed**
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 though 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 **broken link removed** 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;
**broken link removed**
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;
**broken link removed**
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 **broken link removed**.
**broken link removed**
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
**broken link removed**
Transmit Program:
Code:
Device = 18F2550
Clock = 8
Config FOSC = INTOSCIO_EC
Include "INTOSC8.bas"
Include "pwm.bas"
Include "IR_UART.bas"
Include "convert.bas"
Dim Variable As Byte
// start of main program
PWM.SetFreq(38000, 50)
IR_UART.SetTX(PORTC.2)
IR_UART.SetMode(umTrue)
IR_UART.SetBaudrate(sbr300)
Variable = 0
Low(PORTC.0)
While True
Inc(Variable)
IR_UART.Write(Variable)
DelayMS(500)
Wend
Receiver Program:
Code:
Device = 18F2550
Clock = 8
Config FOSC = INTOSCIO_EC
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.0
#option LCD_EN = PORTB.1
Include "INTOSC8.bas"
Include "pwm.bas"
Include "IR_UART.bas"
Include "convert.bas"
Include "lcd.bas"
Dim Variable As Byte
PWM.SetFreq(38000, 50)
IR_UART.SetRX(PORTC.2)
IR_UART.SetMode(umTrue)
IR_UART.SetBaudrate(sbr300)
DelayMS(150)
LCD.Cls
LCD.WriteAt(1,1,"IR UART")
While True
IR_UART.Read(Variable)
LCD.WriteAt(2,1,Convert.DecToStr(Variable,3))
Wend
All of the User Libraries can be download from the main guide here **broken link removed**
Last edited by a moderator: