[go: up one dir, main page]

0% found this document useful (0 votes)
180 views27 pages

Capstone Project 1

This document describes a capstone project involving the implementation of Bluetooth using HC-05/HC-06 modules. The project uses Arduino Uno and Nano boards to control lights based on temperature and humidity data transmitted between the boards via Bluetooth. It provides an overview of the theoretical concepts behind Bluetooth, Arduinos, DHT22 sensors, LCD displays, and PZEM-004 modules. It also outlines the chapters that will explain the data transmission process, code, mapping, achievements, drawbacks, and references.

Uploaded by

Minh Triết
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
180 views27 pages

Capstone Project 1

This document describes a capstone project involving the implementation of Bluetooth using HC-05/HC-06 modules. The project uses Arduino Uno and Nano boards to control lights based on temperature and humidity data transmitted between the boards via Bluetooth. It provides an overview of the theoretical concepts behind Bluetooth, Arduinos, DHT22 sensors, LCD displays, and PZEM-004 modules. It also outlines the chapters that will explain the data transmission process, code, mapping, achievements, drawbacks, and references.

Uploaded by

Minh Triết
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

HO CHI MINH UNIVERSITY OF TECHNOLOGY

BACH KHOA UNIVERSITY


ELECTRIC-ELECTRONIC ENGINERING
TELECOMMUNICATION DEPARTMENT


CAPSTONE PROJECT 1
IMPLEMENTAION OF BLUETOOTH USING HC-05/HC-06
MODULE

INSTRUCTOR: Dr.Vo Que Son

STUDENT’S NAME AND ID:


Tran Dang Phuc – 1851099
Nguyen Phung To Uyen – 1851121

HO CHI MINH CITY, January, 2021


Capstone project |2

Since the beginning of this capstone, we have received supports from many people, which brought us
to the successful result today. We would like to express our gratitude toward our instructor, Dr.Vo
Que Son, who has given us valuable advices throughout the project, and he also has helped us
develop our project even further. We also send thanks to friends, who have motivate us during the
how process.

Ho Chi Minh City, January, 2021


Tran Dang Phuc
Nguyen Phung To Uyen
Capstone project |3

OVERVIEW
Science and Technology have developed a lot throughout history, especially in the
telecommunication fields. Bluetooth and Wi-Fi have been invented to meet people demand. At
first, these thing are just used for sending files and communicating among people. However,
there is a potential utility, since it can be used as a means of communication between 2
machines. Until now, more and more implementation of Bluetooth are done to make life become
more convenient. Our capstone project is also an implementation of Bluetooth, which is the
lightning controlling system. From this is project, we can develop even further, since it is the
basic of smart house design. Moreover, we also take measurement of the parameters of the
system, so that people can check the safety of the system and other aspects.
Capstone project |4

Table of Contents
OVERVIEW...................................................................................................................................................... 3
CHAPTER 1: THEORETICAL BASIS............................................................................................................. 5
1. ABOUT BLUETOOTH.....................................................................................................................................5
1.1 About Module Bluetooth HC-05......................................................................................................................5
1.2 About Module Bluetooth HC-06...............................................................................................................6
1.3 HC-05 BLUETOOTH MODULE CONFIGURATION:...........................................................................7
2. ABOUT ARDUINOS.....................................................................................................................................8
2.1 Arduino Hardware...........................................................................................................................................8
2.2 Arduino Software......................................................................................................................................9
2.3 Arduino code............................................................................................................................................9
2.4 About Arduino Uno................................................................................................................................10
2.5 About Arduino Nano...............................................................................................................................12
3. ABOUT DHT22 SENSOR.................................................................................................................................14
4. ABOUT LCD..................................................................................................................................................15
5. ABOUT PZEM-004..........................................................................................................................................16
CHAPTER 2: DATA TRANSMISSION.......................................................................................................... 17
CHAPTER 3: CODE EXPLANATION........................................................................................................... 20
CHAPTER 4: MAPPING................................................................................................................................ 24
CHAPTER 5: ACHIEVEMENT AND DRAWBACKS...................................................................................27
CHAPTER 6: REFERENCES......................................................................................................................... 27
Capstone project |5

CHAPTER 1: THEORETICAL BASIS

1. ABOUT BLUETOOTH

What is Bluetooth?
Bluetooth simply is a short-range, low-power, low-cost, wireless connection between different
devices using radio wave with frequency range from 2.402 GHz to 2.480 GHz.

Masters, Slaves, and Piconets


Bluetooth networks (commonly referred to as piconets) use a master/slave model to control when
and where devices can send data. In this type of connection, one master can connect up to 7
different slave devices, but it can only connect to 1 slave at a time and one slave can only be
connected to one master.

Serial Port Profile (SPP)


