How to do home automation light and fan with TV remote?
Embedded system microcontroller 8052 series making home automation light and fan operate with any TV remote. Mainly use Keil c coding program can making operate between input and output pins of microcontroller 8052. First take microcontroller at89s52 40 pin, tsop1738 sensor, microcontroller development board, 5v DC power supply and remote rc5.
Embedded system micro controller 8052 development board |
Keil C coding
#include <reg51.H>
#define SWPort P1 // port definition
sbit IR = P3^0; // pin's definitions
sbit SW1 = P1^0;
sbit SW2 = P1^1;
sbit SW3 = P1^2;
sbit SW4 = P1^3;
sbit SW5 = P1^4;
sbit SW6 = P1^5;
sbit SW7 = P1^6;
sbit SW8 = P1^7;
void delay_3024ms(); // delay function for 3.024ms
void delay_1728ms();
void delay_4752ms(); // delay function for 4.752ms
void ReadAddr(void); // Read Address
void ReadCmd(void); // Read Command
bit ReadBit(void); // Read Bit
unsigned char temp,addr,cmd; // result in the form of Commands,Address
bit FLIP,TOG=0; // bits
char buffer[50];
void main() // main program
{
TMOD=0X01; // timer 0 mode 1 (16 bit mode)
SWPort=0x00;
while(1)
{
while(IR==1);
delay_3024ms();
FLIP=IR;
delay_4752ms();
ReadAddr();
ReadCmd();
P1=cmd;
}
}
void delay_3024ms(void) // delay of ms
{
TH0=0XF5; // 3.024ms
TL0=0X1D;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
void delay_1728ms(void) // delay of 1.728ms
{
TH0=0XF9; //TH0=0XF9; // 1.728ms
TL0=0XC7; //TL0=0XC7;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
void delay_4752ms(void) // delay of 1.728ms
{
TH0=0XEE; // 4.752ms
TL0=0XE4;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
bit ReadBit(void)
{
return(IR); // return value of IR line
}
void ReadCmd(void)
{
unsigned char i;
cmd = 0;
for (i=0;i<6;i++)
{
cmd|=ReadBit()? 0x01<<i:cmd;
delay_1728ms();
P1=cmd;
}
}
void ReadAddr(void)
{
unsigned char i;
addr = 0;
for (i=0;i<5;i++)
{
addr|=ReadBit()? 0x01<<i:addr;
delay_1728ms();
}
}
The above code is for operate lights and fan through TSOP1738 sensor, the sensor pins +5v, Gnd, output these three pins are connect output pin to Port P3.0 pin. You can connect port 1 pin 1.0 to pin 1.7 total 8 pins connect to devices like three lights, two fans, bed light so on. You can operate with TV remote button 0 to 9 operate can do ON and OFF.
Computer stuff kit tricks of Topics 40.
Blog traffic – how to increase traffic to website
Embedded systems - Micro controller 8051, SRAM, FLASH and EEPROM memories.
Mobile Internet connection - Browsers like Google chrome, Mozilla Firefox.
Desktop or Laptop Troubleshoot - Monitor, Processor, Hard disk RAM and ROM.