Remote Controlled Home Appliances project using ATmega8



Hi everyone! First of all I would like to thank Avinash Gupta for writing all the valuable tutorials and libraries for AVR Microcontrollers and helping people like me to build projects and learn new things. I am dedicating this post to him!
 

Introduction:Using remote keys from 1 to 4, you can control 4 appliances. You can easily extend this number to as many you wish. For example, if you press key_1 on your remote, fan will turn ON. If you press the same key again, fan will turn OFF i.e each time you press a key configured for an appliance, the condition will toggle. I have programmed the MCU such that all devices will turn OFF on pressing power button(RED COLOR on top of your remote). You can also choose combinations like turning all fans OFF at a time, etc. With little tweaking, you can change the program yourself! The status of the appliances is shown in an LCD. You can ignore this feature if you dont want LCD. I used LCD for developing the code.

I main advantage in this project is that the appliance status is stored here using internal ATmega8 EEPROM. So, whenever mains power goes off and comes again, the appliance will be in the same state in which it is before. Suppose if power goes off during night. The fan will be off. When power is back, the fan will be automatically turned on again. You dont have to search for remote again!

Another advantage using this circuit is that you dont have to use your TV Remote. You can use any DVD remote. So, chances for interference are very less. Normally when you use TV Remotes, your TV channel will also change with appliance. Personally I faced this problem in my old project. Thanks to Avinash for creating wonderful libraries for using DVD Remote.

Circuit Diagram :

Circuit Explanation :
The project is running off using internal oscillator with 8MHz frequency. So becarefull with fuse bit settings.

Fuse bits :
Int. 8 MHz d9 e4

We are using TSOP1738 Infrared Receiver IC here to get the DVD Remote signals. The output from TSOP Sensor is connected to INT0 (pin PD2). The MCU receives the signals and appropriate action is taken (appliance switching). After switching, the status of device is stored in EEPROM. Then the status is displayed in LCD.

The commands for keys may vary from one remote to another remote. So, before using the remote, check the command values for keys and update them in "rckys.h" file. Otherwise the appliance will not switch. Use the second tutorial for getting the command codes.
To learn about IR Remote decoding, see this tutorials
Tutorial - 1
Tutorial - 2

To use LCD in your projects, see this tutorial. After reading this, you wont find hard to interface LCD in your project. I started using LCD in every project because you will get visual information directly regarding what is happening and program flow. It will be also useful during debugging process which you cant do using software tools. click the below link for LCD tutorial.
LCD Tutorial
LCD Connection for the project :
PIN Configurations:
The lcd modules has 16 PINs for interfacing. The details are given below.
1 VSS (GND Supply)
2 VCC (+5V)
3 VEE (Contrast Adjust)
Connect to gnd for normal contrast
4 RS
PB2
5 R/W
PB0
6 E
PD7
7 DB0
Not Connected
8 DB1
Not Connected
9 DB2
Not Connected
10 DB3
Not Connected
11 DB4
PD3
12 DB5
PD4
13 DB6
PD5
14 DB7
PD6
15 LED+
Vcc
16 LED-
Gnd

Outputs are connected to PORTC from PC0 to PC3. You can change this connection according to your wish by changing the code. The pins PC0 to PC3 are connected to IC ULN2803. This is a high voltage high current buffer. Click here to know how to use the buffer for connecting relays.
Connecting relays
Internal EEPROM is used for saving the appliance status. I searched internet for using internal EEPROM but didnt find useful information. So, I went back to datasheet of ATmega8 and I found the program there! I made the EEPROM library in my project using the datasheet. You will know about EEPROM more in datasheet. You will know the importance of datasheet once you start using it for programming the MCU.
search for "eeprom_read" to understand the eeprom read operation. search for "eeprom_write" in datasheet to understand the eeprom write operation.I created the libraries using those functions only. For understanding code and C tips, click the link below for tutorial in extremeelectronics.co.in written by Avinash Gupta.
C Programming Tips - Embedded Development
AVR GCC CODE :
#include
#include
#include "lcd.h"
#include "remote.h"
#include "rckeys.h"
#include "eeprom.h"

