Thursday, January 8, 2015

IR Remote Control Based On PIC Microcontroller

IR Remote Control Based On PIC Microcontroller
I used the old pic16f84a microcontroller to construct 4 channel IR (infra red) remote control system. The transmitter part and the receiver part have the same chip microcontroller. Since the pic16f84a does not equipped with PWM model, so I used the following code to generate a 37khz pwm signal.
 void pwm(){
 for(i=0;i<64;i++){
 PORTB.F4=1;
 delay_us(13);
 PORTB.F4=0;
 delay_us(14);}
 }

This IR system has a carrier signal of 37khz and a 4 bit data long, which means that when I press a push button 4 bit data will be transmitted.
To run the 1st channel I have to transmit: 1000,
 and for the 2nd: 1001,
The 3rd channel: 1010,
And the last one: 1011.
Each bit have 1728us long, so the 4 bit data takes 6912us.
IR remote control circuit:
There are 2 circuits one for the transmitter part and the other one for the receiver part.
The transmitter circuit is shown below:

ir remote contol using pic16f84a microcontroller mikroc code

And the receiver circuit is as below:

ir remote contol using pic16f84a microcontroller mikroc code

For the ir receiver chip I used 37khz frequency ir receiver if you use one with different frequency you may get a different result.
IR remote control system mikroC code:
We have tow different codes one for the first PIC16F84A which will send signals, and the second PIC16F84A which will receive the signals. These code are written using Mikroc compiler.
The transmitter code is shown below:

//PIC16F84A IR remote control transmitter Mikroc code.
//Written by: BENCHEROUDA Okba
//electronnote@gmail.com
//Use at your own risk

unsigned short i=0,j=0;
 void pwm(){
 for(i=0;i<64;i++){
 PORTB.F4=1;
 delay_us(13);
 PORTB.F4=0;
 delay_us(14);}
 }
void main() {
 TRISB=0X0F;
 PORTB=0;
 for(j=0;j<6;j++){
  PORTB.F5=~PORTB.F5;
  delay_ms(500);}
 while(1){
 if(Button(&PORTB, 0, 100, 0)){
   pwm();
   PORTB.F4=0;
   delay_us(5184);
 }
 if(Button(&PORTB, 1, 100, 0)){
   pwm();
   PORTB.F4=0;
   delay_us(3456);
   pwm();
 }
 if(Button(&PORTB, 2, 100, 0)){
   pwm();
   PORTB.F4=0;
   delay_us(1728);
   pwm();
   PORTB.F4=0;
   delay_us(1728);
 }
 if(Button(&PORTB, 3, 100, 0)){
   pwm();
   PORTB.F4=0;
   delay_us(1728);
   pwm();
   pwm();
  }
  }
  }


The receiver code is:

//PIC16F84A IR remote control transmitter Mikroc code.
//Written by: BENCHEROUDA Okba
//electronnote@gmail.com
//Use at your own risk

unsigned short i=0;
 void interrupt(){
 delay_us(800);
 if(PORTB.F0 == 0){
    delay_us(3456);
    if(PORTB.F0 == 1){delay_us(1728);
        if(PORTB.F0==1)
           PORTB.F1=~PORTB.F1;
        if(PORTB.F0==0)
           PORTB.F2=~PORTB.F2;
           delay_ms(200);}

    if(PORTB.F0==0){delay_us(1728);
        if(PORTB.F0==1)
           PORTB.F3=~PORTB.F3;
        if(PORTB.F0==0)
           PORTB.F4=~PORTB.F4;
           delay_ms(200);}}

 INTCON.F1 =0;}     //clear interrupt flag bit
void main() {
 OPTION_REG = 0X00;
 INTCON = 0x90;     //enable external interrupt
 TRISB = 0X01;      //configure rb0 as input
 PORTB = 0;
 for(i=0;i<6;i++){
   PORTB=~PORTB;
   delay_ms(500);}
 while(1)
 ;                  //endless loop
}