![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
![]() 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 Spencys digital-diy 18F PIC micro - Infrared IR Modulated UART 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 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 ![]() 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
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
__________________
Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net Last edited by Nigel Goodwin; 8th June 2008 at 04:35 PM. |
|
|
|
|
|
|
(permalink) |
|
Spency,
Another very clever and creative demo'. Bravo! Have you experimented with baud rates and determined that 300 baud is the most effective for the performance and distances you're getting? Also, are you using the PWM module in the receiver code? Your demo has me very excited about potentially using a little 8 pin 12F683 device with it's built-in 8 MHz oscillator and PWM module. Mike Last edited by Mike, K8LH; 8th June 2008 at 02:53 PM. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
You could go faster, so long as there are at least 6 cycles of the 38Khz signal for each bit being transmitted. I have been getting the best long range results with slower frequencies though A couple of changes to the code have been made (I left the PWM settings in the receiver and can't edit them out now, damn 15 minute edit time frame), none the less its all updated on the site.
__________________
Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net |
||
|
|
|
|
|
(permalink) |
|
Spency,
Well 300 baud seems like a very impressive rate (to me) for those distances. And that receive code minus the PWM stuff makes more sense to me now. Thanks... Regards, Mike Last edited by Mike, K8LH; 8th June 2008 at 04:13 PM. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| infrared remote control help? / | ujjvalshah | Electronic Projects Design/Ideas/Reviews | 9 | 15th July 2007 04:40 PM |
| Problem in applying configuration data to UART | tkvenki | Micro Controllers | 0 | 22nd March 2007 10:58 AM |
| sending data via infrared | jijita | General Electronics Chat | 3 | 18th June 2004 02:36 PM |
| Infrared Remote control | kizzap | General Electronics Chat | 9 | 27th April 2004 09:13 AM |
| receive 0 data from UART..... | wingbar | General Electronics Chat | 5 | 15th March 2004 06:11 PM |