Automation using Android - Final Year Project for B.E


Published on

Published in: Engineering, Technology, Business
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Automation using Android - Final Year Project for B.E

  1. 1. Organization Automation Using Android Dept of C.S.E Page 1 KARNATAK LAW SOCIETY’S GOGTE INSTITUTE OF TECHNOLOGY UDYAMBAG, BELGAUM – 590008 ORGANIZATION AUTOMATION USING ANDROID A Project Report submitted in partial fulfillment of the requirements for the Award of Degree of Bachelor of Engineering in Computer Science & Engineering of the Visvesvaraya Technological University, Belgaum SUBMITTED BY : Amit Walvekar Anup Vanarse [2GI09CS008] [2GI09CS014] Indraneel Deshpande Jayesh Dhoot [2GI09CS038] [2GI09CS039] UNDER THE GUIDANCE OF: Asst. Prof. K. D. Hanabaratti VIII SEMESTER DEPARTMENT OF COMPUTER SCIENCE & ENGG. GOGTE INSTITUTE OF TECHNOLOGY 2012– 2013
  2. 2. Organization Automation Using Android Dept of C.S.E Page 2 KARNATAK LAW SOCIETY’S GOGTE INSTITUTE OF TECHNOLOGY UDYAMBAG, BELGAUM – 590008 DEPARTMENT OF COMPUTER SCIENCE & ENGG. CERTIFICATE Certified that the project work entitled “ORGANIZATION AUTOMATION USING ANDROID” carried out by Mr. Amit Walvekar Mr. Anup Vanarse Mr. Indraneel Deshpande Mr. Jayesh Dhoot bonafide student[s] of Karnatak Law Society’s Gogte Institute of Technology, Belgaum, in partial fulfillment for the award of Bachelor of Engineering in Computer Science and Engineering of the Visveshvaraya Technological University, Belgaum during the year 2012-2013. It is certified that all corrections/suggestions indicated for Internal Assessment have been incorporated in the Report deposited in the departmental library. The project report has been approved as it satisfies the academic requirements in respect of Project work prescribed for the said Degree Guide HOD Principal Asst. Prof. K. D. Hanabaratti Dr. R. M. Jogdand Dr. A. S. Deshpande
  3. 3. Organization Automation Using Android Dept of C.S.E Page 3
  4. 4. Organization Automation Using Android Dept of C.S.E Page 4 ABSTRACT Automation is a way to have things around you happen automatically. The first thing that comes to mind when folks think of automation are robots, flashing lights, complicated electronics and a general feeling that their surrounding is less of a warm place and more of a cold science experiment. However, in most organizations today, you can easily find some simple forms of automation such as: Garage door openers ,Remote Controls ,Irrigation / sprinkler control systems ,Motion activated lights ,Security systems ,Programmable thermostats ,Programmable light timers If you want to keep going, you can throw in dishwasher, clothes washers and dryers, ovens, microwaves, cars, lights and switches…. The list goes on and on.
  5. 5. Organization Automation Using Android Dept of C.S.E Page 5 ACKNOWLEDGEMENT No project can be successfully completed without timely guidance and moral support of technically equipped and experienced minds. We would like to express our heartfelt gratitude towards our inspirational guide and mentor Asst. Prof. K. D. Hanabaratti, whose firm belief in our capabilities to bring our potential to the forefront, has played a major role in the accomplishment of this project. We owe a debt of gratitude to Dr. A. S. Deshpande, Principal, Gogte Institute Of Technology, Belgaum, for providing us all the support, facilities and cooperation to carry out the project. We sincerely thank Dr. Rashmi M. Jogdand, HOD, Dept. of CSE, without whose moral support this would not have been successful. We also thank the faculty and non-teaching staff of Computer Science and Engineering Department and the library staff for their timely cooperation and much needed assistance. Last but not the least, we would like to thank our parents and friends for their support and understanding without which we would not have been able to complete this project. Project Associates Anup Vanarse Amit Walvekar Jayesh Dhoot Indraneel Deshpande
  6. 6. Organization Automation Using Android Dept of C.S.E Page 6 TABLE OF CONTENTS CHAPTER PAGE NO. 1. LITERATURE SURVEY 1 1.1. Android Overview 1 1.2. Java Socket Programming 3 1.3. Port Forwarding In Router 9 1.4. Atmel ATMega16 Microcontroller 14 2. INTRODUCTION 22 2.1. Objective 22 2.2. Module 22 2.3. Basics 22 2.4. Problem Definition 23 2.5. Software Requirement Specification 23 2.6. Hardware Requirement Specification 23 2.7. Scope 24 3. USE-CASE DIAGRAM AND SEQUENCE DIAGRAM 25 3.1. Use-Case Diagram 25 3.2. Sequence Diagram 26 4. SYSTEM DESIGN 27 4.1. Dataflow Model 27 4.2. Hardware Design 28 4.3. Android Application Development Design 32
  7. 7. Organization Automation Using Android Dept of C.S.E Page 7 5. IMPLEMENTATION 33 5.1. AVR Programming 33 5.2. Android Application 35 6. RESULT 41 6.1. Snapshots of the Android Application 41 6.2. Snapshots of the Embedded System 50 7. CONCLUSION AND FUTURE IMPROVEMENTS 51 8. APPENDIX A 52 9. BIBLOGRAPHY 53
  8. 8. Organization Automation Using Android Dept of C.S.E Page 8 Chapter 1 Literature Survey 1.1. Android Overview Android is an open-source software stack created for a wide array of devices with different form factors [1]. The primary purpose of Android is to create an open software platform available for carriers, OEMs, and developers to make their innovative ideas a reality and to create a successful, real-world product that improves the mobile experience for end users. We also wanted to make sure that there was no central point of failure, where one industry player could restrict or control the innovations of any other. The result is a full, production-quality consumer product whose source is open for customization and porting[5]. 1.1.1 Open Source Android was built from the ground-up to enable developers to create compelling mobile applications that take full advantage of all a handset has to offer [5]. It was built to be truly open. For example, an application can call upon any of the phone’s core functionality such as making calls, sending text messages, or using the camera, allowing developers to create richer and more cohesive experiences for users. Android is built on the open Linux Kernel[1][6]. Furthermore, it utilizes a custom virtual machine that was designed to optimize memory and hardware resources in a mobile environment. Android is open source; it can be liberally extended to incorporate new cutting edge technologies as they emerge. The platform will continue to evolve as the developer community works together to build innovative mobile applications[6]. 1.1.2 All applications are created equal Android does not differentiate between the phone’s core applications and third-party applications. They can all be built to have equal access to a phone’s capabilities
  9. 9. Organization Automation Using Android Dept of C.S.E Page 9 providing users with a broad spectrum of applications and services. With devices built on the Android Platform, users are able to fully tailor the phone to their interests[1][5]. They can swap out the phone's home screen, the style of the dialer, or any of the applications. They can even instruct their phones to use their favorite photo viewing application to handle the viewing of all photos [5]. 1.1.3 Breaking down application boundaries Android breaks down the barriers to building new and innovative applications. For example, a developer can combine information from the web with data on an individual’s mobile phone — such as the user’s contacts, calendar, or geographic location — to provide a more relevant user experience [5]. With Android, a developer can build an application that enables users to view the location of their friends and be alerted when they are in the vicinity giving them a chance to connect[6]. 1.1.4 Fast & easy application development Android provides access to a wide range of useful libraries and tools that can be used to build rich applications [6]. For example, Android enables developers to obtain the location of the device, and allows devices to communicate with one another enabling rich peer–to–peer social applications. In addition, Android includes a full set of tools that have been built from the ground up alongside the platform providing developers with high productivity and deep insight into their applications[6].
  10. 10. Organization Automation Using Android Dept of C.S.E Page 10 1.2. Java Socket Programming The term network programming refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network. The package of the J2SE APIs contains a collection of classes and interfaces that provide the low-level communication details, allowing you to write programs that focus on solving the problem at hand [7]. The package provides support for the two common network protocols:  TCP: TCP stands for Transmission Control Protocol, which allows for reliable communication between two applications. TCP is typically used over the Internet Protocol, which is referred to as TCP/IP.  UDP: UDP stands for User Datagram Protocol, a connection-less protocol that allows for packets of data to be transmitted between applications. 1.2.1 Socket Programming Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server. When the connection is made, the server creates a socket object on its end of the communication. The client and server can now communicate by writing to and reading from the socket. The class represents a socket, and the class provides a mechanism for the server program to listen for clients and establish connections with them [7]. The following steps occur when establishing a TCP connection between two computers using sockets:  The server instantiates a ServerSocket object, denoting which port number communication is to occur on.  The server invokes the accept() method of the ServerSocket class. This method waits until a client connects to the server on the given port.  After the server is waiting, a client instantiates a Socket object, specifying the server name and port number to connect to.
  11. 11. Organization Automation Using Android Dept of C.S.E Page 11  The constructor of the Socket class attempts to connect the client to the specified server and port number. If communication is established, the client now has a Socket object capable of communicating with the server.  On the server side, the accept() method returns a reference to a new socket on the server that is connected to the client's socket. After the connections are established, communication can take place using I/O streams. Each socket has both an OutputStream and an InputStream. The client's OutputStream is connected to the server's InputStream, and the client's InputStream is connected to the server's OutputStream.TCP is a two-way communication protocol, so data can be sent across both streams at the same time. There are following useful classes providing complete set of methods to implement sockets. 1.2.2 ServerSocket Class Methods The class is used by server applications to obtain a port and listen for client requests[8]. The ServerSocket class has four constructors: SN Methods with Description 1 public ServerSocket(int port) throws IOException Attempts to create a server socket bound to the specified port. An exception occurs if the port is already bound by another application. 2 public ServerSocket(int port, int backlog) throws IOException Similar to the previous constructor, the backlog parameter specifies how many incoming clients to store in a wait queue. 3 public ServerSocket(int port, int backlog, InetAddress address) throws IOException Similar to the previous constructor, the InetAddress parameter specifies the local IP address to bind to. The InetAddress is used for servers that may have multiple IP addresses, allowing the server to specify which of its IP addresses to accept client requests on 4 public ServerSocket() throws IOException Creates an unbound server socket. When using this constructor, use the bind() method when you are ready to bind the server socket Table 2.1 ServerSocket Class constructors
  12. 12. Organization Automation Using Android Dept of C.S.E Page 12 If the ServerSocket constructor does not throw an exception, it means that your application has successfully bound to the specified port and is ready for client requests[8]. Here are some of the common methods of the ServerSocket class: SN Methods with Description 1 public int getLocalPort() Returns the port that the server socket is listening on. This method is useful if you passed in 0 as the port number in a constructor and let the server find a port for you. 2 public Socket accept() throws IOException Waits for an incoming client. This method blocks until either a client connects to the server on the specified port or the socket times out, assuming that the time-out value has been set using the setSoTimeout() method. Otherwise, this method blocks indefinitely 3 public void setSoTimeout(int timeout) Sets the time-out value for how long the server socket waits for a client during the accept(). 4 public void bind(SocketAddress host, int backlog) Binds the socket to the specified server and port in the SocketAddress object. Use this method if you instantiated the ServerSocket using the no-argument constructor. Table 2.2 Methods of the ServerSocket When the ServerSocket invokes accept(), the method does not return until a client connects. After a client does connect, the ServerSocket creates a new Socket on an unspecified port and returns a reference to this new Socket. A TCP connection now exists between the client and server, and communication can begin.
  13. 13. Organization Automation Using Android Dept of C.S.E Page 13 1.2.3 Socket Class Methods The class represents the socket that both the client and server use to communicate with each other. The client obtains a Socket object by instantiating one, whereas the server obtains a Socket object from the return value of the accept() method[8]. The Socket class has five constructors that a client uses to connect to a server: SN Methods with Description 1 public Socket(String host, int port) throws UnknownHostException, IOException. This method attempts to connect to the specified server at the specified port. If this constructor does not throw an exception, the connection is successful and the client is connected to the server. 2 public Socket(InetAddress host, int port) throws IOException This method is identical to the previous constructor, except that the host is denoted by an InetAddress object. 3 public Socket(String host, int port, InetAddress localAddress, int localPort) throws IOException. Connects to the specified host and port, creating a socket on the local host at the specified address and port. 4 public Socket(InetAddress host, int port, InetAddress localAddress, int localPort) throws IOException. This method is identical to the previous constructor, except that the host is denoted by an InetAddress object instead of a String 5 public Socket() Creates an unconnected socket. Use the connect() method to connect this socket to a server. Table 2.3 Socket class constructors
  14. 14. Organization Automation Using Android Dept of C.S.E Page 14 When the Socket constructor returns, it does not simply instantiate a Socket object but it actually attempts to connect to the specified server and port. Some methods of interest in the Socket class are listed here. Notice that both the client and server have a Socket object, so these methods can be invoked by both the client and server[8]. SN Methods with Description 1 public void connect(SocketAddress host, int timeout) throws IOException This method connects the socket to the specified host. This method is needed only when you instantiated the Socket using the no-argument constructor. 2 public InetAddress getInetAddress() This method returns the address of the other computer that this socket is connected to. 3 public int getPort() Returns the port the socket is bound to on the remote machine. 4 public int getLocalPort() Returns the port the socket is bound to on the local machine. 5 public SocketAddress getRemoteSocketAddress() Returns the address of the remote socket. 6 public InputStream getInputStream() throws IOException Returns the input stream of the socket. The input stream is connected to the output stream of the remote socket. 7 public OutputStream getOutputStream() throws IOException Returns the output stream of the socket. The output stream is connected to the input stream of the remote socket 8 public void close() throws IOException Closes the socket. Table 2.4 Methods of Socket Class
  15. 15. Organization Automation Using Android Dept of C.S.E Page 15 1.2.4 InetAddress Class Methods This class represents an Internet Protocol (IP) address. Here are following useful methods which you would need while doing socket programming[8]: SN Methods with Description 1 static InetAddress getByAddress(byte[] addr) Returns an InetAddress object given the raw IP address . 2 static InetAddress getByAddress(String host, byte[] addr) Create an InetAddress based on the provided host name and IP address. 3 static InetAddress getByName(String host) Determines the IP address of a host, given the host's name. 4 String getHostAddress() Returns the IP address string in textual presentation. 5 String getHostName() Gets the host name for this IP address. 6 static InetAddress InetAddress getLocalHost() Returns the local host. 7 String toString() Converts this IP address to a String. Table 2.5 InetAddress Class methods
  16. 16. Organization Automation Using Android Dept of C.S.E Page 16 1.3 Port Forwarding in Router Port forwarding or port mapping is a name given to the combined technique of: 1. Translating the address and/or port number of a packet to a new destination 2. Possibly accepting such packet(s) in a packet filter (firewall) 3. Forwarding the packet according to the routing table. The destination may be a predetermined network port (assuming protocols like TCP and UDP, though the process is not limited to these) on a host within a NAT- masqueraded, typically private network, based on the port number on which it was received at the gateway from the originating host. The technique is used to permit communications by external hosts with services provided within a private local area network[9]. Fig.2.1. Setting up of Port Forwarding
  17. 17. Organization Automation Using Android Dept of C.S.E Page 17 1.3.1 From Inside of Your Network Here’s a map of a simple home network. As you can see, you’ve got three computers with unique IP addresses all connected to a router. You can easily access the other computers, but when they all access the internet, they go through the router. The router has an IP address that’s relative for you network, but it also has an external IP, one that it uses when interacting with things outside of your network. Whenever these computers make a request towards the internet, they all use the same IP – in our example. Simple requests, such as loading web sites, are automatically handled by the router and are sent to their appropriate places. It’s not too difficult because each computer starts with a unique request, so it’s not hard for the router to figure out where things should go[9]. 1.3.2 Ports and Protocols Ports help make this process easier. If an IP is like a building’s address, then ports are like the apartment numbers for the residences in the building. Lower numbered ports have specific applications which are standards throughout the computing industry. When Fig.2.2. Simple home network
  18. 18. Organization Automation Using Android Dept of C.S.E Page 18 you fetch a web page, for example, it uses port 80. The receiving computer’s software knows that port 80 is used for serving http documents, so it listens there and responds accordingly. If you send an http request over a different port – say, 143 – the web server won’t recognize it because it’s not listening there, although something else might be. Each port can be used via either TCP or UDP. TCP, or Transmission Control Protocol, is what’s used most commonly. UDP, or User Datagram Protocol, is less widely used in home applications with one major exception: Bit Torrent. Depending on what is listening, it’ll be expecting requests to be made in either one or the other of these protocols[9]. 1.3.3 From Outside Your Network Now let’s take a look at what happens when a device outside of the network starts a request. Fig.2.3. External device sending request to a network
  19. 19. Organization Automation Using Android Dept of C.S.E Page 19 Let’s say you’re out and about and want to access a file on your network. Your computer makes a request to your home network’s IP,, which then goes to your router. Your router doesn’t know which computer to send it to[9]. We can configure our router to forward ports. This means that depending on the port number that the request is sent over; the router can pass it along to different IP addresses. So in this example, when you’re out and about and using your laptop, you use different ports to make your requests. When you access your home network’s IP address using port 22, your router at home knows that this should go to inside the network. At the same time, you can make a request over port 80, which your router will send to the web server at Or, you can try to remotely control your sister’s laptop with VNC, and your router will connect you to it at[9]. Fig.2.4. Configuring router for Port Forwarding
  20. 20. Organization Automation Using Android Dept of C.S.E Page 20 You can even tell the router to change ports. For example, let’s say you have two web servers[9]. When you access your home network via the standard port, 80, you can tell your router to send it to The web server there will be listening at port 80 and will respond accordingly. But, you can tell your router that when you access it via port 10,000, that it should go to another computer,, but also at port 80. This way, the second computer doesn’t have to be reconfigured to use a different port, but you can still manage traffic effectively[9]. Fig.2.5. Configuring Port Forwarding with two web servers
  21. 21. Organization Automation Using Android Dept of C.S.E Page 21 1.4 Atmel ATMega16 Microcontroller The high-performance, low-power Atmel 8-bit AVR RISC-based microcontroller combines 16KB of programmable flash memory, 1KB SRAM, 512B EEPROM, an 8- channel 10-bit A/D converter, and a JTAG interface for on-chip debugging. The device supports throughput of 16 MIPS at 16 MHz and operates between 4.5-5.5 volts. By executing instructions in a single clock cycle, the device achieves throughputs approaching 1 MIPS per MHz, balancing power consumption and processing speed. ATmega16 is a 40 pin microcontroller. There are 32 I/O (input/output) lines which are divided into four 8-bit ports designated as PORTA, PORTB, PORTC and PORTD. ATmega16 has various in-built peripherals like USART, ADC, Analog Comparator, SPI, JTAG etc. Each I/O pin has an alternative task related to in-built peripherals[2][10]. 1.4.1 ATMega16 I/O Ports ATMega16 has 32 I/O lines, that means it has 4 I/O ports(A,B,C,D).Every I/O port has 3 registers associated with each ports. These three registers are:  DDRx(data direction register)  PINx  PORTx x = A, B, C, D. A. DDRx (DATA DIRECTION REGISTER): This register configures data direction of port pins , means by using this register microcontroller decides whether this port will be used as input port or output port. In 8051 if we will declare any port as FF it becomes input port but in ATMega it is opposite if we declare FF it becomes output port[2][10]. E.g. To make all pins of port D as input pins DDRD=0b00000000 If we want to make first 4 pins of port C as input and remaining 4 as output then
  22. 22. Organization Automation Using Android Dept of C.S.E Page 22 DDRC=0b00001111 B. PINx register: PIN (port IN) used to read data from port pins. E.g. To read data from port A DDRA=0b00000000 Y = PINA // data from port A will be stored in variable Y. C. PORTx register: PORTx is used for two purpose- To O/P data: When port is configured as output i.e. when corresponding bits in DDR is set DDRA=0b11111111 x=0b10101010 PORTA=x // now content of port A will be AA To activate or deactivate pull up registers: When you configure a port as input port and pull up is enabled, it will be in input mode which is default. So, even if you don’t connect anything to the pin and if you try to read it, it will read as 1. Now, when you drive pin to zero, only then it will read as 0[2]. E.g. To make port A as I/P with pull-up enable DDRA=0b00000000 PORTA=0b11111111 y=PINA To make port A as tri-stated I/P DDRA=0b00000000 PORTA=0b00000000
  23. 23. Organization Automation Using Android Dept of C.S.E Page 23 1.4.2 ATMega16 Serial Communication using USART (Universal Synchronous / Asynchronous Receiver/Transmitter) There are two methods for serial data communication Synchronous and Asynchronous communication. In Synchronous communication method complete block (characters) is sent at a time. It doesn’t require any additional bits (start, stop or parity) to be added for the synchronization of frame. The devices are synchronized by clock. And in asynchronous communication data transmission is done byte by byte i.e., one byte at a time. The additional bits are added to complete a frame. In synchronous communication the frame consists of data bits while in asynchronous communication the total number of bits in a frame may be more than the data bits[10]. Fig.2.6. Data frame Serial USART provides full-duplex communication between the transmitter and receiver. Atmega16 is equipped with independent hardware for serial USART communication[2]. Pin-14 (RXD) and Pin-15 (TXD) provide receive and transmit interface to the microcontroller. Fig.2.7. USART pins in ATMega16
  24. 24. Organization Automation Using Android Dept of C.S.E Page 24 Atmega16 USART provides asynchronous mode of communication and do not have a dedicated clock line between the transmitting and receiving end. The synchronization is achieved by properly setting the baud rate, start and stop bits in a transmission sequence. Start bit and stop bit: These bits are use to synchronize the data frame. Start bit is one single low bit and is always given at the starting of the frame, indicating the next bits are data bits. Stop bit can be one or two high bits at the end of frame, indicating the completion of frame[10]. Baud Rate: In simple words baud rate is the rate at which serial data is being transferred. Atmega16 USART has following features: · Different Baud Rates. · Variable data size with options ranging from 5bits to 9bits. · One or two stop bits. · Hardware generated parity check. · USART can be configured to operate in synchronous mode. · Three separate interrupts for RX Complete, TX complete and TX data register empty. To use the USART of Atmega16, certain registers need to be configured: UCSR: USART control and status register. It’s is basically divided into three parts UCSRA, UCSRB and UCSRC. These registers are basically used to configure the USART. UBRR: USART Baud Rate Registers. Basically use to set the baud rate of USART UDR: USART data register Fig.2.8. Equation for one data frame
  25. 25. Organization Automation Using Android Dept of C.S.E Page 25 1) UCSRA: (USART Control and Status Register A) RXC (USART Receive Complete): RXC flag is set to 1 if unread data exists in receive buffer, and set to 0 if receive buffer is empty. TXC (USART Transmit complete): TXC flag is set to 1 when data is completely transmitted to Transmit shift register and no data is present in the buffer register UDR. UDRE (USART Data Register Empty): This flag is set to logic 1 when the transmit buffer is empty, indicating it is ready to receive new data. UDRE bit is cleared by writing to the UDR register. 2) UCSRB: (USART Control and Status Register B) RXCIE: RX Complete Interrupt Enable, When 1 - RX complete interrupt is enabled. When 0 - RX complete interrupt is disabled. TXCIE: TX Complete Interrupt Enable, When 1 - TX complete interrupt is enabled When 0 - TX complete interrupt is disabled Fig.2.9. UCSRA Register Fig.2.10. UCSRB Register
  26. 26. Organization Automation Using Android Dept of C.S.E Page 26 UDRIE: USART Data Register Empty Interrupt Enable, When 1 - UDRE flag interrupt is enabled. When 0 - UDRE flag interrupt is disabled. RXEN: Receiver Enabled, When 1 - USART Receiver is enabled. When 0 - USART Receiver is disabled. TXEN: Transmitter Enabled, When 1 - USART Transmitter is enabled. When 0 - USART Transmitter is disabled. 3) UCSRC: (USART Control and Status Register C) The transmitter and receiver are configured with the same data features as configured in this register for proper data transmission. URSEL: USART Register select. This bit must be set due to sharing of I/O location by UBRRH and UCSRC UMSEL: USART Mode Select, When 1 - Synchronous Operation When 0 - Asynchronous Operation Fig.2.11. UCSRC Register
  27. 27. Organization Automation Using Android Dept of C.S.E Page 27 UPM[0:1]: USART Parity Mode, Parity mode selection bits. USBS: USART Stop Select Bit, When 0-> 1 Stop Bit When 1 -> 2 Stop Bits UCSZ[0:1]: The UCSZ[1:0] bits combined with the UCSZ2 bit in UCSRB sets size of data frame i.e., the number of data bits. The table shows the bit combinations with respective character size. UCSZ2 UCSZ1 UCSZ0 Character Size 0 0 0 5-bit 0 0 1 6-bit 0 1 0 7-bit 0 1 1 8-bit 1 0 0 Reserved 1 0 1 Reserved 1 1 0 Reserved 1 1 1 9-bit Table 2.6 UCSZ[0:1] initializations 4) UDR: (USART Data Register) The USART Data receive and data transmit buffer registers share the same address referred as USART UDR register, when data is written to the register it is written in transmit data buffer register (TXB). Received data is read from the Receive data buffer register (RXB). Fig.2.12. UDR Register
  28. 28. Organization Automation Using Android Dept of C.S.E Page 28 5) UBRRH & UBRRL (USART Baud Rate Registers) The UBRRH register shares the same I/O address with the UCSRC register, the differentiation is done on the basis of value of URSEL bit. When URSEL=0; write operation is done on UBRRH register. When URSEL=1; write operation is done on UCSRC register. The UBRRH and UBRRL register together stores the 12-bit value of baud rate, UBRRH contains the 4 most significant bits and UBRRL contains the other 8 least significant bits. Baud rates of the transmitting and receiving bodies must match for successful communication to take place[10]. Fig.2.13.UBRR Register
  29. 29. Organization Automation Using Android Dept of C.S.E Page 29 Chapter 2 Introduction 2.1. Objective Our project enables the user to control and monitor the electrical loads in an organization. Through the Graphical User Interface (GUI) provided by the Android application, the user is able to monitor and switch the electrical loads. This process will be achieved using Internet. The Android application is user friendly and easy to understand. 2.2. Modules In this project, we are making use of four modules which themselves will describe what we intend to do. The modules are:  Module 1: Android application.  Module 2: Communication between Android application and router.  Module 3: Communication between router and embedded system.  Module 4: Embedded system. 2.3. Basics The user sets and enters his username and password to enter the android application. After proper authentication, the user selects a particular room in the organization. From here the user will be able to view the status and control the electrical loads. The Android application sends a specific signal over the internet to the router via Domain Name System (DNS). The router forwards the received signal to the embedded system via port forwarding. The embedded system receives the signal and switches the state of the corresponding relay. The same is reflected on the respective electrical load. The various modules of the system are:
  30. 30. Organization Automation Using Android Dept of C.S.E Page 30 The first module is the Android application that provides a GUI and authentication of the user. Using this, user sends a signal to switch the state of an electrical load. The second module manages the communication between the android application and the router. This is done via DNS Server as the router does not have a static Internet Protocol (IP). The third module deals with communication between the router and the embedded system. This is established using port forwarding facility provided by the router. The fourth and the last module is the embedded system which receives the signal from the router and switches the corresponding relay which in turn switches the load. 2.4. Problem Definition To build an automation system that comprises of an embedded system and an Android application. The Android application will control the embedded system by sending messages through Internet using GPRS or Wi-Fi. The Embedded System will in turn switch ON/OFF the electrical load and send an acknowledgement to the user. The communication between the Embedded System and the application is intermediated through a router. The concept of Port Forwarding is used here. Thus remote access to any electrical appliance in an organization can be achieved. 2.5. Software Requirement Specification  Languages used: AVR Studio 4, Java and Android SDK.  Platform (OS): Any Android Smartphone with Android version 2.1 +. The Android Smartphone should support API version 14 to support switch widget in the GUI. 2.6. Hardware Requirement Specification  Components: AVR Development Board with ATMega16 microcontroller, Ethernet to Serial converter, Relay circuit.
  31. 31. Organization Automation Using Android Dept of C.S.E Page 31 2.7. Scope The user can access the electrical loads of his organization remotely. The automation required can be customized as per the requirement of the organization.
  32. 32. Organization Automation Using Android Dept of C.S.E Page 32 Chapter 3 Use-Case Diagram & Sequence Diagram 3.1. Use-Case Diagram The use-case diagram is as given below: Fig.3.1. Use Case diagram After proper authentication the user can act as a client and requests the services provided by the embedded system, which acts as server. The user interacts with the Android application to select a room or a sector of the organization and changes the state of the electrical load. The application generates a signal and transmits the message over internet using GPRS or Wi-Fi. The message is received by a router at the organization. The router forwards the message to appropriate port using Port Forwarding. The forwarded message is converted into serial data by an Ethernet-to-Serial converter. This serial data is
  33. 33. Organization Automation Using Android Dept of C.S.E Page 33 received by the microcontroller of the core system using USART (Universal Synchronous/Asynchronous Receiver/Transmitter). The microcontroller changes the logic state of the selected electrical load with the help of a relay module. Thus the electrical load is switched ON/OFF and the user is provided with an appropriate acknowledgement. Hence automation can be obtained remotely. 3.2. Sequence Diagram The Sequence diagram describing the working of the system is given below and is self-explanatory. Fig.3.2. Sequence diagram
  34. 34. Organization Automation Using Android Dept of C.S.E Page 34 Chapter 4 System Design 4.1. Dataflow Model The Dataflow model of the system is given below: A simplified working of the system is explained through the dataflow diagram. The only data in the system is the signal and acknowledgements. After authentication, the user enters the Android application. At this moment, the application retrieves the current IP of the router at the organization through DNS server. After selecting a specific room, the application generates a signal to receive the current state of the electrical loads in that room and the same is reflected in the application. Then, the user toggles the state of any load of that room shown in the application. This generates a signal which is transmitted over the Internet using TCP to the specified router IP. The router receives the data and forwards it to the system. The data is converted into serial data by the Ethernet-Serial Fig.4.1.Dataflow Model
  35. 35. Organization Automation Using Android Dept of C.S.E Page 35 converter (refer Appendix A). The controller reads the serial data and changes the state of the corresponding load. After the action, the controller generates an acknowledgement and the same is converted into TCP from serial and transmitted back to the user. This is how the data in the system undergoes conversion and traverses from the user to the system and vice versa. 4.2. Hardware Design  Power Supply Socket: This power supply socket which actually named as AC/DC Socket provides the functionality to user to connect external power supply from Transformer, Battery or Adapter via DC jack. User can provide maximum of 15V AC/DC power supply through AC/DC socket. This is power supply designed into maximum protection consideration so that it can even prevent reverse polarity DC power supply as well as AC power Supply. It also includes 7805 Voltage Regulator which provides regulated 5V DC for Microcontroller and other I/O connectors. Fig.4.2. AVR Development Board
  36. 36. Organization Automation Using Android Dept of C.S.E Page 36  GND, VCC and VIN Connector: This board also provides user to have an extra pins for Power supplies as shown in figure. These pins are GND (0V), VCC (5V from Voltage Regulator) and VIN (Voltage supplied to AC/DC Socket minus 1.4V denoted as +12V on board). Four pins are provided for each type of supply. User can connect these pins to external device by using Single Berg Wire.  On/Off Switch and Reset Switch: On/Off switch is type of Push on – push off DPDT switch which is used for only make power supply on/off provided through AC/DC Socket. Reset Switch is type of Push on DPST tactile switch which is used as program reset.  10 pin Box Header Connector: Pin Headers with plastic guide box around them are known as “Box Headers” or “Shrouded Headers” and are normally only used in combination with a Flat Ribbon Cable (FRC) connector. A notch (key) in the guide box normally prevents placing the connector the wrong way around. Box Header can be connected using FRCs connections. Fig.4.3. VCC, GND and VIN connector Fig.4.4. On/Off and Reset switch Fig4.5.Box Header Fig.4.6. Box header
  37. 37. Organization Automation Using Android Dept of C.S.E Page 37  A, B, C and D Port Connector: 40 pin ATMega series microcontroller has four I/O ports generally. These Four Port are expanded from Microcontroller IC separately by using 10 pin Box Header for each port (A, B, C and D port). Among 10 pins 8 pins represents I/O pin of respective port and 9th & 10th pin represents GNDand VCC respectively. This is shown in figure.  LED Connector: Eight LEDs used for I/O testing are connected in common cathode configuration. Other terminal (anode) of LED connected to the LED port. This LED port can be directly connected to any of A, B, C or D port's Box Header through Flat Ribbon Cable(FRC). Fig4.7. Port A header Fig.4.8. LED connector
  38. 38. Organization Automation Using Android Dept of C.S.E Page 38  ISPConnector: ISP (In System Programming) port provides connection between AVR Development Board and AVR Programmer Kit. It has following configuration. It also used as a power supply from USB (Universal Serial Bus) Cable. As this functionality provided by Microcontroller IC itself, thus pins are directlyconnected to respectivepins. Fig.4.9. ISP Port
  39. 39. Organization Automation Using Android Dept of C.S.E Page 39 4.3. Android application development design The diagram for android application development given below explains all the stages of application development stepwise. Fig.4.10. Android Application Development Flow
  40. 40. Organization Automation Using Android Dept of C.S.E Page 40 Chapter 5 Implementation 5.1. AVR Programming: The code follows: #include<avr/io.h> #include<compat/deprecated.h> #include<avr/delay.h> #include<stdlib.h> #define BIT0 0b00000001; #define BIT1 0b00000010; //Initialize USART void USART_Init() { /* Set baud rate */ UBRRH = 0; UBRRL = 51; /* Enable receiver and transmitter */ UCSRB|= (1<<RXEN)|(1<<TXEN); /* Set frame format: 8data---ucsz0=1,ucsz1=1, 1stop bit ---usbs=0*/ UCSRC|= (1 << URSEL)|(3<<UCSZ0); } //Transmission void USART_Transmit( unsigned char data ) { /* Wait for empty transmit buffer */ while ( !( UCSRA & (1<<UDRE)) ); /* Put data into buffer, sends the data */ UDR = data; }
  41. 41. Organization Automation Using Android Dept of C.S.E Page 41 //Reception unsigned char USART_Receive( void ) { while (!(UCSRA & (1 << RXC)) ); // Do nothing until data have been received and is ready to be read from UDR return UDR; } void main() { DDRA=255; USART_Init(51); //4800 buad rate while(1) { unsigned char data = USART_Receive(); if(data=='a') { PORTA|=BIT0; //PORT A turns ON the relay USART_Transmit('a'); //ACK is sent } if(data=='b') { PORTA&=~BIT0; //PORT A turns OFF the relay USART_Transmit('b'); //ACK is sent } if(data=='c') { PORTA|=BIT1; //PORT B turns ON the relay USART_Transmit('c'); //ACK is sent } if(data=='d') { PORTA&=~BIT1; //PORT B turns OFF the relay USART_Transmit('d'); //ACK is sent } } }
  42. 42. Organization Automation Using Android Dept of C.S.E Page 42 5.2. Android Application: The Android application contains 5 activities: 5.2.1. This is the activity screen we get when we start the application for the first time after installation. It follows the following algorithm: STEP-1: Accept username from the text field. STEP-2: Store the username in SHARED PREFFERENCES. STEP-3: Navigate to next screen The code snippet is: void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); acceptUsernameBtn = (Button) findViewById(; usernameEt = (EditText) findViewById(; acceptUsernameBtn.setOnClickListener(this); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String username = preferences.getString("username", null); String password = preferences.getString("password", null); Log.e("user and password", "" + username + " " + password); if (username != null && password != null) { Intent j = new Intent(FirstActivity.this, LoginActivity.class); startActivity(j); finish(); } } Public void onClick(View arg0) { if (arg0.getId() == { saveUserNameToSharedPrefs(); Toast.makeText(FirstActivity.this, "Username Saved Successfully", Toast.LENGTH_SHORT).show(); Intent i = new Intent(FirstActivity.this, PasswordActivity.class); startActivity(i); } }
  43. 43. Organization Automation Using Android Dept of C.S.E Page 43 5.2.2. This activity is generated after the UsernameActivity. Here we store the password given as input by the user. The algorithm follows: STEP-1: Accept password from the text field. STEP-2: Store the password in SHARED PREFFERENCES. STEP-3: Navigate to the next screen. The code snippet is: void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); acceptPasswordBtn = (Button)findViewById(; passwordEt = (EditText)findViewById(; acceptPasswordBtn.setText("Get Password"); passwordEt.setHint("Please enter password"); acceptPasswordBtn.setOnClickListener(this); } public void onClick(View arg0) { if(arg0.getId() == { savePasswordToSharedPrefs(); Toast.makeText(PasswordActivity.this, "Password Saved Successfully", Toast.LENGTH_SHORT).show(); Intent j = new Intent(PasswordActivity.this, LoginActivity.class); startActivity(j); } } private void savePasswordToSharedPrefs() { SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(this); SharedPreferences.Editor editor = preferences.edit(); Log.e("password in passwordactivity", passwordEt.getText().toString()); editor.putString("password", passwordEt.getText().toString()); editor.commit(); }
  44. 44. Organization Automation Using Android Dept of C.S.E Page 44 5.2.3. This activity is the start screen for after-installation run. It authenticates the user by the earlier stored username and password. The algorithm is: STEP-1: Check if the username and password is not NULL in SHARED PREFFERENCES. STEP-2: If username and password are not stored in SHARED PREFFERENCES start the STEP-3: Else take input for username and password. STEP-4: Verify the data fields with the data stored in SHARED PREFFERENCES. The code snippet is: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); username = (EditText) findViewById(; password = (EditText) findViewById(; login = (Button) findViewById(; login.setOnClickListener(this); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); usernameStored = preferences.getString("username", null); passwordStored = preferences.getString("password", null); Log.e("user and password in login activity", "" + usernameStored + " " + passwordStored); } public void onClick(View arg0) { if (arg0.getId() == { if (username.getText().toString().equals(usernameStored) && password.getText().toString().equals(passwordStored)) { Toast.makeText(getApplicationContext(), "Login Successfully !!!", Toast.LENGTH_LONG).show(); Intent intent = new Intent(LoginActivity.this,
  45. 45. Organization Automation Using Android Dept of C.S.E Page 45 ConnectActivity.class); startActivity(intent); } else Toast.makeText(getApplicationContext(), "Login Not Successful !!!", Toast.LENGTH_LONG).show(); } } } 5.2.4. This activity is the Main Activity i.e. it is the home activity of the application. Here the user is provided buttons to choose the room to switch the state of an electrical load in the room. The algorithm is: STEP-1: Provide the interface consisting of buttons. STEP-2: Navigate to the respective room activity that the user has choosen. The code snippet is: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void navigate1(View view) { Intent intent = new Intent(this, Navigate1Activity.class); startActivity(intent); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(, menu); return true; }
  46. 46. Organization Automation Using Android Dept of C.S.E Page 46 5.2.5. This activity provides an interface containing switches that resemble the actual loads in the room. Its function is to record current statues, sends signals and waits for acknowledgements. The algorithm is: STEP-1: Update the current statues of the loads in the room. STEP-2: Create a socket and send the signal to turn on/off any load when selected by the user. STEP-3: Wait for the acknowledgement and then reflect the change in the application. The code snippet is: void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigate1); swit1 = (Switch)findViewById(; swit2 = (Switch)findViewById(; swit3 = (Switch)findViewById(; swit1.setOnClickListener(this); swit2.setOnClickListener(this); swit3.setOnClickListener(this); } public void onClick(final View v) { Thread t = new Thread (new Runnable() { public void run() { try { InetAddress serverAddr = InetAddress.getByName(""); client = new Socket(serverAddr,100); printwriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())), true); printwriter.println(msg1);
  47. 47. Organization Automation Using Android Dept of C.S.E Page 47 switch(v.getId()) { case printwriter.println(msg1); break; case printwriter.println(msg2); break; case printwriter.println(msg3); break; } printwriter.close(); client.close(); } catch (UnknownHostException e) { Toast.makeText(getApplicationContext(), "Host Exception", Toast.LENGTH_LONG).show(); } catch (IOException e) { Toast.makeText(getApplicationContext(), "IO Exception", Toast.LENGTH_LONG).show(); } } }
  48. 48. Organization Automation Using Android Dept of C.S.E Page 48 Chapter 6 Results 6.1 Snapshots of the Android application: When the application is installed for the first time, the activity to accept username appears. Fig.6.1. Username Activity
  49. 49. Organization Automation Using Android Dept of C.S.E Page 49 The activity to accept password in its first run follows. Fig.6.2. Password Activity
  50. 50. Organization Automation Using Android Dept of C.S.E Page 50 If the username and password is stored in its first run, the application begins with login activity. Fig.6.3. Password Saved Toast
  51. 51. Organization Automation Using Android Dept of C.S.E Page 51 The application matches the username and password entered by the user with the one stored in shared preferences during the first run. Fig.6.4. Login activity
  52. 52. Organization Automation Using Android Dept of C.S.E Page 52 If the entered username and password doesn’t match it stays in the same activity and displays “Login not successful”. Fig.6.5. Login Activity – unsuccessful login
  53. 53. Organization Automation Using Android Dept of C.S.E Page 53 After valid login the application enters its main activity which is the home page. The user selects desired room here. Fig.6.6. Main Activity
  54. 54. Organization Automation Using Android Dept of C.S.E Page 54 The application navigates into selected room. Fig.6.7. Navigate Activity
  55. 55. Organization Automation Using Android Dept of C.S.E Page 55 The application checks for connectivity prior to enable the user to switch the state of the load. Also it retrieves the current state of the load. Fig.6.8. Navigate activity - Connecting
  56. 56. Organization Automation Using Android Dept of C.S.E Page 56 After the connectivity check, the user can switch the state of any load in the room. Fig.6.9. Navigate Activity – Switch On/Off
  57. 57. Organization Automation Using Android Dept of C.S.E Page 57 6.2. Snapshot of the embedded system: The complete embedded system connected to a router. Fig.6.10. Embedded System with Router
  58. 58. Organization Automation Using Android Dept of C.S.E Page 58 Chapter 7 Conclusion and Future Improvements It was interesting experience to work on the latest technology like Android and merge its application to an automation embedded system. This establishes a new prototype and a benchmark of one of a kind application. We are happy to say that our project i.e. “Organization Automation using Android” is successfully completed. The working of the established system is flawless and as desired. All the four modules discussed earlier were developed with great care using trusted third party facilities like DNS and technical support like JAVA programming. The application reserves user’s identity to avoid unauthorized access and efficient acknowledgement transmission over internet secures proper implementation of user inputs. To sum up, the established prototype provides application programmed switches in an organization. The main functionality of the system to automate an organization remotely is tested and perfectly working. This project can be extended to work on iOS and Windows-OS Smartphones in the future. Some of the other future enhancements can be:  Adding the facility of scheduled switching using functions of Android or by adding timer circuits.  Heavy loads like Air Conditioner can also be handled through application.  Automation can be extended as per the user’s need  More secured system by continuously ping to the router for the system status.  Integrating sensors like light sensors and water-leak sensors.  Integrating CCTV surveillance.
  59. 59. Organization Automation Using Android Dept of C.S.E Page 59 APPENDIX A DATA SHEET FOR ETHERNET TO SERIAL CONVERTER MODEL SC10TK
  60. 60. Organization Automation Using Android Dept of C.S.E Page 60 Bibliography [1] Donn Felker, Android Application Development for Dummies, Paperback, 1st Edition December 2010, ISBN: 978-0-470-77018-4. [2] Steven Steven Frank Barrett, Daniel J. Pack, Atmel AVR microcontroller primer: programming and interfacing, Morgan & Claypool Publishers, 2008. [3] R.Piyare, M.Tazil, “ Bluetooth Based Home Automation System Using Cell Phone,” 2011 IEEE 15th International Symposium on Consumer Electronics. [4] Muhammad Izhar Ramli, Mohd Helmy Abd Wahab, Nabihah, “TOWARDS SMART HOME: CONTROL ELECTRICAL DEVICES ONLINE,” Nornabihah Ahmad International Conference on Science and Technology: Application in Industry and Education (2006) [5] [6] [7] Elliot Rusty Harold, Java Network Programming, O'Reilly Media, Inc., 09-Feb- 2009. [8] [9] [10]