S14: Android based Automation

From Embedded Systems Learning Academy
Revision as of 00:22, 23 May 2014 by Proj user6 (talk | contribs) (Schedule)

Jump to: navigation, search

Grading Criteria

  • How well is Software & Hardware Design described?
  • How well can this report be used to reproduce this project?
  • Code Quality
  • Overall Report Quality:
    • Software Block Diagrams
    • Hardware Block Diagrams
      Schematic Quality
    • Quality of technical challenges and solutions adopted.

Project Title

ANDROID BASED AUTOMATION

Abstract

This project is to develop an Android application which can be used to switch an electrical appliance On/Off, and notify the status to the user through his mobile device. Here we connect an Android Application running device to the SJSU One board using Bluetooth protocol and make the board detect the signals coming from the Android device via a Bluetooth module. This board generates operation in according to the incoming signals.

Objectives & Introduction

Show list of your objectives. This section includes the high level details of your project. You can write about the various sensors or peripherals you used to get your project completed.

Team Members & Responsibilities

  • Bhargava Kunchanapalli
    • (Hardware Implementation)
  • Harsha
    • (Android Development)
  • Kiran Vaddey
    • (Device Drivers and FreeRTOS Programming)

Schedule

Date Task Status Notes
2/24 Project Reviewing Completed
3/6 Parts Ordered Completed
3/13 Review Data sheets & Bluetooth module interfacing Completed
3/20 Installation of Android SDK and Designing a blue print of the application Completed
3/27 Android Application development (Continued...) Completed
4/3 Interfacing the mobile application with SJ-One Board using Bluetooth module Completed
4/10 Setup the interface between the SJ-One Board and External Peripherals Completed
4/17 Improving software functionality on Unique Features Completed
4/24 Testing and Debugging Completed
5/1 Testing and Debugging Completed
5/8 Final Demo Pending

Parts List & Cost

Qty Description Total Cost
1 HC - 05 Bluetooth UART Module $10.00
1 SJ One Board $160.00
1 Relay Module $10.00
1 Any Android Phone $0.00
Total Cost 180.00

Design & Implementation

The design section can go over your hardware and software design. Organize this section using sub-sections that go over your design and implementation.

Hardware Design

Electrical Switching Circuitry The electrical switching is done using a circuitry which uses relays to switch the lines. The voltage we handle here is 110V and frequency 60Hz. The transistor used in here produce sufficient current that is approximately 200V with a voltage supply of 9V rather than traditional 5V supply with drives less current when used against SJSU One board and it is used to switch the operation of the relay. The 3.3V supplied by the SJSU One board from the GPIO port is not sufficient to power the relay so the relay control board is been used in this project. As seen below, the circuit consists of a transistor, an LED, and a power supply.

The LED is connected to the control signal to show whether the relay should be turn on or turn off. The transistor acts as a switch to enable and disable the relay depending on the signal received from SJ One board. When the LPC 1768 gets the data frame from the Android application it processes it for signal and pass code where signal is processed in switch_task in our program to act accordingly. The pass code is matched against the codes which are pre assigned to identify the user.


Hardware Interface

UART Bus

The UART bus is used to communicate between Bluetooth device and the microcontroller. UART pins are power on the SJ One board using UART init function API provided by the FreeRTOS. The initialized pins are driven by the UART driver to handle the communication. Each of the UART pin if logic high produce a output voltage of 3.3V and if logic low produce a 0.0V. The SJ One board has a switch between UART-2 & UART-3, to make a selection. If we want to uses both for them then we have to use them as GPIO pins.

GPIO Port

The GPIO port is used to enable or disable the transistor and the indicator LED. When the LPC1768 micro-controller recognizes a pass code that is sent from the Android, it will send 3.3V through the GPIO which is connected to the relay circuit. Above is the GPIO initialization function. We have used port-1 pins that is P0.0 and P0.1 pins to give a 3.3V voltage to the relay circuit board. First the pins need to be selected and then the direction of the pin needs to be specified. For instance an output pin would be set to a 1 while an input would be set to 0.

Software Design

Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code. For example, do not show exact code, but you may show psuedocode and fragments of code. Keep in mind that you are showing DESIGN of your software, not the inner workings of it.

