Tag Archives: HC-05

Get Sensor Data From Arduino To Smartphone Via Bluetooth

Hariharan Mathavan at allaboutcircuits.com designed a project on using Bluetooth to communicate with an Arduino. Bluetooth is one of the most popular wireless communication technologies because of its low power consumption, low cost and a light stack but provides a good range. In this project, data from a DHT-11 sensor is collected by an Arduino and then transmitted to a smartphone via Bluetooth.

Required Parts

  • An Arduino. Any model can be used, but all code and schematics in this article will be for the Uno.
  • An Android Smartphone that has Bluetooth.
  • HC-05 Bluetooth Module
  • Android Studio (To develop the required Android app)
  • USB cable for programming and powering the Arduino
  • DHT-11 temperature and humidity sensor

Connecting The Bluetooth Module

To use the HC-05 Bluetooth module, simply connect the VCC to the 5V output on the Arduino, GND to Ground, RX to TX pin of the Arduino, and TX to RX pin of the Arduino. If the module is being used for the first time, you’ll want to change the name, passcode etc. To do this the module should be set to command mode. Connect the Key pin to any pin on the Arduino and set it to high to allow the module to be programmed.

Circuit to connect HC-05 with Arduino
Circuit to connect HC-05 with Arduino

To program the module, a set of commands known as AT commands are used. Here are some of them:

AT Check connection status.
AT+NAME =”ModuleName” Set a name for the device
AT+ADDR Check MAC Address
AT+UART Check Baudrate
AT+UART=”9600″ Sets Baudrate to 9600
AT+PSWD Check Default Passcode
AT+PSWD=”1234″ Sets Passcode to 1234

The Arduino code to send data using Bluetooth module:

//If youre not using a BTBee connect set the pin connected to the KEY pin high
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(4,5); 
void setup() {
 String setName = String("AT+NAME=MyBTBee\r\n"); //Setting name as 'MyBTBee'
 Serial.begin(9600);
 BTSerial.begin(38400);
 BTSerial.print("AT\r\n"); //Check Status
 delay(500);
 while (BTSerial.available()) {
 Serial.write(BTSerial.read());
 }
 BTSerial.print(setName); //Send Command to change the name
 delay(500);
 while (BTSerial.available()) {
 Serial.write(BTSerial.read());
 }}
void loop() {}

Connecting The DHT-11 Sensor

To use the DHT-11, the DHT library by Adafruit is used. Go here to download the library. When the letter “t” is received, the temperature, humidity, and heat index will be transmitted back via Bluetooth.

circuit to connect DHT-11 with Arduino
circuit to connect DHT-11 with Arduino

The code used to read data from the DHT sensor, process it and send it via Bluetooth:

#include "DHT.h"
#define DHTPIN 2 
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE);
void setup() {
 Serial.begin(9600);
 dht.begin();}

void loop()
{ char c; 
if(Serial.available()) 
 { 
 c = Serial.read(); 
 if(c=='t')
 readSensor();
 }}
void readSensor() {
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 if (isnan(h) || isnan(t)) {
 Serial.println("Failed to read from DHT sensor!");
 return;
 }
 float hic = dht.computeHeatIndex(t, h, false);
 Serial.print("Humidity: ");
 Serial.print(h);
 Serial.print(" %\t");
 Serial.print("Temperature: ");
 Serial.print(t);
 Serial.print(" *C ");
 Serial.print("Heat index: ");
 Serial.print(hic);
 Serial.print(" *C ");
}

Developing The Android App

The flow diagram of the Android app is illustrated below,

Flow diagram of the Android app
Flow diagram of the Android app

As this app will be using the onboard Bluetooth adapter, it will have to be mentioned in the Manifest.

uses-permission android:name="android.permission.BLUETOOTH"

Use the following code to test if Bluetooth adapter is present or not,

BluetoothAdapter bluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
Toast.makeText(getApplicationContext(),"Device doesnt Support Bluetooth",Toast.LENGTH_SHORT).show();
}

The following part of the code deals with reading the data,

int byteCount = inputStream.available();
 if(byteCount > 0)
 {
 byte[] rawBytes = new byte[byteCount];
 inputStream.read(rawBytes);
 final String string=new String(rawBytes,"UTF-8");
 handler.post(new Runnable() {
 public void run()
 {
 textView.append(string);
 }
 });
 }

To send data, pass the String to the OutputStream.

outputStream.write(string.getBytes());

