Wednesday, 25 March 2020

IoT- Part- 3- Serial Communication and Bluetooth Voice Control

Serial Communication:

Serial communication is the process of sending  one bit of data at a time over a channel or a bus.

Serial in Arduino:

All Arduino boards has at least one Serial port (connection point), Four ports are available in Arduino Mega. These Serial ports are also know as UART (Universal Asynchronous Receiver/Transmitter) or USART (Universal Synchronous/Asynchronous Receiver Transmitter). Its a physical circuit embedded on the arduino board to communicate with the outer computer.

Note: Serial communication is not a type of Communication protocol, you can think of it an chip which is doing its work standalone.

UART: Two systems working on different clock speed
Ex: WiFi, Uploading code to arduino.

USART: Two systems working on same clock speed
Ex: SPI, I2C (Two wire interface).

Receiver is alias as Rx and Transmitter as Tx. 

Types of Wired Communication:

  1. Serial - There is only one channel between Rx and Tx.
  2. Parallel - Multiple channels are available between Rx and Tx

Serial Communication:

The very fine example of Serial communication is already implemented by you, remember the process of uploading arduino program? Did you notice that continuous blinking of orange led when upload was happening? 

Definitely Yes!!!

Reason for this is that when you connect your USB cable with arduino board, the communication established between them was a Serial Communication, Arduino uses Rx-Tx pins of atmega to communicate with your PC. Once you begin with the uploading process the serial ports are activated and bit wise data are sended from your PC to arduino board.

You can also see as Rx and Tx are available at arduino board mostly pin no. 0 and 1, these pins are available for the use of external purpose which we will see later on. In Arduino UNO only one Serial Port is available.

Baud Rate:

Baud rate is the rate at which the information is being transferred over the channel, measured in bits/sec.

Some very known baud rates are:
  • 300
  • 9600
  • 19200
  • 38400
  • 57600
  • 74880
  • 115200
  • 230400

Serial.begin():

Defines the speed (baud rate) at which your arduino board will be communicating with the Serial Monitor or with the connected device at the serial ports. As configuration of baud rate is required once it is placed in void setup() block.

Syntax: Serial.begin(speed);

Ex:

Serial.print():

Is used to print data over the Serial port in Human Readable format.

Syntax: Serial.print(data);

Ex:
This will print data in a single line, to shift printing to the next line replace print with println.



Upload your program and open Serial Monitor by clicking magnifying icon  from top right corner, shortcut (CTRL+SHIT+M).

Set baud rate from bottom right drop 2nd down menu as per baud rate configured in void setup. Once baud rate is set you will be able to see result



To print  data multiple times, write the instruction into void loop(). 

To print variable simply pass the variable as parameter without inverted commas.

Serial.read():

Is used to read the incoming data at the Serial port. Serial.read() returns the data in byte and returns -1 if not available.

Demo Code:



Note: Serial.available() checks for byte data that is already received and is stored in Serial buffer (size of 64 byte).

HC-05 Bluetooth interface with arduino:

Brief description of HC-05

HC-05 is wireless module which can be used for two-way (full duplex) function. It can be used to create communicate between arduino or other controller to your daily devices such as smartphone or laptop.

HC-05 consist of  7 pins:
  1. Enable key: This pin is used to toggle between Data mode (set low) and AT command  modes (set high). We will be using Data mode which is also default mode for HC-05.
  2. Vcc: Used for the power supply of HC-05.
  3. GND: Connect with system ground.
  4. Tx: Transmit serial data, is used by Bluetooth to transmit data to other device.
  5. Rx: Receive serial data, is used as an input of Bluetooth.
  6. State: Is used to check if Bluetooth is working properly.
  7. LED: Indicate status of module.

Note: Bluetooth LED  blinking pattern show status of module.
  • Blink once in 2 sec: Command mode is set.
  • Repeated blinking: Waiting for connection in Data Mode.
  • Blink twice in 1 sec: Connection successful in data Mode.

Default Settings:

  • Name: HC-05
  • Password: 1234 or 0000
  • Communication type: Slave
  • Mode: Data
  • Baud Rate: 9600

Operating specification:

  • Input Voltage: 3v to 6v (Most commonly works on 3.3 v).
  • Current Consumption: 30mA.
  • Communication range: less than 100m.
  • Protocol: IEEE 802.15.1
  • Max support baud rate: 460800.

HC-05 interface with arduino:

Connect Bluetooth using one to one jumper wire as show below.



Note: Rx-Tx pins available on Arduino Nano is common pin for Arduino program loading purpose, you need to disconnect Bluetooth Rx-Tx from Arduino every time you upload program into arduino. 

We will be seeing practical demonstrations for better understanding of Arduino Serial and program flow.


Practical Demonstration Videos:

Clip -1: Serial Communication using HC05


Clip -2: Bluetooth voice control using HC05



In next part we will begin with some communicating protocols and hardware interface in IoT.








No comments:

Post a Comment

IoT- Part- 4- IoT Communication Protocol

Implementation of IoT is of no use unless or until we overcome some existing problems. As we are very much familiar with the most wide...