Bluetooth Home Automation using AVR Microcontroller

This bluetooth based home appliances control using android phone is developed using the AVR microcontroller. And It will be very interesting if we can control the home appliances through the android phone. Normally we switch ON and OFF the home appliances through the switch. But there are different wireless mode like WiFi, RF, DTMF and Bluetooth to control the home appliances.

We are using the Bluetooth technology of an android phone to control the home appliances. Bluetooh has a range of around 20-30 meter. So we can control the devices within this range.

We are controlling the home appliances through the android application which are available at the google play store. There is a different Bluetooth application to control the devices like Arduino Bluetooth ControlBlueSwitch Home automation and Arduino Smart Home Automation.

But we are using the Bluetooth Controller App. It is very simple and easy to use.

Home Automation Bluetooth Application


A bluetooth module operates at Scientific and Medical (ISM) 2.4GHz short-range radio frequency band. Bluetooth uses a radio technology called frequency-hopping spread spectrum. 
There is a different bluetooth module in the market for hobby and embedded system development. We are using HC 05 bluetooth module in this tutorial.

Working of Bluetooth based Home Automation

In this project, we are using the HC-05 bluetooth module and AVR ATmega8 microcontroller. Both HC05 and atmega8 is connected serially at a baud rate of 9600.

We can control three devices in this project and for that, we used three relays in the circuit. We are assumed to control these devices FAN, BULB and AC in this tutorial.

We configure the bluetooth controller app to control these three devices from the android phone.

You can see easily that all the button is empty and we can edit according to the project.

Arduino Bluetooth Controller App


So press button "SET KEYS"
A new window will open:
Key Name: FAN, BULB and AC => This is button Text
Key Value: => A, B and C respectively, send  this key value via bluetooth of android to HC-05 module Now press OK.

Home Automation Bluetooth AVR

Bluetooth Home Automation AVR


Now connect the bluetooth module as shown above and then supply it. Pair the HC-05 device with the mobile. It is just like we pair the other mobiles. The passkey is "1234". Once paired we can find it from the bluetooth controller app by pressing the button "SCAN".

Arduino Bluetooth Controller App
Arduino Bluetooth Controller App

Bluetooth Home Automation Atmega

And its Done! Now we write some code to arduino that will ON and OFF the LED by accepting 'A' for "ON" and 'B' for "OFF".

Bluetooth Home Automation AVR Circuit

Bluetooth Home Automation Circuit using AVR and HC05

Bluetooth Home Automation AVR Code

#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#include <avr/interrupt.h>

char buffer[10];
void USARTInit(uint16_t ubrr_value)
{
    //Set Baud rate
    UBRRL = ubrr_value;
    UBRRH = (ubrr_value>>8);
    UCSRC=(1<<URSEL)|(3<<UCSZ0);
    //Enable The receiver and transmitter
    UCSRB=(1<<RXEN)|(1<<TXEN);
}

char USARTReadChar()
{
    //Wait until a data is available
    while(!(UCSRA & (1<<RXC)))
    {
        //Do nothing
    }
    return UDR;
}

void USARTWriteChar(char data)
{
    while(!(UCSRA & (1<<UDRE)))
    {
        //Do nothing
    }
    UDR=data;
}
int main()
{
    USARTInit(77);
    DDRB=0b11111111;//PORTB as output
    char data;
    int fan=0;
    int bulb=0;
    int ac=0;
    while(1)
    {
        data=USARTReadChar();
        if(data=='A')
        {
            fan=~fan;
        }
        if(data=='B')
        {
            bulb=~bulb;
        }
        if(data=='C')
        {
            ac=~ac;
        }
        if(fan)
            PORTB|=(1<<PORTB0); //FAN ON
        else
            PORTB&=~(1<<PORTB0);//FAN OFF
        if(bulb)
            PORTB|=(1<<PORTB1); //BULB ON
        else
            PORTB&=~(1<<PORTB1);//BULB OFF
        if(ac)
            PORTB|=(1<<PORTB2); //AC ON
        else
            PORTB&=~(1<<PORTB2);//AC OFF
    }
    return 0;
}