Friday, 16 September 2016

Bluetooth Controlled Home appliances

Bluetooth Controlled Home appliances:

Code:



#include <avr/io.h>
#define F_CPU 8000000ul
#include<util/delay.h>

#define light PORTC
#define light1 PC0
#define light2 PC1
#define light3 PC2

char str[3],i=0;

void serialinit()
{
UCSRB=0x18;
UCSRC=0x86;
UBRRL=0x33;
}

void send(char p)
{
UDR=p;
while(!(UCSRA & (1<<UDRE)));
}

void txstring(char *ptr)
{
while(*ptr)
{
send(*ptr);
ptr++;
}
}

void rxdata()
{
while(!(UCSRA & (1<<RXC)));
char temp=UDR;
str[i++]=temp;
}

int main(void)
{
  DDRC=0xff;
  serialinit();
  while(1)
  {
  rxdata();
  if(str[i-1]=='1')
  {
  light|=(1<<light1);
  txstring("Light1 ON\r\n");
  i=0;
  }
 
  else if(str[i-1]=='2')
  {
  light&=~(1<<light1);
  txstring("Light1 OFF\r\n");
  i=0;
  }
 
  else if(str[i-1]=='3')
  {
  light|=(1<<light2);
  txstring("Light2 ON\r\n");
  i=0;
  }
 
  else if(str[i-1]=='4')
  {
  light&=~(1<<light2);
  txstring("Light2 OFF\r\n");
  i=0;
  }
 
  else if(str[i-1]=='5')
  {
  light|=(1<<light3);
  txstring("Light3 ON\r\n");
  i=0;
  }

else if(str[i-1]=='6')
{
light&=~(1<<light3);
txstring("Light3 OFF\r\n");
i=0;
}

else if(str[i-1]=='7')
{
light|=(1<<light3) | 1<<light2 | 1<<light1;
txstring("ALL Lights ON\r\n");
i=0;
}

else if(str[i-1]=='8')
{
light&=~(1<<light3) & ~(1<<light2) & ~(1<<light1);
txstring("All Lights OFF\r\n");
i=0;
}
}
 }




0 comments:

Post a Comment

if you have any doubt please let me know