Home Automation using Android App Without Coding Backend Part

The aim of this project is to control appliances of the house using an app sitting anywhere in the house. In this project I have shown how to control LED using an app, the same method can be applied for home appliances by just adding relay in the circuit.

Components required:

  • Android Mobile
  • ATMEGA128(Microcontroller)
  • LM7805(Voltage Regulator)
  • HC05(Bluetooth Module)
  • LEDs and Resistors
  • 9v Battery

Circuit Diagram:

Brief description about components and its configurations:

  • ATMEGA128

Atmega128 is a microcontroller. A microcontroller is different from a microprocessor. A microprocessor is a multipurpose device capable of heavy calculations but lacking other components like timers, RAM, ROM (i.e. peripherals). These have to be connected externally for proper functioning. Meanwhile, microcontrollers have such inbuilt features into them. Microcontrollers are not multipurpose devices. Atmega comes in various shapes and types. I have used Atmega128 for this project.

  •  LM -7805

A LM7805 Voltage Regulator is a voltage regulator that outputs +5 volts when given a higher voltage like 12v. If you give 12v/9v through battery directly to your Atmega you will end up with a deep-fried chip. 

An easy way to remember the voltage output by a LM78XX series of voltage regulators is the last two digits of the number. A LM7805 ends with “05”; thus, it outputs 5 volts. The “78” part is just the convention that the chip makers use to denote the series of regulators that output positive voltage. The other series of regulators, the LM79XX, is the series that outputs negative voltage. 

LM78XX: Voltage regulators that output positive voltage, “XX”=voltage output.

LM79XX: Voltage regulators that output negative voltage, “XX”=voltage output

The LM7805, is a three-pin IC.

Pin 1 (Input Pin): The Input pin is the pin that accepts the incoming DC voltage, which the voltage regulator will eventually regulate down to 5 volts.

Pin 2 (Ground): Ground pin establishes the ground for the regulator.

Pin 3 (Output Pin): The Output pin is the regulated 5 volts DC.

  • BLUETOOTH MODULE HC05:

It is used for wireless serial communication. The Bluetooth module HC-05 is a MASTER/SLAVE module. By default the factory setting is slave. The Role of the module (Master or Slave) can be configured only by AT COMMANDS.

The HC-05 Bluetooth Module has 6 pins. They are as follows:

Enable:

When this pin is connected to 3.3V module is enabled and communication can take place.

VCC: 

Supply Voltage 3.3V to 5V

GND:

Ground pin

TXD & RXD: 

These two pins acts as an UART interface for communication

STATE: 

It is a status indicating whether the Bluetooth module is paired with other Bluetooth or not. If it is paired LED on module blinks with constant delay and if it is not paired it blinks continuously.

BUTTON SWITCH: 

This is used to switch the module into AT command mode. With the help of AT commands, the user can change the parameters of this module but only when the module is not paired with any other Bluetooth device. If the module is connected to any other Bluetooth device, it starts to communicate with that device and fails to work in AT command mode.

SOME COMMON AT COMMANDS

These commands are for Teraterm software.

AT+NAME – To rename the Bluetooth module

AT+ADDR- Displays the IP address of the module.

AT+PSWD-To set the pin (e.g.: 0000, 1234) for pairing connection

AT+UART-To set (Baud rate, Parity, Stop bits) for UART communication

AT+HELP-It displays all commands that can be used

AT-If it gives OK, the Bluetooth module is in AT command mode.

Note: These commands may vary with your module’s model. Check for the appropriate commands online.  

You can set parameters too.

 E.g.-

AT+NAME=ABC will set the module’s name to ABC. 

AT+PSWD=0000 will the password to 0000

(The default password is 1234 or 0000)

These commands are given via software called Teraterm. Download and install it. 

To configure the module, take a TTL and make the following connections between it and HC05. 

5v to 5v 

GND to GND

EN to 5V

TX to RX

RX to TX

Configurations of Bluetooth module:

Press down the button on the module before connecting the TTL to the laptop, this will set the HC 05 to at command mode. If you forget to do this you won’t be able to configure it ( it won’t reply OK when you command AT). In Teraterm select setup>serial >terminal>set transmit to CR+LF and check the “local echo”. Now setup>serial port>set the baud to 38400.

NOTE: This is not the baud of your code. This is the standard baud at which the TTL communicates with the HC05. You will set the baud that you want via the at command: AT+BAUD=9600,0,0 (This command will vary with the model, please check the datasheet for your model or goggle “at commands for HC 05 ”and try all commands and see what sticks). 

After configuring the module, disconnect the TTL; download the app “Bluetooth Terminal

UART (Universal Asynchronous Receiver/Transmitter)

UART stands for Universal Asynchronous Receiver/Transmitter. As mentioned earlier, Bluetooth communicates serially so to communicate with microcontroller UART protocol is used. In UART communication, two UARTs communicate directly with each other. The transmitting UART converts parallel data from a controlling device like a CPU into serial form, transmits it in serial to the receiving UART, which then converts the serial data back into parallel data for the receiving device. Only two wires are needed to transmit data between two UARTs. Data flows from the Tx pin of the transmitting UART to the Rx pin of the receiving UART. 

Through UART data is transmitted asynchronously unlike USART, which means there is no clock signal required for the sampling of bits by the receiving UART. Instead of a clock signal, the transmitting UART add start and stop bits to the data packet being transferred. These bits define the beginning and end of the data packet so the receiving UART knows when to start reading the bits.

For more information on UART and its registers you can go through datasheet of ATMEGA128.

ANDROID APPLICATION 

Log on http://ai2.appinventor.mit.edu

Register yourself and start using the portal. 

This website uses a graphical interface, very similar to the scratch user interface, which allows users to drag-and-drop visual objects to create an application that can run on Android devices. 

You can test your application using the MIT A2 COMPANION application which can be downloaded from Google Play store. 

After login how its 1st page looks:

AFTER CODING, YOUR CODE WINDOW WILL LOOK SOMETHING LIKE THIS:

Software used for coding is Atmel Studio:

CODE:

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>
int x=0;
void init()
{
                UBRR0H=(51>>8);
                UBRR0L=51;
                UCSR0B=0b00011000;
                UCSR0C=0b00000110;
}
void transmit( unsigned char data )
{
                while ( !( UCSR0A & (1<<UDRE0)) );
                UDR0 = data;
}
unsigned char receive(void)
{
                while(!(UCSR0A &(1<<RXC0)));
                return UDR0;
}
void app()
{                             
                                unsigned char data;
                                data=receive();
                                if (data == '1')
                                                                {PORTB |= (1<<PB0);}
                           else if (data == '2')
                                                                {PORTB &= ~(1<<PB0);}
                           else if (data == '3')
                                                                {PORTB |= (1<<PB1);}
                            else if (data == '4')
                                                                {PORTB &= ~(1<<PB1);}
                             else if(data == '5')
                                                                {PORTB |= (1<<PB2);}
                            else if(data == '6')
                                                                {PORTB &= ~(1<<PB2);}
                             else if(data == '7')
                                                                {PORTB |= (1<<PB3);}
                            else if(data == '8')
                                                                {PORTB &= ~(1<<PB3);}
}
int main(void)
{                              init();
                                while(1)
                                                {
                                                app()
}
}

Leave a Comment

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.