Our project is to setup the communication between two Arduinos so using SPP profile to replace
a serial communication interface (like RS-232 or a UART) is a suitable choice. Using SPP, each
connected device can send and receive data just as if there were RX and TX lines connected
between them

1.1 About Module Bluetooth HC-05

HC-05 Bluetooth Module is an easy to use Bluetooth SPP (Serial Port Protocol) module for
communicating between devices, It can be set as master or slave mode while HC-06 only works
in slave mode.
Capstone project |6

 Tech specs

 Pin Out

 VCC connects to Arduino Nano 5V

 GND connects to Arduino Nano GND

 TXD connects to Arduino Nano Pin that is set as RX

 RXD connects to Arduino Nano Pin that is set as TX

1.2 About Module Bluetooth HC-06

HC-06 is a class-2 slave Bluetooth module designed to enable wireless serial communication
between microcontroller (like Arduino) and other Bluetooth enabled devices.
 Tech specs
Capstone project |7

 Pin Out

 VCC connects to Arduino Uno 5V

 GND connects to Arduino Uno GND

 TXD connects to Arduino Uno Pin that is set as


RX

 RXD connects to Arduino Uno Pin that is set as


TX

1.3 HC-05 BLUETOOTH MODULE CONFIGURATION:

First, press and hold the button on the HC-05 chip (connected to arduino), and plug in the cable
at the same time. When the LED blinks every 2s instead of blinks fast, the chip is now in AT
command mode.
After that, open the Serial Monitor and type these following command:
- AT: To test the module. The program will return OK.
- AT + ORGL: To restore the module to default.
- AT + ROLE = 1: Set the chip to master mode (0-slave, 2-slave loop).
- AT + CMODE = 1: Connect to random Bluetooth module around it
Or if you know the slave Bluetooth module you can use this way:
- AT + CMODE=0: Connect to specific BLE module address.
- AT + BIND = <address>
And moving onto the UART setup:
- AT + UART = <baud rate>,<number of stop bits>,<parity bit>
For our capstone project: AT + UART = 38600, 0, 0: this mean baud rate at 38600, 1 stop bit, no
parity bit used.
Capstone project |8

2. ABOUT ARDUINOS

Arduino is a tool for controlling electronics, it’s used to read inputs (such as temperature and
humid sensors in this project) and control outputs (such as LCD display and light bulb in this
project). There are three main components in Arduino, they are Arduino Hardware, Arduino
Software, Arduino Code.

2.1 Arduino Hardware

It’s a physical component of Arduino which are Arduino boards and all Arduino boards have a
microcontroller on them. Basically a microcontroller is a small computer that allows us to read
different inputs and control different outputs.
Types of Arduino Boards:

Arduino UNO Arduino Nano

Lilypad Arduino Arduino Mega ADK


Capstone project |9

2.2 Arduino Software

To write and upload programs to Arduino compatible boards you need Arduino IDE (Integrated
Development Environment)

2.3 Arduino code

The code that you write inside the Arduino IDE is ultimately what gets loaded onto the
microcontroller that’s on these Arduino boards. The Arduino code that you write is called a
sketch. The Arduino code itself is basically a derivative of the C and C++ programming
languages, but with some Arduino-specific functions and structure.
Capstone project | 10

2.4 About Arduino Uno

 Tech specs
Capstone project | 11

Arduino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital
input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs. They operate at 5
volts. Each pin can provide or receive 20 mA as recommended operating condition and has an
internal pull-up resistor (disconnected by default) of 20-50k ohm. A maximum of 40mA is the
value that must not be exceeded on any I/O pin to avoid permanent damage to the
microcontroller.

Our project, the pins we use:


PWM 2: set as TX to connect to Bluetooth HC-06
PWM 4: set as RX to connect to Bluetooth HC-06
A4
A5
Capstone project | 12

2.5 About Arduino Nano

 Tech specs:
Capstone project | 13

 Pin Out

Our project, the pins we use:


PWM 2: set as RX to connect to Pzem
PWM 3: set as TX to connect to Pzem
PWM 4: set as TX to connect to Bluetooth HC-05
PWM 5: set as RX to connect to Bluetooth HC-05
PWM 6: to connect to DHT22
Capstone project | 14

3. About DHT22 sensor

The DHT22 is a basic digital temperature and humidity sensor. It uses a capacitive humidity
sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data
pin, no analog input pins needed.

 Tech specs

 PinOut

 VCC connects to Arduino Nano 5V

 GND connects to Arduino Nano GND

 Data connects to Arduino Nano pin 6


Capstone project | 15

4. About LCD

We use I2C 16X2 LCD to display datas of temperature, humid and power. It is more convenient
because it only needs just 4 wires to connect to Arduino Uno, while connecting 16X2 LCD to
Arduino Uno need more than 12 wires.

 Tech specs

 Pin Out

