This article explains how to create a wireless infrared transmitter using an IR LED and a wireless IR receiver using a phototransistor to make a communication system. Asynchronous serial is transmitted over this link at 9600 BPS. Two PIC 18F452's are used to transmit and receive the data.
One of the earliest methods of wireless transmission used was with infrared light. Using wireless IR links has many advantages with the primary two being low cost and low part count to implement. The simplest of on/off switches using wireless IR would take no more than 10 parts, but this Project will be going to send asynchronous serial data over a wireless IR link.
This Project will create a wireless infrared transmitter using an IR LED and a wireless IR receiver using a phototransistor. Asynchronous serial will be transmit over this link at 9600 BPS. The PIC 18F452 will be used to transmit and receiver this data.
The goal of this Project is to build an IR transmitter and an IR receiver. These two will be a wireless link of one-way asynchronous serial communication at 9600 BPS. To prove the system works the transmitter should count from 0 to 8, sending the count value out the transmitter link to the receiver. The receiver will display the current count value on 8 LEDs. Both the transmitter and receiver will use a PIC 18F452 microcontroller.
In order to create the asynchronous serial communication signals, the transmitter and receiver will use the PIC's USART module to send and receive. The transmitter data will be sent out the IR Emitter LED and, if all is successful, into the phototransistor circuit. The signal will then be input to the transmitter's USART receiver module and the current count displayed on the 8 LEDs.
PIC 18F452 Microcontroller
PIC 18F4520 Microcontroller
PICKIT 2
7805 +5v Regulator
IR Emitter LED
Phototransistor
3x 10kΩ Resistors
2x 1kΩ Resistors
2x 2n2222 Transistors
47uF Capacitor
2x 4 MHz Crystal
10x Green LEDs
2x Breadboard
Jumper Wire
SIPS
Some of the parts seen above maybe be familiar to you, but if any of them are not you can see a picture of it above. Below I have a better description of the main parts used in this tutorial.
PIC 18F452 - PIC 18F4520
Two microcontrollers will be used in this tutorial, one for the receiver and one for the transmitter. These will need to be programmed with the software that we will see in that section of this tutorial. I used a PIC 18F452 and 18F4520. These are actually the same and can be used interchangeably.
PICKIT 2
To Load the software onto the PIC microcontroller you will need a programmer. This programmer, called the PICkit2, is very popular and supported by the PIC manufacturer Microchip. It's low cost and will last.
Phototransistor
This component detects the brightness of an infrared light beam. If an infrared LED shines right into a phototransistor, it switches on, otherwise it remains in the off state.
IR Emitter LED
IR Emitter LEDs are found in many places, most commonly in laptops and TV remote controls. These cheap little LEDs are what we will be using to transmit the serial communication data to the receiving phototransistor.
2x 2n2222 Transistors
A small buffer circuit will be created using these general purpose transistors. This will allow us to switch the IR LED on and off with power directly from the power supply.
2x 4 MHz Crystal
Both systems will use a 4 MHz crystal clock, just to make things easier on us. You could use different clock rates for both microcontrollers, just make sure you have the serial communication baud rate set to 9600 BPS.
Wires & Breadboard
These will be used for connecting everything together. If you'd rather use a development board that you have, go ahead, the breadboard just creates a versatile platform that anyone can duplicate this work on.
SCHEMATICS:
Two circuits need to be built for this tutorial; the transmitter and the receiver. These two circuits are not over-complex in anyway so hopefully acquiring the parts and assembling everything should be straight forward. The main parts to take note of in these two circuits are the 7805, 18F452, 2N2222, Phototransistor and IR Emitter LED.
Wireless Infrared Link Transmitter Schematic
Schematic Specifics:
Power Circuit
The power circuit (regulator) is the same in both transmitter and receiver because all we need a +5v regulated power supply to operate the digital electronics. The 7805 linear regulator was chosen because it is cheap and widely available.
Microcontroller Circuit
The transmitting microcontroller will be a PIC 18F452. The USART module inside of this microcontroller will be used to send the asynchronous serial data. The microcontroller will continuously send a count value from 0 to 8 and then repeat.
Infrared Transmitter Circuit
The PIC's digital USART RC6 Tx output port cannot supply enough current to give the IR emitter LED the power it really needs, so a buffer circuit is used with 2x 2N2222 transistors so that the IR Emitter LED is driven from the main +5v regulated power supply.
Wireless Infrared Link Receiver Schematic
Schematic Specifics
Power Circuit
The power circuit (regulator) is the same in both transmitter and receiver because all we need a +5v regulated power supply to operate the digital electronics. The 7805 linear regulator was chosen because it is cheap and widely available.
Microcontroller Circuit
To make things as simple as possible, the receiving microcontroller will be the same as the transmitter: PIC 18F452. The other half of the USART module will be used to receive the data, rather than transmit and then the PIC will decide how many LEDs to light up, 0 to 8, depending upon the transmitted ASCII value, 0 to 8.
Infrared Receiving Circuit
This circuit consists of a photo transistor and 1x 10kΩ resistor with some connections to ground and power. The collector pin of the phototransistor is connected to the PIC's RC7 input also known as the USART Rx input.
HARDWARE DESIGN (TRANSMITTER):
The hardware section, where I'll show you how I built the transmitter and receiver is split into two sections, one for the transmitter and one for the receiver. Below are detailed descriptions and pictures of my step by step construction of the transmitter.
I always like to begin assembling a circuit by having all the parts for it laid out in front of me. When working with a breadboard a pair of needle-nose pliers can also be helpful for getting wires into the breadboard holes.
The first step is getting the power regulation circuit on the breadboard.
Afterward we add the PIC circuitry, with a crystal and 10kΩ resistor.
Now, I added the first 2n2222 buffer stage for the IR output.
The final step is adding the 2nd part of the 2n2222 buffer stage, and IR Emitter.
Hopefully that was seemingly painless, the circuit is not too complex and therefore fits nicely on a breadboard. Now let's make the receiver!
HARDWARE DESIGN (RECEIVER):
In the second part of the hardware section we will look at how the receiver was built step by step. Follow along with the schematic and you'll get a good feeling for how things come together and the stages I use when building electronics on a breadboard.
Just like before, I laid out all the parts on my workbench, ready to be assembled into the breadboard. The receiver does have significantly more parts, so it will take a little longer to get this one right.
Start by assembling the power regulation (7805) circuit on the breadboard.
The PIC circuit is added next with 4 MHz crystal and 10kΩ resistor.
Resistors are added to each pin of PORTD on the PIC for output.
LEDs are connected to the resistors and then to ground.
The final step is connecting the RX pin on the PIC to the phototransistor.
After some effort, the circuit has been built on the breadboard and is ready for some software.
SOFTWARE PART:
There are two main portions of code that we are concerned with:
Transmitter Code
Transmits USART Serial Data
Receiver Code
Receives and Translates USART Data
Since this circuit operates as if the transmitter and receiver were connected directly with a wire, the software has nothing out of the ordinary. The transmitter is constantly counting 0 to 8 over and over, and the receiver is parsing this input and lighting up the corresponding LEDs, over and over.
Infrared Link Transmitter Code
------------« Begin Code »------------
void main(void){
unsigned char rs232_s = '1';
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
25 );
while(1){
putcUSART(rs232_s);
Delay10KTCYx(10);
rs232_s += 1;
if(rs232_s == '8')
rs232_s='0';
}
}
------------« End Code »------------
There really are no surprises here. The transmitter is setup with a routine and simple while loop that counts then transmits, then counts and then transmits over and over until infinity.
Infrared Link Receiver Code
------------« Begin Code »------------
void main(void)
{
unsigned char input;
TRISC = 0xFF;
TRISD = 0x00;
PORTD = 0x00;
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
25 );
while(1){
Delay1KTCYx(1);
input = getcUSART();
switch(input){
case '1' : PORTD = 0x01;
break;
case '2' : PORTD = 0x03;
break;
case '3' : PORTD = 0x07;
break;
case '4' : PORTD = 0x0F;
break;
case '5' : PORTD = 0x1F;
break;
case '6' : PORTD = 0x3F;
break;
case '7' : PORTD = 0x7F;
break;
case '8' : PORTD = 0xFF;
break;
case '0' : PORTD = 0x00;
break;
}
}
CloseUSART();
}
------------« End Code »------------
The receiver does the same thing as the transmitter just with the opposite function: receiving. It continually checks to see if data is ready in the USART receiver buffer. When data is accepted, it is then evaluated and the LEDs updated to output the change.
DOWNLOADS: