Arduino 4
Arduino 4
Bluetooth Technology
Introduction
Bluetooth is a wireless communication technology used for exchange
of data over short distances.
It is found in many devices ranging from mobile phones and
computers.
Bluetooth technology is a combination of both hardware and
software.
It is intended to create a personal area networks (PAN) over a short
range.
It operates in the unlicensed industrial, scientific and medical (ISM)
band at 2.4 to 2.485 GHz.
It uses a radio technology called frequency hopping spread spectrum
(FHSS).
It is a packet-based protocol with a master-slave structure.
The range of Bluetooth depends upon the class of radio using.
Class 3 radios have range up to 1 meter or 3 feet.
Class 2 radios have range of 10 meters or 33 feet.
Class 1 radios have range of 100 meters or 300 feet.
The most commonly used radio is Class 2.
Advantages and Disadvantages
Advantages
The biggest advantage of using this technology is that there are no
cables or wires required for the transfer of data over short ranges.
Bluetooth technology consumes less power when compared with
other wireless communication technologies.
For example Bluetooth technology using Class 2 radio uses power of
2.5 mW.
As it is using frequency hopping spread spectrum radio technology
there is less prone to interference of data if the other device also
operates in the same frequency range.
Bluetooth doesn’t require clear line of sight between the
synchronized devices.
Disadvantage
Since it uses the greater range of Radio Frequency
(RF), it is much more open to interception and
attack.
It can be used for short range communications only.
Although there are fewer disadvantages, Bluetooth
still remains best for short wireless technology.
Introduction to HC-05 and HC-06 Modules
HC 05
HC-05 is a class 2 Bluetooth module
with Serial Port Profile (SPP).
It can be configure either as master or
salve.
It is a replacement for wired serial
connection.
The module has two modes of
operation, Command Mode where we
can send AT commands to it and Data
Mode where it transmits and receives
data to another Bluetooth module.
HC-05 Specification:
Bluetooth Protocol : Bluetooth Specification v2.0 + EDR (Enhanced Data Rate)
Frequency : 2.4 GHz ISM band
Profiles : Bluetooth Serial Port
Working Temperature : -20 to + 75 centigrade
Power of emitting : 3 dBm
The pins on the module are:
Vcc – Power supply for the module.
GND – Ground of the module.
TX – Transmitter of Bluetooth module.
RX – Receiver of the module.
Key – Used for the module to enter into AT command mode.
The default mode is DATA Mode, and this is the default
configuration, that may work fine for many applications:
Baud Rate: 9600 bps, Data : 8 bits, Stop Bits: 1 bit, Parity :
None, Handshake: None
Passkey: 1234
Device Name: HC-05
Hooking up with Arduino
Circuit connections for Data Mode of operation:
The connections are:
HC-05 Arduino
Vcc -----------> 5V
GND -----------> GND
TX -----------> RX
RX -----------> TX
void setup()
{
Let’s control the LED Serial.begin(9600);
on Arduino using a pinMode(13,OUTPUT);
}
basic code to send void loop()
command over {
Bluetooth. if(Serial.available())
{
int ch=Serial.read();
The code is shown: if(ch=='h')
{
digitalWrite(13,HIGH);
}
else if(ch=='l')
{
digitalWrite(13,LOW);
}
}
}
Configuring HC-05 with AT commands
HC-05 can be configured i.e. its name and password
can be changed and many more using AT
commands.
It can also be configured as either master or slave.
To set the HC-05 into AT command mode, the KEY
pin of the module is made high i.e. it is connected
to either 5V or 3.3V pin of Arduino and TX of
Arduino is connected to TX of HC-05 and RX of HC-
05 to RX of Arduino.
Circuit connections for Command Mode of operation:
To enter the AT commands open up the COM port of the
Arduino to which the Bluetooth module is connected and set
the baud rate to 38400.
After opening COM port if you enter command “AT” (without
quotes) it should return “OK” thus it can be said that HC-05
entered into AT command mode.
Refer following link for detailed AT commands and its
descriptions:
http://www.linotux.ch/arduino/HC-
0305_serial_module_AT_commamd_set_201104_revised.pdf
Popular AT commands
1. AT
2. AT+RESET
3. AT+VERSION?
4. AT+ORGL
5. AT+ADDR?
6. AT+ ROLE?
7. AT+PSWD?
8. AT+UART?
9. AT+STATE?
10. AT+DISC
11. AT+NAME
• AT : Ceck the connection.
AT+NAME : See default name
AT+ADDR : see default address
AT+VERSION : See version
AT+UART : See baudrate
AT+ROLE: See role of bt
module(1=master/0=slave)
AT+RESET : Reset and exit AT mode
AT+ORGL : Restore factory settings
AT+PSWD: see default password
Here are a few AT commands that I found useful:
•To ensure the unit is responding, enter AT. The unit should respond OK
•To return the HC-05 to its default settings, enter AT+ORGL
•To see the version of your HC-05 enter AT+VERSION?
•To change the name of the device to AJCLOCK, for example, enter
AT+NAME=AJCLOCK
•To change the default security code (1234) to 2332 enter
AT+PSWD=2332
•To check baud rate, enter AT+UART? (my unit reset to 38400)
•To change baud rate to say, 115200, 1 stop bit, 0 parity, enter
AT+UART=115200,1,0
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX | TX
void setup()
{
Serial.begin(9600);
Serial.println("Enter AT commands:");
mySerial.begin(38400); // HC-05 default speed in AT command mode
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
DHT11/DHT22
Experiment -DHT11 Sensor
Interfacing with Arduino UNO
• DHT11 sensor measures and provides humidity
and temperature values serially over a single wire.
• It can measure relative humidity in percentage (20
to 90% RH) and temperature in degree Celsius in
the range of 0 to 50°C.
• It has 4 pins; one of which is used for data
communication in serial form.
• DHT11 sensor uses resistive humidity
measurement component, and NTC temperature
measurement component.
DHT11 Specifications
• Ultra-low cost
• 3 to 5V power and I/O
• 2.5mA max current use during conversion
(while requesting data)
• Good for 20-80% humidity readings with 5%
accuracy
• Good for 0-50°C temperature readings ±2°C
accuracy
DHT22 Specifications
• Low cost
• 3 to 5V power and I/O
• 2.5mA max current use during conversion
(while requesting data)
• Good for 0-100% humidity readings with 2-5%
accuracy
• Good for -40 to 125°C temperature readings
±0.5°C accuracy
• Before you can use the DHT11 on the Arduino, you’ll need to install the
DHTLib library.
• https://github.com/adafruit/DHT-sensor-library
• It has all the functions needed to get the humidity and temperature
readings from the sensor.
• It’s easy to install, just download the DHTLib.zip and open up the Arduino
IDE.