Implementation

Hardware Tasks

Switching Task

This task is the main processing place in this entire program. The task it performs is that it analyses the data received and does the intended action. This task doesn't take any inputs it gets context switched from get_data task when it receives any data into the queue. It waits for the queue item for 300ms and in case if doesn't receive any information on which it can start the process then it send the data frame it received to the other SJ One board connected in this network. Where the other SJ One board does the remaining action. This task when it gets the signal from the get_data task it compares the signal in an if cascade. It records the previous signal and it compares it with the present signal, in case if both the signals are different then it sends a toast of appropriate action to the Android application. The follow of the function is explain in the following diagram.


The snippet of the task is as followed for the clear understanding.


Get Data Task

Get data task is where the data frame is received from the Android application. By using the FreeRTOS API's we receive the data from the UART-3 receive line. The data received is in character then we convert it to the format we needed. Then the pass code is compared against the pre-defined codes, if there is a match then we proceed onto add the signal into the queue. The tasks get context switched because the switch task is with higher priority. Once the data is written into the queue then immediately the switch task starts running, where it receives the signal from the queue. The detailed data flow is as follows.


The snippet of the task is as followed for the clear understanding.


Temperature Task

In this task we read the temperature sensor values and send it via an SPI bus to the 7-segment display to display it. This task sends a toast to the Android application that the temperature in the place where this SJ One board is present. The code snippet is as follows for reference.

Light Sensor Task

This function reads the light sensor values and valuates it to our requirements. This is a Boolean function where it returns where the relay should be switched on or off based on the values presented by the sensor. The function is snippet is as follows.

SOS Task

This task transmits SOS i.e. Save Our Souls which is a help signal in case of emergency. It is transmitted as an alternative pattern of Dots and Dashes i.e. electronically 1's and 0's. This function switches relay alternatively by approximately half a second, then the lights all connected to this network would On and Off in a pattern.

Testing & Technical Challenges

Testing and Debugging The testing for this is project is done on individual tasks like Android application, Bluetooth interface, hardware module and firmware code. Bluetooth interface debugging

Hardware debugging

In hardware integration the main part is to get the enough driving current in all the wires. The SJ One board doesn't produce the 5V which is required by the relay module. The relay module works on the 5V voltage supply and 60mV of minimum current. The SJ One board GPIO pin provides the 1-3mV of current. The current is first amplified by the op-amp and then it is replaced by a transistor which can amplify the current value in a circuit. Now, the voltage is boosted up to 9V which can produce 200mA current is far than sufficient to drive the circuit.

Firmware Code

The code for the LPC1768 processor is written in C++, this code is stored in a flash device provided on the SJ One Board. The code has to be written in such a way that the all tasks have to be inter connected, so we used queues to communicate between the tasks. The priority of the switching task is more so that the program waits for the queue to be filled. The moment the data is queued there would be context switching, which allows the high priority task to get the control. The data is sent by the android application by concatenating signal to the user or code name, so it is packed into a data frame before sending the signal to the SJ One board. The code is verified by connecting it to the computer and observed the data flow. The Hercules is used to display the data and the flow. The screen shots of the observations are as attached below.


My Issue #1

The interfacing of the Bluetooth device has itself posed big challenge for us. The module was not responding to the commands. We tried to make it read the AT commands but the module was not responding. So, after a lot of struggle we figured it out that while sending the AT commands we do not need to send the NULL at the end of the string.

My Issue #2

The Android application will display the toasts after sending the signaling command. These toasts have to be sent by the module as response, but the toasts where scrambled. We tried to send the data by delaying the signal by 300ms but it didn't work. Finally we found that we have to send the data only matching the frequency of toasts. So, we compare the previous data and the present data, where only once the previous and present data are different, so at that time we sent the toast data. It worked.

Conclusion

Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?

Project Video

Upload a video of your project and post the link here.

Project Source Code

Send me your zipped source code and I will upload this to SourceForge and link it for you.

References

Acknowledgement

Any acknowledgement that you may wish to provide can be included here.

References Used

List any references used in project.

Appendix

You can list the references you used.