GND connects to Arduino Uno GND


VCC connects to Arduino Uno 5V
SDA connects to Arduino Uno A4
SCL connects to Arduino Uno A5
Capstone project | 16

5. About Pzem-004

Pzem-004 is a best choice for measuring the voltage, current and power
 Tech specs

 Pin Out

GND connects to Arduino Nano GND


VCC connects to Arduino Nano 5V
TXD connects to Arduino Nano Pin that is set as RX
RXD connects to Arduino Nano Pin that is set as TX
Capstone project | 17

CHAPTER 2: DATA TRANSMISSION

Micro- controller transmit data in several ways, and there is 2 prevalent ways to do so, which are
in parallel way or cascade way (serial transmission).
In parallel transmission, when we want to transmit a package of n-bit data, we need n wire for
each bit. This could make the transmission faster, yet it will require lots of wires (32-bit data
need 32 wires). We want to reduce the size of the circuit, so this is not an optimal to do.
Meanwhile in serial transmission, we just need one wire for n-bit data, yet this way take a lot of
time than the other way. For example, for 32-bit data, we just need one wire, but it will be 32
times slower than the parallel transmission. There are 3 types of serial transmission:
 Simplex: The data can be transmitted in only 1 way.

 Half-duplex: The data can now be transmitted back and forth on 1 wire, but only 1
action can be done at a time.

 Full-duplex: The data can be transmitted in both ways at the same time.

I. UART (Universal Asynchronous Receiver-Transmitter)


UART is also a full-duplex data transmission, but it has no clock. To communicate, 2 devices
have to meet some requirement. Baud rate has to be set at the same rate. The power source and
GND wire of 2 devices must be the same, so the high/low signal can be identified. Data package
is the next factor. It contains 3 (or 4) components based on the user:
Capstone project | 18

 Start bit: The first low-bit in the series (0), inform the device that there is data about to
be transmitted to.
 Data: Package of n-bit data, usually 8-bit (7-bit if parity bit is used), is placed right after
start bit begin with LSB to MSB.
 Parity bit (optional): Use to check the data.
 Stop bit: High-bit (1), can be 1 or more based on the user, inform the device that the
transmission of data is finished.

Note: This type of serial communication is used a lot in our capstone project.

II. I 2C (Inter – Integrated Circuit)


I2C (I-square-C) only need 2 wires (SDA & SCL) to communicate, and unlike UART, it does
not require 2 devices to have the same baud rate. I2C use clock to transmit data between 2
devices, and the clock is set by the “master”. Moreover, its protocol is quite special, since it
require an address to store the data in.
The data is transmitted between “master” and “slave” device through a single wire (SDA) under
a sequence of 0 and 1. Every string of 0 and 1 is considered a transaction and that transaction has
the following structure:

Start condition: when status of SDA move from high to low before the SCL move from high to
low.
Capstone project | 19

Address block: Contain 7-bit address of the slave device to be communicated with.
Read/Write bit: Decide the direction of data flow: “0” if MasterSlave and “1” if
SlaveMaster.
ACK/NACK bit (Acknowledge/Not-Acknowledge): Check if the slave address is same as the
address block. “0” if it is the same and vice versa.
Data Block: Contain 8-bit of data and followed by an ACK/NACK bit. This bit (0) will
determine if the data is transmitted successfully.
Stop condition: Status of SDA move from low to high before SCL do.

Note: We use the I2C protocol to perform communication between the Arduino and the LCD
16x2.
Capstone project | 20

CHAPTER 3: CODE EXPLANATION

 MAIN PROGRAM
The capstone project’s main idea is the implementation of Bluetooth chips (HC-05 & HC-06) on
the wireless controlling system and measurement of the power, temperature, etc. To make this,
we have to split the program into 2 parts:
 Master (connected to the HC-05): which will be in charge of the measuring process and
then send the collected data as well as the signal to the other part.
To take a measurement, we use the DHT-22 chip for the temperature and humidity and pzem-
004t v1.0 for the electrical parameters.
Set up part: where we initialize everything and set the pin nodes, IP address, etc.

Given the library DHT.h and PZEM004T.h, we can measure things faster since function calling
is the only thing we need to do: dht.readHumidity(), dht.readTemperature(), pzem.power(IP
address).
However, there is a problem during the transmitting process, in which it only send the integer
part of a number to “the slave”. Clearly, we use the Arduino Uno R3 as the microcontroller
(based on ATmega328p), which is just an 8-bit processor. Therefore, the maximum integer it can
get is only 255 and sent in the form of “package”. In order for the slave to receive the a whole
real number with both the integer and fractional parts, we have write a function to separate them
into 2 parts and send them one by one and assemble them back in the “slave”.
This function contain 2 while loops: loop1 and loop2 with the former calculating the unit of tens
of the number and with the latter computing the unit of ones of the number and return the sum of
them.
Capstone project | 21

