Chapter 1 Overview
(Author: Xiao Bo QQ463431476)
(Source: http://blog.chinaaet.com/zhaocundang blog)
1.1 Design Background and Significance
The design of the Android IoT system mainly aims to solve the integration of Android mobile phone APP with smart hardware, combining the Internet with household appliances used in daily life. Similar to smart homes, the future development relies heavily on the Internet and the IoT system. A mobile phone can connect to the home network through 4G network, allowing individuals to know everything happening at home even when they are not present. With just a few taps on the mobile phone APP, one can control home appliances such as lamps, fans, water heaters from a distance. If returning home late, one can preemptively turn on the APP to activate the water heater via the Internet. Additionally, it allows for remote monitoring of the home situation, providing more convenience and joy in life. The design of the IoT system APP is geared towards intelligent development, integrating with the IoT to bring convenience and fun to life.
1.2 Design Objectives
(1) Understand and proficiently write Android code, understand the relevant frameworks, the Android development system and operational mechanisms, and configure the Eclipse Android environment.
(2) Use various Android components and be proficient in using various Android controls. This software is based on the Eclipse development environment and employs Activity, Broadcast Receiver, Service components, with the page menu using Navigation Drawer, and each page utilizing Fragment, adapting flexibly to different screen sizes. The home page adopts a grid view layout, utilizing a horizontal layout that allows for horizontal scrolling, enabling quick access to any page, which is quite convenient.
(3) Implement voice recognition control. The project utilizes the iFlytek voice recognition API interface for voice control of appliances and vehicles, offering quick convenience and the function of voice text reading.
(4) Create a minimalist UI design, employing Translucent immersive design to achieve a concise and friendly interface, with flat minimalist round buttons and a convenient navigation drawer, maximizing space efficiency in layout.
(5) Use Socket connections for WIFI to transmit data, primarily transmitting characters to control the high and low level triggering of hardware devices.
(6) Implement various data storage methods: complete SQLite database storage, mainly for storing user login credentials; another lightweight data storage method is share preference, mainly used for temporarily storing WIFI configuration information.
(7) Complete the hardware soldering work, primarily designing the code for the Arduino development board, including the lamp fan USB interface and external power supply interface design, servo connection methods, and camera settings connected to an OpenWrt router, as well as relay soldering and the balance car motor drive module, MPU6050 gyroscope, Arduino master control, motor encoder, and wiring methods for the motors.
Chapter 2 Requirement Analysis
2.1 Functional Requirements
The Android mobile IoT system APP can connect to the home network through 4G network, allowing users to check the specific situation at home, view home surveillance, and remotely control the camera to rotate left or right. Users can also remotely control household appliances such as water heaters, lamps, and fans. Additionally, it can remotely control the smart balance car, enabling forward, backward, left, and right movements.
2.2 Interface Requirements
(1) Login and registration interface
The user login and registration interface is the same, allowing users to log in and register account passwords, which are saved in the SQLite database. Users can log in and register account information at any time, ensuring that the SQLitte database saves account information securely and facilitates maintenance.
(2) Main screen interface
The user main interface allows quick selection of functions, using GridView, achieving horizontal scrolling for a better user experience.
(3) User interface
The user interface mainly displays user information, using TextView to indicate available functions.
(4) Camera interface
The camera interface primarily implements real-time display of surveillance video and controls the camera to rotate left or right.
(5) Network interface
The network interface is mainly used to configure user settings for WIFI addresses, video ports, and control port numbers, facilitating development and maintenance. It uses Share Preference for lightweight data storage, allowing for convenient data saving without needing to re-enter information next time.
(6) Appliance interface
The appliance interface primarily controls the switches for lamps and fans.
(7) Voice interface
Utilizes the iFlytek voice API interface to achieve voice recognition for controlling appliances on and off, as well as for controlling the balance car’s posture.
(8) Vehicle control interface
Primarily implements control for the balance car’s forward, backward, left, and right movements.
Chapter 3 Overview Design
3.1 Design Framework Diagram
The system is mainly divided into 5 major modules: user data module, camera module, network configuration storage module, control module, and voice recognition and voice reading module. The overall system framework diagram is shown in 3.1:
Figure 3.1 System Design Framework
3.2 System Module Framework Diagram Design
(1) User Login/Registration Module Framework
Utilizes SQLite3 database as the data storage solution, facilitating maintenance of user information. The user login and registration framework is shown in Figure 3.2.1:
Figure 3.2.1 System Login and Registration Framework
(2) Camera Module Framework
The camera module primarily displays the monitoring screen and controls the camera’s left and right rotation, as shown in Figure 3.2.2:
Figure 3.2.2 Camera Framework
(3) Network Settings Module Framework
The network settings module mainly configures the network’s URL address, camera port number, and control port number, as shown in Figure 3.2.3:
Figure 3.2.3 Network Settings Module Framework
(4) Appliance Module Framework
The appliance module framework primarily implements the opening and closing of lamps and fans, as shown in Figure 3.2.4:
Figure 3.2.4 Appliance Control Module Framework
(5) Voice Module Framework
The voice module primarily implements voice recognition to control the opening and closing of lamps and fans, as well as the direction control of the balance car. The framework is shown in Figure 3.2.5:
Figure 3.2.5 Appliance Control Module Framework
(5) Vehicle Control Module Framework
The vehicle module primarily controls the direction of the vehicle, moving forward, backward, left, and right, and connects to WIFI, as shown in Figure 3.2.6:
Figure 3.2.6 Vehicle Control Module Framework
3.3 Design Framework Explanation
3.3.1 Background Service
The voice recognition and voice text reading utilize background service components. The advantage of using Service is that it allows for flexible service invocation and background operation. The voice module starts the Service service through Intent Start Service, calling Stop Service to switch the Service service off. The service mainly implements the call of the voice API interface, voice recognition, obtaining the results of voice recognition, and returning them to the Fragment.
3.3.2 SQLite Database Storage
The user login and registration module adopts SQLite database. The SQLite3 database is used to store user account password information, facilitating the maintenance of user information data. First, an SQLite Helper class is established to override the methods of adding, deleting, modifying, and querying, and a Database data file is created, as well as establishing tables. Then, functions are defined in the user class to implement addition, deletion, modification, and querying.
3.3.3 Share Preference Data Storage
Android lightweight data storage is used to temporarily store user preference settings, which is very convenient. The stored user data is kept in XML files.
3.3.4 Grid View Data Adapter
The data adapter stores images and titles in a linked list data structure, and during display, it traverses the linked list according to the length of images or titles, outputting the complete images and text titles.
3.3.5 Navigation Drawer Navigation Drawer
The navigation drawer is a side-slide menu that saves layout space. The side-slide menu adopts Fragment, which contains a List View, utilizing a data adapter, where the List View contains images and titles.
Chapter 4 Arduino Development Board Hardware Solutions
4.2.1 Arduino Main Control Setup
(1) Utilizes Arduino Nano minimum board plus an expansion board, mainly to control lamps, fans, voice modules, and camera servos, as shown in Figure 4.2.1.1:
Figure 4.2.1.1 Arduino Nano Main Control Board
(2) The balance car control utilizes Arduino UNO R3 board, as shown in Figure 4.2.1.2:
Figure 4.2.1.2 Arduino Uno Board
4.2.2 Arduino Lamp and Fan Relay Setup
The relay is used for low-power control of high-power devices, supplying power to the relay to control the opening and closing of lamps and fans, as shown in Figure 4.2.2.1:
Figure 4.2.2.1 Lamp and Fan Relay
4.2.3 Servo and Camera Setup
The servo primarily controls the left and right rotation of the camera, which is used to capture video images, as shown in Figure 4.2.3.1:
Figure 5.2.3.1 Servo Camera
4.2.4 SYN6288 Voice Text Synthesis Module
The module is primarily used for voice synthesis, playing messages such as “The lamp has been turned off” or “The lamp has been turned on”, or playing “The fan has been turned off” or “The fan has been turned on” voice prompts, as shown in Figure 4.2.4.1:
Figure 4.2.4.1 SYN6288 Voice Synthesis Module
4.2.5 OpenWrt Router Module
OpenWrt is essentially a Linux operating system running on a microcontroller.
The router primarily implements WIFI hotspots and collects camera images, controlling the operation of the Arduino MCU main control board through WIFI serial port, as shown in Figure 4.2.5.1:
With TX RX GND connected to the MCU Arduino’s RX TX GND, communication can be established (provided that ser2net or similar software is installed on OpenWrt to forward and receive data).
Figure 4.2.5 OpenWrt Router
4.2.5 Balance Car Overall Circuit Construction Design
The balance car system circuit construction mainly includes Arduino UNO R3 main control board, L298N motor driver module, MPU6059 gyroscope module, buck module, and other components including batteries and motors, as shown in Figure 4.2.5.2:
Figure 4.2.5.2 Balance Car Overall Circuit Construction
4.2.6 Upper Circuit Construction Design
The upper section primarily controls the lamp, fan, and the left and right rotation of the servo camera, as shown in Figure 4.2.6.1:
Figure 5.2.6.1 Upper Circuit Design
Chapter 5 Testing
5.2.4 Voice Recognition Testing
Mainly checks whether the voice recognition is successful, testing as shown in Figure 5.2.4
Figure 5.2.4 Voice Recognition Testing Image
5.2.5 Broadcast Sending and Receiving Testing
Mainly tests whether the broadcast is sent and received successfully, as shown in Figure 5.2.5:
Figure 5.2.5 Broadcast Testing Image
5.2.6 WIFI Sending and Receiving Testing
Mainly tests whether WIFI is sent and received successfully, as shown in Figure 5.2.6:
Figure 5.2.6 WIFI Sending and Receiving Testing Image
5.3 Hardware Testing Process
5.3.1 Lamp and Fan Testing
Using a mobile phone to connect WIFI to test whether it can turn on and off the fan, as shown in Figure 5.3.1:
Figure 5.3.1 Lamp and Fan Control Testing Image
5.3.2 Camera and Servo Testing
Using a mobile phone to connect WIFI to test whether it can receive surveillance images and whether the servo can rotate left and right, as shown in Figure 5.3.2:
Figure 5.3.2 Camera and Servo Testing Image
5.3.3 Smart Balance Car Testing
Using a mobile phone to connect WIFI to test whether the balance car can move forward, backward, left, and right, as shown in Figure 5.3.3:
Figure 5.3.3 Balance Car Testing Image
Chapter 6 Conclusion
Understand the development process of Android, comprehend the operational development mechanism of Android, and become familiar with the coding of the four major components of Android and their proficient applications, gaining deeper insights into various controls.
The IoT system project integrates Android mobile APP with smart hardware devices, communicating through WIFI via serial port with the Arduino MCU main control serial port, realizing data sending and receiving, and gaining a deeper understanding of the inseparable relationship between software and hardware. As a combination of software and hardware, it is bound to become a trend for smart devices like smart homes and smart IoT systems.
During the project development, a deeper understanding of various UI interfaces and development frameworks of Android was acquired, understanding the development thought process, learning from others’ development methods, and combining them with one’s own project for better improvements. In hardware, learning to write Arduino development board hardware code, understanding serial port sending and receiving methods, ensuring successful execution of related instructions. For controlling the balance car, the main focus is on controlling the angle output of MPU6050 gyroscope, outputting stable angle values with Kalman filtering, and then calculating the angle output PWM pulses to control the motors. When the car tilts forward, the car motor quickly moves forward to prevent it from tipping over; conversely, when the car tilts backward, the car motor quickly moves backward to prevent it from tipping over, ensuring stable operation of the car.
This concludes the introduction. If you have any thoughts or questions, please leave a message below, and let’s learn and improve together!