Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to interface IR sensor (Tx-Rx pair) with PIC16F877A or 16F88?

Status
Not open for further replies.

faryal

Banned
Joined
Dec 15, 2011
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
0
I need to interface IR sensor (black&white) digitally with PIC uC 16F877A. My project is to control room appliances e.g light, fan etc through IR technology like remote control turns on/off a TV. Please help me ithe project and kindly provide me schematic diagram circuit and code. I wud be very thankful to you.
 

You can do it by several ways.How many switch do you need to control? And what kind of remote,the universal one or something self-made? Analyzing these things you should choice your protocol. Like UART or just switching it through logic.
At first,try yourself. If failed,then post the code or documentation :)
 

better to use some remote control technology like RC5 or NEC or you can create your on encoding method with pulse encoding.

search about RC5 or NEC,there are many tutorial regarding it.
 

Hi arnab913,
kind of remote: universal
protocol: switching it through logic
and for now i need to contol two switches.
 

If you use universal remote,you should know each button's pulse code. You can find in using manchester coding.
There is another way,you can use UART protocol for uC to uC communication. Use Transmitter IR on Tx of remote uC.Send a character,say 'x' by UART_write function. Set IR receiver on recevier uC and make the logic,if (UART_read()=='x'),then it switches. Thus,you can control switches as many as ASCII characters.
:smile:
 

Ok i will find out each button's pulse code , can't u just send me the further logic to control switches?
Or if i use a self made remote also in this case I need a code, Plz send it to me U have vast knowledge about it it will be quite easy for u
 

Code:
  // char data1='x';
   //char data2='a';
   //char data3='1';
   int kp=0;
   char keypadPort at PORTD;
   char key[]="abcdefghijklmno";
void main()
{
  Keypad_Init();
  trisb=0b00000111;
  portb=0;
                                          // Initialize Keypad
        UART1_Init(1200);                 // Initialize UART module at 9600 bps
        Delay_ms(100);
                                          // Wait for UART module to stabilize
   while(1) 
           {
      do                                     // Store key code in kp variable
      kp = Keypad_Key_Click();             // Store key code in kp variable
    while (!kp);
    kp=key;
    UART1_Write(key);
    portb.f6=1;
       delay_ms(100);
     portb.f6=0;
             }
}
This is Tx code.
Code:
char uart_rd;
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB6_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections


void main()
 {
  trisb=0b00000000;
  trisc=0b11111000;
  portc=0;
  portb=0;
    UART1_Init(1200);                        // Initialize UART module at 9600 bps
    Delay_ms(100);                           // Wait for UART module to stabilize
    Lcd_Init();                        // Initialize LCD

    Lcd_Cmd(_LCD_CLEAR);               // Clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

         //start:
      while (1)
           {                               // Endless loop
              if (UART1_Data_Ready())
             {
                uart_rd = UART1_Read();     // read the received data,
                delay_us(100);
               {
                if(uart_rd=='x')
                {
                    delay_ms(10);
                  portc.f0=!portc.f0;
                  // Lcd_Out(1,2,uart_rd);
                  Lcd_Chr_Cp(uart_rd);       //jekhane cursor ase sekhan thk lekha
                  delay_ms(2000);

                }
                if(uart_rd=='a')
                {
                    delay_ms(10);
                  portc.f1=!portc.f1;
                  // Lcd_Out(1,2,uart_rd);
                  Lcd_Chr_Cp(uart_rd);       //jekhane cursor ase sekhan thk lekha
                  delay_ms(2000);

                }
                if(uart_rd=='1')
                {
                    delay_ms(10);
                  portc.f2=!portc.f2;
                  // Lcd_Out(1,2,uart_rd);
                  Lcd_Chr_Cp(uart_rd);       //jekhane cursor ase sekhan thk lekha
                  delay_ms(2000);

                }
               }
              }
           }

}
This is the code of Rx.I used 2 16f73 uC.
Untitled.png
Hope that will help you to understand the process. And I know very little of this vast field. Is this your academic project or something other?
 

Thank you so much, can u upload the original .dsn proteus file or whole Rar folder?

- - - Updated - - -

Can I use the same code for 16F877A or 16F88? and this is my academic project.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top