uint8_t app_1,app_2,app_3,app_4,cmd=0;
 int main()
{
DDRC|=((1<<<<

 //Give Some Time for other hardware to start
 _delay_loop_2(0);
  LCDInit(LS_BLINK);//Initialize the LCD Subsystem
  LCDClear();
  InitRemote();//Initialize the Remote Subsystem

 /*EEPROM bits have to set to either FF or 00. In default they will be set to FF. But its better to check them using Extreme electronics USB avr burning software.
 If the values are other than those, set them to 00 or FF. 
 00 - OFF
 ff - ON

 I have written the EEPROM routines using atmega8 datasheet. Refer EEPROM section in datasheet for more information regarding reading and writing of operation in EEPROM.
 */
 //Reading from internal EEPROM
 app_1 = EEPROM_read(0); 
 app_2 = EEPROM_read(1);
 app_3 = EEPROM_read(2);
 app_4 = EEPROM_read(3);

 while(1)
 {
 switch(cmd)
  {
  case RC_1:
   app_1=~app_1;   
 //toggling the state of appliance

   if(app_1==0)
   PORTC|=(1<
   else
   PORTC&=(~(1<  //Turn On the appliance_1

   EEPROM_write(0,app_1); 
  //saving the state of appliance
   break;
  
  case RC_2:
   app_2=~app_2;   
  //toggling the state of appliance
   if(app_2==0)
   PORTC|=(1<
   else
   PORTC&=(~(1<  
  //Turn On the appliance_2
  
   EEPROM_write(1,app_2); 
  //saving the state of appliance
   break;

  case RC_3:
   app_3=~app_3;   
  //toggling the state of appliance
   if(app_3==0)
   PORTC|=(1<
   else
   PORTC&=(~(1<  
   //Turn On the appliance_3
  
   EEPROM_write(2,app_3); 
   //saving the state of appliance
   break;

  case RC_4:
   app_4=~app_4;   
  //toggling the state of appliance
   if(app_4==0)
   PORTC|=(1<
   else
   PORTC&=(~(1<  
  //Turn On the appliance_4
  
   EEPROM_write(3,app_4); 
  //saving the state of appliance
   break;

  case RC_POWER:  
  //turn off all the appliances
   app_1=0;
   app_2=0;
   app_3=0;
   app_4=0;
   EEPROM_write(0,app_1);
   EEPROM_write(1,app_2);
   EEPROM_write(2,app_3);
   EEPROM_write(3,app_4);
   break;
  }
  
   if(app_1==0)
   {LCDWriteStringXY(1,0,"A1-OFF");}
   else
   {LCDWriteStringXY(1,0,"A1-ON ");}
  
   if(app_2==0)
   {LCDWriteStringXY(9,0,"A2-OFF");}
   else
   {LCDWriteStringXY(9,0,"A2-ON ");}
     
   if(app_3==0)
   {LCDWriteStringXY(1,1,"A3-OFF");}
   else
   {LCDWriteStringXY(1,1,"A3-ON ");}
  
   if(app_4==0)
   {LCDWriteStringXY(9,1,"A4-OFF");}
   else
   {LCDWriteStringXY(9,1,"A4-ON ");}
  
   uint8_t cmd;  //dont cut and paste on the top
   cmd=GetRemoteCmd(1);
   /*Get Remote Command. Command is taken in last because the
    the past device status has to be recovered first!   
   */
 }
}

 
Implementation :
I Implemented this project on XboardMini from extremeelectronics. I am posting images of the project. I am currently improving the code for fan speed control and Room light control for the same project. Very soon, I will build the project on a demo board and will post those photos. I will be updating this post regularly, so subscribe to my blog newsletter for updated information.

Wondered how the XBoardMini is working with out power adopter? In the last photo, can you a see a red wire connecting two terminals and the ISP connector with black tape wounded around it? Yes! the development board is running from USB power supply. If you also want to power your development boards directly from your USB, view this post.
Modifying AVR Development board and Programmer









Comments