8051 Based Remote for Home Appliance

Today most of the audio and video devices are remotely controlled by IR remote. IR or Infra-Red is an electromagnetic wave like light but not visible to human eye. Cheap IR remote-controllers are widely available in the market. In this tutorial I am going to show how we can control home appliance like light, fan etc. using this remote controller.

Required components:

  1. RC5 remote (e.g. PH17)
  2. Atmel 89S52 microcontroller
  3. 40 pin IC socket
  4. 11.0592Mhz crystal
  5. 10μF capacitor (2 pieces)
  6. 33pF capacitor (2 pieces)
  7. 8.2kΩ resistance
  8. 222Ω resistance (7 pieces)
  9. 10kΩ SIP resistance
  10. LED (8 pieces)
  11. ULN2003
  12. 16 pin IC socket
  13. Relay
  14. TSOP 1736
  15. 0-12V Transformer
  16. 4007 diode (4 pieces)
  17. 7805 voltage regulator
  18. Veroboard
  19. Wire and Tools

IR Protocols:             When user presses any remote key we need to send a particular message to the receiver. But there are number of IR source available in our environment like sun,light bulb, candle, any heating object. For this reason we need to encode our IR message in a way that these environments IR does not create interference and message reaches to receiver without error. Different manufacture encode in different way. But they maintain some standard known as IR protocols. Some of common IR protocols are RC5, RC6 and NEC.

In this project I have used PH17 remote which follows RC5. You can use any other RC5 remote. You may need very little code change (device address and delay).

PH17 Remote

About RC5 Protocol:            RC5 protocol is consisting of 14 bit message with constant time. Address is 5 bit long and command is 6 bit long. The message is modulated with 36 kHz carrier frequency. To know more about RC5 protocols please refer my RC5 Protocol tutorial.

Circuit Design:                      The heart of this project is 8051 microcontroller. In this project I have used 89S52 which is based on 8051 microcontroller architecture with some extra flexibility. You can use any other 8051 microcontroller with same clock frequency (11.0592MHz).

TSOP1736 is very useful sensor to demodulate IR signal with 36kHz. It is an active low device. The output pin is pulled Low when IR signal with 36kHz detected. The output pin of TSOP is connected to P3_0 of microcontroller.

8 LEDs attached in P1 as output indicator. To handle 240v AC we need Relay as switch. Relay is an electromechanical device, used to isolate low voltage DC and high voltage AC or DC. To drive relay we need good amount of current which can’t be provided by microcontroller output pin. ULN2003 which generally used as unidirectional motor driver can be used as relay driver as well. It can drive upto 7 relays.

We need 12v power supply for ULN2003 and relay. 5v for all other components. A 0-12v transformer with 500mA output current capability is good enough for this. The output of transformer is converted to 12v DC using bridge circuit and filter. For 12v to 5v step-down I have used 7805 IC.

AC Remote Circuit Diagram

Hardware Design:                 The whole circuit is designed on strip line veroboard. You can use PCB layout if you are comfortable with it. Place the components wherever you like. There is no dependency of microcontroller I/O pin with the components e.g. TSOP output pin can be attached to any of the microcontroller I/O pin. Here is my prototype.

  • Hardware Prototype

Demo:

Source Code:                        Decoding of any IR protocol is highly dependent with time frame. In this project I have used 11.0592MHz crystal. The code is written in C and we need a compiler to generate Hex code. Different compiler generates different Hex code and delay used in program might be different. I have used SDCC compiler which is a very good open source compiler. If you are using different compiler you might need to adjust the delay.

// Bootloader and Library Fnctions Starts Here //
#include <8051.h>
void setup();
void loop();
void main(){
	setup();
	while(1)loop();
}
// Bootloader and Library Fnctions Ends Here //
#define IR_PIN P3_0
void delayRC5(unsigned char p);
void processIR(unsigned char command);
__bit flipBit = 0;
__bit prevFlipBit = 0;

