IR Transmitting and Receiving Circuits


Infrared (IR) light is electromagnetic radiation with a wavelength between 0.7 and 300 micrometres, which equates to a frequency range between approximately 1 and 430 THz. IR wavelengths are longer than that of visible light, but shorter than that of terahertz radiation microwaves. Bright sunlight provides an irradiance of just over 1 kilowatt per square meter at sea level. Of this energy, 527 watts is infrared radiation, 445 watts is visible light, and 32 watts is ultraviolet radiation.

There are very wide applications for IR light, for example:

      • IR in AV instruments such as Audio, TV, DVD, VCR, CD, etc.
      • Home appliances such as Air conditioner, Fan etc.
      • Multi-media Equipment.
      • The other equipments with wireless remote control.

In this project, I will show you how to build the transmitting and receiving circuit of IR sensor !!!!!! The transmitting circuit contains a micro-controller with 5 codes. These codes can be selected from switches connected to PORTB. Each switch is responsible on a certain code. For example, if sw1 is pressed, code1 will be transmitted [ code1=01010].

As can be seen, this code is in binary numeral system!! Thus, how can IR led transmit this code at a certain frequency in order to recover it in the receiving circuit?? Since the center frequency of IR receiver is at 38KHZ, you have to send the signal on 38kHz to recover it with max. amplitude. Until now, how to send logic “0” and logic “1” is still unknown!! In order to send “0” & “1” , you may create spaces between the pulses. For logic “0”, you may use space=1 msec, and for logic “1” , you may use space=2msec. Check Figure 1 & 2.

IR-fig1

Fig.1: Transmitted Signal

IR-fig2

Fig.2: Transmitted Signal (time base, 250usec)

 When the signal is transmitted in the air with directivity toward the IR receiver, IR receiver will recover it. The received signal may look like the signal in the Figure below.

IR-fig3

Fig.3: Received Signal

After receiving the transmitted signal, the micro-controller starts measuring the spaces between pluses and logically numbering them to get the original code (the transmitted one).

IR-Rec

Fig.5: Receiving Circuit

IR-Tran

Fig.4: Transmitting Circuit

 

 

 

//Author: Abdullah M. Zyarah
//Receiving Circuit
//www.DigitalComputing.net

#include <16f877a.h>
#use delay(clock=20000000)
#fuses hs,nowdt,nocpd,nolvp,noprotect
#use fast_io(B)
#use fast_io(c)

#define one_min 9000        //1msec=5000
#define one_max    14000
#define zero_min 4000
#define zero_max 8000    

#byte PIR1=0x0c
#bit  ccp1f=PIR1.2
#byte portb=0x06
#byte portc=0x07
#bit led1=portb.0        
#bit led2=portb.1        
#bit led3=portb.2
#bit led4=portb.3
#bit led5=portb.4
#bit ledz=portc.4        // RC4 use for zero's
#bit ledo=portc.5        // RC5 use for one's

int16 fall;                            // variable to save the period of space
int8 rec[5]={0xff,0xff,0xff,0xff,0xff};            // array to save the received code
int8 code_x[25]={0,1,0,1,0,1,0,1,0,1,1,1,0,1,1,0,0,1,0,0,1,1,0,0,0};        // codes array
int8 one=0,zero=0,i=0,j=0,n,m,x,z,similar=0;

#include <interrupt.h>

/****************************************************/    

#int_ccp1                // interrept on falling edge
void ccp1_int();

void main()
{
    set_tris_b(0x00);    //set portb as output
    set_tris_c(0x0f);    // set 4-portc as input
    portb=0x00;
    portc=0x00;
    ledz=0;
    ledo=0;
    set_timer1(0);

    while(1)
    {
         setup_ccp1(ccp_capture_fe);    // capture the Rising edge
        setup_timer_1(t1_internal); // start timer1
        enable_interrupts(int_ccp1);
        enable_interrupts(global);        
    }
}
//Author: Abdullah M. Zyarah
//Transmitting Circuit
//www.DigitalComputing.net


#include <16f877a.h>
#use delay(clock=20000000)
#include <zeron.h>
#include <codes.h>

#fuses hs,nowdt,nocpd,nolvp,noprotect
#use fast_io(B)
#use fast_io(c)

#byte portb=0x06
#byte portc=0x07
#bit  sw1=portb.0    // sw1=RB0
#bit  sw2=portb.1    // sw2=RB1
#bit  sw3=portb.2    // sw3=RB2
#bit  sw4=portb.3    // sw4=RB3
#bit  sw5=portb.4    // sw5=RB4

#bit led=portc.4

void send_1();
void send_0();

void send_code_1();        // related to switch1
void send_code_2();        // related to switch2
void send_code_3();        // related to switch3
void send_code_4();        // related to switch4
void send_code_5();        // related to switch5


void main()
{    
    set_tris_b(0x1F);    // make RB0,RB1,RB2,RB3,&RB4 as input
    set_tris_c(0x00);    // set portc as output
    portb=0x00;
    portc=0x00;    

    while(1)
        {
            led=1;
            delay_ms(200);

            if(sw1==0)
            {
                send_code_1();
                delay_ms(50);
            }
            
            
            if(sw2==0)
            {
                send_code_2();
                delay_ms(50);
            }


            if(sw3==0)
            {
                send_code_3();
                delay_ms(50);
            }

            
            if(sw4==0)
            {
                send_code_4();
                delay_ms(50);
            }


            if(sw5==0)
            {
                send_code_5();
                delay_ms(50);
            }

        led=0;
        delay_ms(200);
            
        }
}