1. Trang chủ
  2. » Luận Văn - Báo Cáo

Research on bluetooth low energy (ble) and implement a control application using ble

83 8 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

VIET NAM NATIONAL UNIVERSITY HO CHI MINH CITY HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY COMPUTER SCIENCE AND ENGINEERING UNIVERSITY THESIS Research on BLUETOOTH LOW ENERGY (BLE) and implement a control application using BLE Major: Computer Engineering Council: Instructor: Reviewer: Student 1: Student 2: Student 3: Computer Engineering Ph.D Nguyen Tran Huu Nguyen Ph.D Pham Hoang Anh Tran Cao Bao An Le Hieu Phuong Ngo Nguyen Thuan HO CHI MINH CITY, October 2021 1752085 1752431 1752525 TR I H C QU C GIA TP.HCM -NG I H C BÁCH KHOA C NG HÒA XÃ H I CH NGH A VI T NAM c l p - T - H nh phúc NHI M V LU N ÁN T T NGHI P KHOA: KH & KT Máy tính _ B MƠN: K thu t Máy Tính Chú ý: Sinh viên ph i dán t vào trang nh t c a b n thuy t trình H VÀ TÊN: TR N CAO B O ÂN _MSSV: 1752085 H VÀ TÊN: LÊ HI U PH NG MSSV: 1752431 H VÀ TÊN: NGÔ NGUYÊN THU N MSSV: 1752525 NGÀNH: K THU T MÁY TÍNH _ L P: u đ lu n án: Nghiên c u v bluetooth n ng l ng th p hi n th c ng d ng giao ti p không dây s d ng bluetooth n ng l ng th p (Research on BLUETOOTH LOW ENERGY (BLE) AND implement a control application using BLE) Nhi m v (yêu c u v n i dung s li u ban đ u):  Bluetooth Low Energy is a wireless personal area network technology designed and marketed by   the Bluetooth Special Interest Group (Bluetooth SIG) aimed at novel applications in the healthcare, fitness, beacons, security, and home entertainment industries Students will work on nRF52833 development kit: - To learn how the Bluetooth LE works in basic, - To learn how the nRF52833 development kit communicates with an Android App, - To decide what application will be implemented, its specifications and - To write a report Students will focus on implementation what are suggested in the first stage Students need - To make a PCB that utilize the Bluetooth LE modules - To write an application that has an application running on an Android phone communicating with a circuit using BLE - To write a report Ngày giao nhi m v lu n án: 10/02/2021 Ngày hoàn thành nhi m v : 09/08/2021 H tên gi ng viên h ng d n: 1) NGUY N TR N H U NGUYÊN N i dung yêu c u LVTN đ c thông qua B môn Ngày tháng n m CH NHI M B MÔN (Ký ghi rõ h tên) Ph n h ng d n: Toàn b GI NG VIÊN H NG D N CHÍNH (Ký ghi rõ h tên) Nguy n Tr n H u Nguyên PH N DÀNH CHO KHOA, B MÔN: Ng i t (ch m s b ): n v : Ngày b o v : _ i m t ng k t: N i l u tr lu n án: TR NG I H C BÁCH KHOA KHOA KH & KT MÁY TÍNH C NG HÒA XÃ H I CH NGH A VI T NAM c l p - T - H nh phúc -Ngày tháng n m 2021 PHI U CH M B O V LVTN (Dành cho ng H tên SV: TR N CAO B O ÂN MSSV:1752085 H tên SV: NGÔ NGUYÊN THU N MSSV:1752525 H tên SV: LÊ HI U PH NG MSSV:1752431 ng d n/ph n bi n) ih Ngành (chuyên ngành): K THU T MÁY TÍNH Ngành (chuyên ngành): K THU T MÁY TÍNH Ngành (chuyên ngành): K THU T MÁY TÍNH tài: Nghiên c u v bluetooth n ng l ng th p hi n th c ng d ng giao ti p không dây s d ng bluetooth n ng l ng th p (Research on BLUETOOTH LOW ENERGY (BLE) AND implement a control application using BLE) H tên ng i h ng d n/ph n bi n: TS Nguy n Tr n H u Nguyên T ng quát v b n thuy t minh: S trang: 73 S ch ng: S b ng s li u: S hình v : S tài li u tham kh o: 19 Ph n m m tính tốn: Hi n v t (s n ph m) T ng quát v b n v : -S b nv : B n A1: B n A2: Kh khác: - S b n v v tay S b n v máy tính: Nh ng u m c a LVTN: In this thesis, the students have implemented an application using Bluetooth Low Energy (BLE) The main idea of the application is that a user can use an Android App running on a smartphone which can control a device using BLE The students have done many work including - Design a printed circuit board includes sensors and relays - Write a firmware to control the board - Use a development kits and write firmware for BLE communication - Write an Android App for BLE communication Nh ng thi u sót c a LVTN: ngh : cb ov  B sung thêm đ b o v  Không đ c b o v  câu h i SV ph i tr l i tr c H i đ ng: a Could you please propose a solution to ensure data that are sent between an Android App and a BLE device are correct? 10 ánh giá chung (b ng ch : gi i, khá, TB): Khá i m: 8/10 Ký tên (ghi rõ h tên) Nguy n Tr n H u Nguyên TR NG I H C BÁCH KHOA KHOA KH & KT MÁY TÍNH C NG HỊA XÃ H I CH NGH A VI T NAM c l p - T - H nh phúc -Ngày 06 tháng 08 n m 2021 PHI U CH M B O V LVTN (Dành cho ng i ph n bi n) H tên SV: Tr n Cao B o Ân, Ngô Nguyên Thu n, Lê Hi u Ph ng MSSV: 1752085, 1752525, 1752431 Ngành (chuyên ngành): K thu t Máy tính tài: Research on BLE and Implement a control application using BLE H tên ng i ph n bi n: TS Ph m Hoàng Anh T ng quát v b n thuy t minh: S trang: S ch ng: S b ng s li u S hình v : S tài li u tham kh o: Ph n m m tính tốn: Hi n v t (s n ph m) T ng quát v b n v : -S b nv : B n A1: B n A2: Kh khác: - S b n v v tay S b n v máy tính: Nh ng u m c a LVTN: - The students have demonstrated their capability in self-studying and applying knowledge and techniques to implement a BLE based Aquaponic monitoring system, including hardware, firmware and mobile software (Android BLE) - Basically, the system prototype’s functions work correctly - The report has well presented about BLE and related works Nh ng thi u sót c a LVTN: - The students did not present the design and implementation in detail - The system functions are still simple and only work locally - The report lacked experimental results ngh : cb ov  Câu h i SV ph i tr l i tr B sung thêm đ b o v  c H i đ ng: 10 ánh giá chung (b ng ch : gi i, khá, TB): Không đ i m : 8.0/10 Ký tên (ghi rõ h tên) Ph m Hoàng Anh cb ov  Guarantee We assure that except for the results from the references of other relevant works, the content presented in this thesis is our own implementation and has not been submitted in whole or in part, to consider for any degree in school, or any other university Ho Chi Minh City, 12th December, 2020 Acknowledgement First of all, we would like to express our sincere gratitude to our supervisor, Doctor Nguyen Tran Huu Nguyen and Doctor Le Trong Nhan, for his enthusiasm, patience, insightful comments, helpful information, practical advice and unceasing ideas that have helped us tremendously at all times in our research and doing of this thesis His immense knowledge, profound experience and professional expertise in Computer Engineering has enabled us to complete this project successfully Without his support and guidance, this project would not have been possible we could not have imagined having a better supervisor in our study We also wish to express our sincere thanks to the Ho Chi Minh University of technology for accepting us into the graduate program In addition, we are deeply indebted to Computer science and engineering faculty for the precious knowledge and experience when we study here Once again, we honestly give many warmest thanks! Abstract Bluetooth Low Energy (BLE) is an emerging low-power wireless technology developed for short-range control and monitoring applications BLE is expected to be incorporated into billions of devices in the next few years This document introduces Bluetooth Low Energy definition, the main features of BLE, and implements a control application using BLE To this end, we use an nRF52833 Development Kit and some relevant software tools including Android Studio, Segger Embedded Studio IDE and nRF Toolbox Application In addition, we will illustrate how to install and set up those tools and how we work with them to simulate some examples Then based on those software tools and source code, we show the use of an Android application that runs on a mobile phone to communicate with other devices through NRF5 device using simple UART technique which we will discuss more later Finally, we demonstrate the use of BLE in a real application that is about the aquaponic system with controlling lights and relays by using an android application Ho Chi Minh City University of Technology Computer Science and Engineering Contents Overview and introduction 1.1 Bluetooth Low Energy 1.1.1 Overview 1.1.2 Benefits of BLE 1.1.3 Limitations of BLE 1.1.4 Thesis proposal requirements 1.1.5 Thesis goal Theoretical Basis and Tools 2.1 Bluetooth Low Energy 2.1.1 Operating mode 2.1.2 Basic Operations of BLE 2.1.3 Frequency characteristics and transmission data structure of BLE 2.1.4 BLE Stack 12 2.1.5 BLE Protocol and BLE Profile 14 2.2 Universal Asynchronous Receiver/Transmitter (UART) 17 2.3 System architecture 20 2.4 nRF52833 Development Kit 21 2.4.1 Kit content 21 2.4.2 Interface MCU 21 Segger Embedded Studio 22 2.5.1 Overview 22 2.5.2 Installation and setting up 23 SoftDevices 23 2.6.1 Overview 23 2.6.2 Compatible SoftDevices 24 Software Development Kit (SDK) 24 2.7.1 Overview 24 2.7.2 Get started 24 2.7.3 Other components: 25 2.8 Nordic nRF Toolbox app 25 2.9 Android Studio 28 2.5 2.6 2.7 Page 1/73 Ho Chi Minh City University of Technology Computer Science and Engineering 2.10 Hterm and Arduino serial monitor 29 2.10.1 Hterm 29 2.10.2 Arduino serial monitor 29 Aquaponic system 29 3.1 Introduction 30 3.2 System feature base on aquaponic model 30 3.3 Implementation idea and system feature 31 Implementation 4.1 4.2 4.3 4.4 33 Android Application 33 4.1.1 User guide 33 4.1.2 BLE Communication 35 Printed Circuit Board Design 36 4.2.1 Hardware Components description 36 4.2.2 Hardware Design 46 4.2.3 Implement the board 53 Programming micro-controller 55 4.3.1 Arduino Uno 55 4.3.1.a Timer 55 4.3.1.b Interrupt 57 4.3.1.c Current Sensor ACS712 57 4.3.1.d Water Sensor: 59 4.3.1.e Moisture Sensor: 61 4.3.2 nRF52833 62 4.3.3 Functionality 65 Communication between application and board 67 Result 69 Conclusion and future plan 70 6.1 Achievements 70 6.2 Limitations 70 6.3 Future plan 70 6.4 Conclusion 71 Page 2/73 Thesis Structure The thesis is divided into chapters, each of which is a different content around the knowledge, tools used in the topic, the purpose of the report to help readers understand the technologies as well as the steps that we has done and developed, as well as an evaluation of the implementation process Chapter 1: Overview and introduction The goal of chapter is to have a better overview of the thesis topic, the reasons for using BLE, advantages and limitations of BLE What tools we are using The use of relays and smartphones to control remote devices Moreover with thesis goal and requirements All questions will be answered in Chapter Chapter 2: Theoretical basis and Tools In chapter 2, we introduce technologies used in the topic to help readers have more basic knowledge, Chapter will discuss about Bluetooth Low Energy, and how we control remote devices using PCB board and application on smartphone Chapter 3: Aquaponic system We will introduce about the aquaponic model, why we use this model to apply our BLE research As long as system requirement, feature of our system Chapter 4: Implementation Talking about each step of development and realization of the topic, this section will include other sub-sections which is smartphone application programming on Android Studio, PCB circuit design using Altium and programming for the nRF52833 chip using Segger Embedded Tools, Arduino IDE for Arduino programming Chapter 5: Result Showing what we have done, result, and the final product Chapter 6: Conclusion and future plan Synthesizing results from chapters and to identify future steps, what needs to be overcome and developed Chapter 7: Reference Ho Chi Minh City University of Technology Computer Science and Engineering Figure 51: AC current measuring code We encountered some difficulties while doing AC measurement The data must be taken continuously for a long enough time to get the maximum and minimum values, from which the calculated results will be accurate At first we used Serial.readString() function to retrieve data received by UART, but Serial.readString() take some time for it to read whole string (can be set by setTimeout function), so it interrupted into data taken process and make result was not accurate To fix that, we changed message sent to a single character and used Serial.read() function instead, it reads bytes at a time and it is faster 4.3.1.d Water Sensor: This sensor is used for determine water level We put it in tree pot to know when water is enough, then stop a water pump Page 59/73 Ho Chi Minh City University of Technology Computer Science and Engineering Figure 52: Water Sensor connection with Arduino Water sensor sends analog signal just like Current Sensor, value from - 1023 will be returned when there is no water touch it, value is returned, and increases base on water level In our project, the result we use is around 400 to 600 Connecting with Analog Pin A1 in Arduino Uno and using AnalogRead() function Figure 53: Water Sensor Page 60/73 Ho Chi Minh City University of Technology Computer Science and Engineering 4.3.1.e Moisture Sensor: We use this sensor to determine condition of soil, if the soil lacks water, it will activate pump to pump water for plants, until the amount of water reaches a certain level(indicated by water sensor), the pump will stop Figure 54: Moisture Sensor connection with Arduino When module detects water, result is around 900 to 1024, and when it is dry, number will returns Connecting with Analog Pin A2 in Arduino UNO and using AnalogRead() function Figure 55: Soil Moister Sensor Page 61/73 Ho Chi Minh City University of Technology Computer Science and Engineering 4.3.2 nRF52833 We use nRF52833 Development Kit to make Bluetooth connection with smartphone Connecting nRF5 with Arduino via UART connection (Tx pin and Rx pin) Set up baud rate to 115200 Whenever a message is received over Bluetooth(from smartphone), the message will be sent over UART to Arduino Figure 56: UART connection diagram Page 62/73 Ho Chi Minh City University of Technology Computer Science and Engineering Figure 57: Receive from BLE and send to UART Data are received from BLE will be saved in param.rx data variable Then they are sent by app uart put method And a function for sending a message received by UART to Bluetooth Page 63/73 Ho Chi Minh City University of Technology Computer Science and Engineering Figure 58: Send message from UART to BLE At first, we get data from UART using app uart get method Storing data into data array variable Finally they are sent by ble nus data send function Aside from sending and receiving function, nRF5 has more function to initialize Bluetooth GATT and GAP, also handles power management(sleep mode), advertising function and UART initializing function Page 64/73 Ho Chi Minh City University of Technology Computer Science and Engineering 4.3.3 Functionality Figure 59: Connection between sensor and PCB board Above is picture showing wire connection between sensor and a PCB, with red wire indicate VCC, black is GND and blue is signal pin(analog signal) Every seconds, the board will send statuses of Aquaponic system such as humidity, water level and status of a pump(on or off), to smartphone The system has modes, which are auto mode and controlled mode In auto mode, system will depend on sensor to turn the pump on or off In controlled mode, user can turn a pump by themselves Page 65/73 Ho Chi Minh City University of Technology Computer Science and Engineering Figure 60: System overal flowchart Arduino controls relays through pins, and receives result from sensor then sends it to nRF5 The nRF5 sends message to smartphone and receives control signal from smartphone Figure 61: Messages are sent from board Page 66/73 Ho Chi Minh City University of Technology Computer Science and Engineering 4.4 Communication between application and board During operation, the board and the phone application will continuously send signals to each other via bluetooth connection Receiving data from smartphone The original idea would be to use a string to send signals from both sides, such as the string SIGNAL1 ON and SIGNAL1 OFF to turn relay number on and off To that, we will use the Serial.readString() function Figure 62: Function declaration on Arduino This way has a big drawback that it depends on the setTimeout() function When the readString function is called, the system will have to wait for the amount of time set in setTimeout() (1000 milliseconds by default) This leads to a delay for the whole system Because of that, we use a single character to represent information, for example a for SIGNAL1 ON and A for SIGNAL OFF Using ASCII table so that we can have about 127 different signals Page 67/73 Ho Chi Minh City University of Technology Computer Science and Engineering Figure 63: ASCII table Using Serial.read() function, this function read the first byte coming from buffer and does not rely on any delay timer function For that reason, the system can handle more task with faster speed Figure 64: Receiving signal with ASCII code Sending data to smartphone For sending, we simply using Serial.print() function This function will send the message through Serial(UART) to nRF5 and nRF5 will send message to smartphone Page 68/73 Ho Chi Minh City University of Technology Computer Science and Engineering Result Figure 65: Printed Circuit Board and Arduino, nRF5 Figure 66: Aquaponic mini system Page 69/73 Ho Chi Minh City University of Technology Computer Science and Engineering Conclusion and future plan In this section, we will talk about what has been achieved, besides limitations and difficulties, finally what will be included in the future development plan of this project 6.1 Achievements We have finished the product The product works as expected, with few errors The final result meets the initial goal set by the instructor and the direction from the thesis proposal We have learned more about how Bluetooth works and how to apply it to a real product We use the thesis to participate in scientific research projects and presentations with the council 6.2 Limitations In terms of difficulties, due to the impact of the pandemic, the team hardly had the opportunity to meet and work together, so some features that wanted to be added to the project were not implemented Along with the complexity of the code in the Nordic device that requires a lot of research time, these things make the project still limited in terms of features The sensors used are cheap, so the data and durability are not stable We have to test and record the results many times, align properly so that the system can perform well For instance, the water sensor when there is no water is and when it detects water result around 700 will be returned, but sometimes the result was around 500 or 400, which was quite difficult for us to determine a right number while coding 6.3 Future plan There are a lot of new and interesting features that we want to be added: • Adding more sensors to measure soil quality, so that user can see the state of plants • Making a server so that user can view data on the system such as temperature, humidity, water quality, remotely User can also control the system from far away • Making a backup function, when the data transfer is fails, there is a mechanism to resend the data • Adding a security layer, which is protecting system privacy for user Also prevent hacker from changing the system against user will Page 70/73 Ho Chi Minh City University of Technology Computer Science and Engineering 6.4 Conclusion In summary, Bluetooth Low Energy has many application in any fields With their popularity, we can determine the important of them and there are many way to develop these application with multiple board With nRF5 Series Devices, there are many fields for developers choose and research The combination of nRF52833 and mobile phone using BLE is one of the topic which has many aspects for developing Therefore, in this thesis proposal, we not only research the BLE knowledge, the nRF52833 DK, but also we learn more about software tools such as Segger, Toolbox, Android Studio compatible with nRF5 board Aquaponic system is just one of many projects using BLE which we implement during this thesis time We not only gain many lessons and knowledge during working with aquanonic but also it is the experience when we work with another related projects Page 71/73 Ho Chi Minh City University of Technology Computer Science and Engineering References [1] Kevin Townsend Introduction to Bluetooth Low Energy, [https://learn adafruit.com/introduction-to-bluetooth-low-energy] Access February 28, 2021 [2] Mohammad Afaned May 6, 2016 The Basics of Bluetooth Low Energy (BLE) [https://www.novelbits.io/basics-bluetooth-low-energy/] Access March 2, 2021 [3] Gioi thieu cong nghe BLE [https://vngiotlab.github.io/vbluno/vi/ mydoc_ble_vi.html#gatt-services-and-characteristics] Access May 21, 2021 [4] VIFONIC ADMIN June 7, 2020 Huong dan giao tiep voi smartphone, may tinh bang qua Bluetooth Low Energy (BLE) (Phan 2) [https://htelectronics.vn/ huong-dan-giao-tiep-voi-smartphone-may-tinh-bang-qua-bluetooth-low-energy Access May 21, 2021 [5] VIFONIC ADMIN June 7, 2020 Huong dan giao tiep voi smartphone, may tinh bang qua Bluetooth Low Energy (BLE) (Phan 3) [https://htelectronics.vn/ huong-dan-giao-tiep-voi-smartphone-may-tinh-bang-qua-bluetooth-low-energy Access May 21, 2021 [6] VIFONIC ADMIN June 7, 2020 Huong dan giao tiep voi smartphone, may tinh bang qua Bluetooth Low Energy (BLE) (Phan 6) [https://htelectronics.vn/ huong-dan-giao-tiep-voi-smartphone-may-tinh-bang-qua-bluetooth-low-energy Access May 21, 2021 [7] Eric Pena, Mary Grace Legaspi Dec, 2020 UART: A Hardware Communication Protocol Understanding Universal Asynchronous Receiver/Transmitter [https://www.analog.com/en/analog-dialogue/ articles/uart-a-hardware-communication-protocol.html], Access May 25, 2021 [8] Scott Campbell Basics of UART Communication [https://www circuitbasics.com/basics-uart-communication/] Access May 25, 2021 [9] nRF52833 DK [https://infocenter.nordicsemi.com/topic/ug_nrf52833_ dk/UG/dk/intro.html] Access March 23,2021 [10] Embedded Studio - The All-in-One Embedded Development Solution [https: //www.segger.com/products/development-tools/embedded-studio/] Access March 12, 2021 [11] nRF52833 DK [https://www.nordicsemi.com/Products/ Development-hardware/nRF52833-DK] Access March 12, 2021 [12] nRF Toolbox App [https://www.nordicsemi.com/Products/ Development-tools/nRF-Toolbox] Access March 12, 2021 Page 72/73 Ho Chi Minh City University of Technology Computer Science and Engineering [13] Hterm [http://der-hammer.info/pages/terminal.html] Access March 25, 2021 [14] Tarun Agarwal 2019 ACS current sensor working and applications.[https://www.elprocus.com/ acs712-current-sensor-working-and-applications/] Accessed May 27, 2021 [15] Sikandar Haidar November 5, 2020 Pin relay wiring diagram use of relay [https://www.electricalonline4u.com/2020/11/ 5-pin-relay-wiring-diagram-use-of-relay.html] Access April 5, 2021 [16] Optocoupler Tutorial [https://www.electronics-tutorials.ws/blog/ optocoupler.html] Access April 5, 2021 [17] July 11, 2020 C1815 Transistor Details About Pinout, Equivalent, Uses, Features More [https://www.componentsinfo.com/ c1815-transistor-pinout-equivalent/] Access April 5, 2021 [18] amandaghassaei - Arduino Timer Interrupts [https://www.instructables com/Arduino-Timer-Interrupts/] Accessed Jun 26, 2021 [19] Dejan Arduino Relay Tutorial - Control High Voltage Devices with Arduino [https://howtomechatronics.com/tutorials/arduino/ control-high-voltage-devices-arduino-relay-tutorial/] Accessed May 27, 2021 [20] Our team members Source code of our system [https://github.com/ kangken1508/ThesisPTA] Page 73/73 ... manufacturer as Nordic The figure above shows the functionally divided code blocks of a BLE application Any BLE application contains main parts: controller, host and application • Application. .. c a LVTN: In this thesis, the students have implemented an application using Bluetooth Low Energy (BLE) The main idea of the application is that a user can use an Android App running on a smartphone... developed an application on Android mobile as a BLE central device This application can run on SDK 18 (Android 4.3 Jelly Bean) and above but work best on SDK 29 (Android 10) We have a link for any

Ngày đăng: 03/06/2022, 11:29

Xem thêm:

TỪ KHÓA LIÊN QUAN

w