void setup(){
	
}
void loop(){
	unsigned char address = 0x00;
	unsigned char command = 0x00;
	unsigned char count=0x00;
	while(IR_PIN==1);	//Wait for first bit 
	delayRC5(7);		//Delay for 3.024ms
	flipBit=IR_PIN;		//Reading flip bit
	for(count=0;count<5;count++){
		delayRC5(4);	//Delay for 1.728ms
		address = address << 1;
		if(IR_PIN==1)
			address = address | 0x01;
	}
	for(count=0;count<6;count++){
		delayRC5(4);	//Delay for 1.728ms
		command = command << 1;
		if(IR_PIN==1)
			command = command | 0x01;
	}
	//P1 = command;
	if(address == 0x00 && flipBit != prevFlipBit){
		processIR(command);
		prevFlipBit = flipBit;
	}
}
void processIR(unsigned char command){
	if(command == 0x01){
		P1_1 = ! P1_1;
		P2_1 = ! P2_1;
	}else if(command == 0x02){
		P1_2 = ! P1_2;
		P2_2 = ! P2_2;
	}else if(command == 0x03){
		P1_3 = ! P1_3;
		P2_3 = ! P2_3;
	}else if(command == 0x04){
		P1_4 = ! P1_4;
		P2_4 = ! P2_4;
	}else if(command == 0x05){
		P1_5 = ! P1_5;
		P2_5 = ! P2_5;
	}else if(command == 0x06){
		P1_6 = ! P1_6;
		P2_6 = ! P2_6;
	}else if(command == 0x07){
		P1_7 = ! P1_7;
		P2_7 = ! P2_7;
	}
}
//delay for 432uS. For 3.024ms call 7 times and fro 1.728ms call 4 times //
void delayRC5(unsigned char r){ 
	unsigned char p;
	unsigned int q;
	for(p=0;p<r;p++)
		for(q=0;q<53;q++);	//Clock 11.0592MHz
}

23 thoughts on “8051 Based Remote for Home Appliance

  1. Hey dude,,,,
    Where I can add my custom ir signal value …I have a six digit value for a signal …so I have to add the last two digits only huh …

    Sayy….my tv power button code is 1FF0B6 …now I have to put the last two digits B6 only in the code ?? …like the below

    if (command ==0xB6)
    {
    }

      1. Dude ..I have 2 questions pls help me …in this code ….where I want put the founded RC5 protocal value ….

        And the second question is … actually I have 89s52 mcu ….I want to make a home automation using IR ….and I have NEC ir remote …this is my project kindly help mee!!!!!

        Plz…ans this two questions ..

        Thanks in advance 😅😅

    1. You need to change q<53 in delayRC5 function. You need to modify in a way this function gives 3.024ms delay. You can use an oscillator for this.

    1. 8051.h should be present in default building environment. You need to include at the beginning of your code only.

  2. I like to make remote control ac 230v fan speed control using AT89C2051. Please help me for coding & software..

    1. You can use the provided code for IR decoding. To control the speed you can use either Digital Dimmer or PWM with TRIAC.

  3. I like to make remote control ac 230v fan speed control useing arduino. Please help me for coding & software.

    1. Hi Ishwarlal,

      Building IR receiver using Arduino is much more easier. There are multiple IR decoder library for Arduino available in internet. You can choose any one of them and you have to write very full lines of code according to your requirement. Simply you can edit their example code.

      From hardware perspective you need to replace 8051 microcontroller and its associate components with Arduino. You can use ULN 2003 as relay driver.

    1. Hi Bhavana,

      As you mentioned that you are a beginner I would suggest to go through some tutorial for basic C programming and embedded system. This program is very simple and self explanatory. If you are unable to understand any specific section please let me know, I will try to explain.

  4. Hey, Rahul great job. I want to control intensity of light by TV remote using micro controller(PIC/ 8051). How much time it will take and how much cost you will charge?

    1. Hi Jay,
      Here are the few options that can be used to control light intensity.

      1. The easiest way is to use digital dimmer module available in market. You can use 8051 or PIC microcontroller for this. You only have to pass the intensity value in binary form to the module. This will cost you approx Rs. 500/- extra.

      2. The second way is PWM dimming using TRIAC. Though 8051 does not have PWM hardware you can implement this by software. The drawback of this method is you only can use resistive load (filament bulb) for reliable output.

  5. Hi,
    This isn’t a full proof code. You are using delay functions for the decoding the signals. This is highly unreliable as you’ll have to use ‘trial and error’ technique every time you change the platform to compile.
    But on the other hand, this is a good code when you consider for non-commercial/educational purposes.

  6. I HAVE A QUESTION!!!!!! HOW DID YOU BURN THAT CODE ON THE MICROCONTROLLER? ALSO CAN YOU PLEASE TELL HOW MUCH WILL IT COST TO PREPARE THE WHOLE PROJECT FROM A SCRATCH…… PLEASE REPLY SOON

    1. Hi Swati,

      Here is the answer to your questions.

      1. To burn the code you need 8051 burner. The burner differs depending on the microcontroller manufacturer. I have used Atmel 89S52. There are plenty of cheap 89S52 burner available in eBay.

      Alternatively if have Arduino board you can make your own burner. Here is one example
      http://www.instructables.com/id/ARDUINO-AS-A-8051-PROGRAMMER/?ALLSTEPS

      2. The approximate cost of the project is Rs 800/- excluding the burner and tools.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.