At first, this function receive the measured number and then calculate and return the integer part
of it. Secondly, we take the difference between the number and the return result and multiply by
100. Then we send both of them. For example: (temperature)

Note: PZEM004T function will return negative value if there is no current through the device.
Therefore, we have restricted it so whenever there is no current, the result will be 0.

Moving onto the controlling part, we use the laptop to control lightning system, which can be
improved by designing a phone application for more convenience.

We use the function “readStringUntil(…)” to give the command through the keyboard. “d” is the
control signal to turn the light on/off.
Capstone project | 22

 Slave (connected to the HC-06): which will receive the data and then use those to display
through a LCD and control the devices (light, motor).
Set up part: similar to master but we also have volatile variables for specific purpose.

In the “slave”, the program receive the data sent from “master” and display them to the LCD
screen. For example: (temperature)

The function “adj()” is to design the interface for user, which will just display one component of
a time to prevent being overwhelmed by words on the screen. However, there is a downside of
this design, since it display the data to users for 5s per component. Therefore the program is
delay about 20s, which is really bad for the control part.

This is where timer/counter (TC) come in handy. TC is a module, which work independently
from the whole program using its own clock system. TC is considered interrupt signal, which
will help us bypass the 20s delay of the program. Therefore the control signal will be nearly
instance with little delay (about 0.2s). The clock count from 0 to 65536, which is about 4µs. To
¿ 0.2 s
get the delay of 0,2s, the clock have to count from t = =50000  t = 65536 – 50000 =
4 µs
15536 TCNT1 = 15536.
Capstone project | 23

Setup part for TC:

Coding part for TC: the function of TC is called “ISR(TIMER1_OVF_vect)”. An example:


(temperature)

At first, we have to reset the timer so that the function will be consecutively called during the
whole process. Then the program read the data sent by “master” and compute those data to get
back the real number with both integer and fractional parts.
In the “master”, it also send the signal “d” to control the light, so this is the part “slave” receive
the signal and proceed to control the light through a relay.

When the signal is “1” the output is set to high and the relay is closed to let the current go
through  light on and vice versa.
Provided the timer, the “slave” read the data wait to control the light every 0.2s, so it has become
more convenient when you do not have to wait 20s to turn a light on and another 20s to turn it
off.
Image of the display on the LCD screen:
Capstone project | 24

CHAPTER 4: MAPPING

In this chapter all components that are mentioned above will be combined together. We separate
into 2 part:

Master board: First picture.


+ Pzem, dht-22 and HC-05 are connected to Arduino Nano. The program take the measurement
and send the data away.

Slave board: Second picture.


+ I2C – LCD (16x2), HC-06 and relay are connected to Arduino Uno. The data collected from
dht-22 and pzem will be transmitted and display on the LCD screen.
Capstone project | 25
Capstone project | 26
Capstone project | 27

CHAPTER 5: ACHIEVEMENT AND DRAWBACKS

I. ACHIEVEMENT:
+ The program has basically fulfilled all tasks for our capstone project 1.
+ The error in transmitting real number (fractional part included) and the 20s delay in controlling
have been fixed.
+ We have learned many things about BLE, implementation of BLE and the wireless embedded
system.
+ Teamwork and time management skill have been improved.
II. DRAWBACKS:
+ Using a laptop to control things is quite inconvenient due to the size of it, so we are planning to
move the controlling part to smaller and more convenient platform such as mobile phones or
smart watch.
+The “slave” read the data so quickly, so it sometimes miss the data  we have to send the
control signal again. However, this event only happens once in a while.
+ Our project is to study about BLE and the implementation of it, yet our project is just based on
the “one to one” connection, which is not practical in our daily life. What we can do is extend
this project to “mesh Bluetooth”, which will be the foundation for the smart building design.

CHAPTER 6: REFERENCES

https://www.arduino.cc/

https://innovatorsguru.com/wp-content/uploads/2019/06/PZEM-004T-V3.0-Datasheet-User-
Manual.pdf

https://www.alldatasheet.com/datasheet-pdf/pdf/1132459/ETC2/DHT22.html

https://components101.com/sites/default/files/component_datasheet/HC-05%20Datasheet.pdf

https://www.alldatasheet.com/datasheet-pdf/pdf/1179032/ETC1/HC-06.html

https://www.seeedstudio.com/blog/2019/09/25/uart-vs-i2c-vs-spi-communication-protocols-and-
uses/#:~:text=What%20is%20I2C%3F&text=It%20is%20a%20serial%20communications,devices
%20connected%20to%20the%20bus.

https://www.quantil.com/content-delivery-insights/content-acceleration/data-transmission/

You might also like