The complete source code of the Android application can be downloaded from here.

Testing

Power up the Arduino and turn on the Bluetooth from your mobile. Pair with the HC-05 module by providing the correct passcode – 0000 is the default one. Now, when “t” is sent to the Arduino, it replies with the Temperature, Humidity, and Heat Index.

the application screen
the application screen

The Winkel Board, All-in-one Arduino Compatible Board

Mintbox Technologies is an Indian tech startup who build smarter connected devices for everyone. It is specialized in consumer electronics, open source software & hardware, PCB design services. Mintbox latest product is The Winkel Board, a powerful new Arduino-compatible, open source hardware platform for development and prototyping.

 

Based on the Atmel ATmega128 microcontroller, The Winkel Board is designed to be easy to use for both junior and senior makers including many popular peripherals such as WiFi, radio, and Bluetooth on board.

Check this video to know The Winkel Board features:

 

By providing an all-in-one compatible Arduino board, Mintbox team is working to solve the routine each maker does before starting a project, which they clarify in this list:

TODO for a maker while building something awesome:
-Prepare a list of right electronics components
-Prepare BOM
-Search them locally or online to fit the BOM
-Wait for the components to arrive if sourced online
-Getting started with prototyping
-Go online again studying libraries and figuring out how they can be interfaced on breadboard or etch a PCB
-Finally start building and actually working on your project and then try not to rage quit

The Winkel Board specifications

  • MCU – Microchip/Atmel ATmega128 MCU @ 16 MHz with 128KB flash memory, 4KB SRAM, 4KB EEPROM
  • Connectivity
    • WiFi 802.11 b/g/n via ESP12E module based on ESP8266
    • Bluetooth 2.0 + EDR via HC-05 module
    • RF Radio – NRF24l01 2.4 GHz ISM radio.
  • I/Os (through both Atmel MCU and ESP8266)
    • 38x Digital I/Os
    • 7x PWM Digital I/Os
    • 8x Analog Inputs
  • USB – micro USB port for programming and power
  • Misc – DS3231 Real-Time Clock + CR2032 battery slot, a few LEDS, reset button, jumper for OTA mode, ISP header, optional MPU-6050 Gyro+accelerometer mount
  • Power Supply – 5 V
  • Dimensions – TBD
Pinout Diagram

 

This board is said to be a one stop platform, that combines different communication protocols and allows a lot of I/O operations, thus you can do everything at once or choose specific on-board components to work with.

The Winkel Board is completely open source, you can check Mintbox’s Github once they upload all the source files soon. This board is now live in a crowd -funding campaign, you can pre-order your own Winkel now for around $21.

Arduino Bluetooth Tutorial HC-05

hc-05-serial_bb-768x446

Bluetooth is typically a low power, medium range device, in fact it can reach up to 10 meters. Bluetooth operates on the same frequencies as WiFi, 2.4Ghz.Connections are normally one to one meaning no group communication is allowed by the protocol. The connection is established by a master device, which connects to a slave device. In internet terminology the master is the client and the slave is the server.

Arduino Bluetooth Tutorial HC-05 – [Link]

Connecting HC-05 Bluetooth Module to Arduino

FZ2U5S4IL6XG9MA.MEDIUM

TechDepot Egypt @ instructables.com has published a tutorial on how to connect a HC-05 Bluetooth module to Arduino. Turorial shows how to connect the module with Arduino and example code is included.

It is worth noting that the HC-05 power in (Vcc) uses 5V, while the transmit and receive (TXD and RXD) logic signal uses 3.3V. Accordingly sending signals from the HC-05 module to Arduino is ok as the Arduino I/O pins can safely receive up to 5V but the issue is when Arduino tries to send the data to the HC-05 with signal level 5V, in this case it is required to use a voltage divider as we will see during the tutorial.

Connecting HC-05 Bluetooth Module to Arduino – [Link]

Bluetooth enabled Door locker using Arduino

arduino-locker

Frank Donald @ gadgetronicx.com has build a bluetooth controlled door locker using Arduino. Source code included:

DIY Arduino based lockers can be found plenty in the internet where keypad was used to feed lock input. But this Bluetooth enabled Door locker uses Bluetooth as a medium to connect with the locker and your smart phone to feed input credentials. This locker allows you to lock/unlock your locker without physical touch when you are within the range of Bluetooth communication.

Bluetooth enabled Door locker using Arduino – [Link]