Tag Archives: Bluetooth

Arduino Two-Way Bluetooth Communication Tutorial

Welcome to another Arduino Tutorial! Today we are going to learn how to use Bluetooth to exchange data between two Arduino boards! As a demonstration project, we are going to build a simple weather station. There is a lot to cover so let’s get started!

Arduino Two-Way Bluetooth Communication Tutorial – [Link]

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

GPS vs. Beacons vs. Wi-Fi: Three Location Identifier Technologies

In IoT and digital age, location-based services applications are widespread: starting from Google maps to anti-loss devices and not ending with location-based marketing. The most common technologies used for user location identification are: GPS, WiFi and Beacons (a custom BLE profile).

Location-based (geofencing) marketing is a new way to enhance the personal experience while shopping. For example if you were near the shampoo section you will get on your mobile exclusive offers about that section.

Choosing the right location detection technology needs to take into consideration that GPS works optimally in the open sky environments and WiFi and Beacons can work probably indoors (and outdoors but within inhabited areas with hotspots). Now let’s get a brief look at each technology:

GPS

Thanks to on-the-shelf GPS modules/receivers from vendors like: Neoway and u-blox it’s easy to embed a GPS receiver into your project. What you need is a module sending its messages via UART to the MCU and a ready-made antenna attached to the module. There is a standard format for these modules messages called NEMEA. These messages contain information about the location that includes longitude, latitude, direction, speed … etc. These receivers need to see at least 4 satellites to compute a position.

There are many navigation systems like the Russian GLONASS, the European Union’s Galileo and the American GPS.

gps system how it works
Image courtesy of: Geneko

GPS is mainly designed to be an outdoor location detection system. Therefore, its performance decreases in enclosed places and across crowded areas with buildings.

WiFi

WiFi can be used in location detection (AKA Wi-Fi positioning system) when your phone or WiFi transceiver module like ESP32 or ESP8266 is near hotspots. You can consider WiFi like a coexisting system with GPS for indoor areas. Moreover, WiFi can be used to detect the location inside the enclosed/underground area; you can see the SubPos project on Hackaday to know how.

Image Courtesy of Blecky

Location detection systems using WiFi use techniques based on received signal strength indication (RSSI), angle of arrival (AoA) and time of flight (ToF). You can read more about these techniques from the Wikipedia article.

Bluetooth Beacons

Beacon technology is enabled by Bluetooth Low Energy (BLE) and it’s one of the BLE custom profiles. Beacons are used for proximity-aware applications like positioning indoors, and for location based advertisements. The idea behind this technology is to calculate the distance between the receiver and the transmitter by calculating the difference between the power of the sent and received signal (comparing the Received Signal Strength Indicator (RSSI) to a transmit (Tx) power). Knowing that, the power information is available in Apple iBeacon advertising packet (for example).

 

To know more about Bluetooth beacons please refer to our previous post about Beacons.

Read more about these three technologies in the DZone’s article.

Control Your IR Devices With Your Smartphone Bluetooth

Managing some of house devices with its IR remotes may be annoying if you are out of its line of sight. You will have to interrupt the work you are doing, move to another room, turn down the volume of your Hi-Fi for example, then go back and resume your work. Assume you can use bluetooth instead of this process, it will be a time saver and it will maintain your focus.

Using an Arduino UNO with IR and Bluetooth shields, you can create your own bluetooth-controlled general purpose remote control. Bluetooth is a good choice because it doesn’t need any active network to connect with a mobile device. Connection between them is direct (point-to-point) and is suitable for small areas. However, by using a wireless shield you will be able to control the devices through the internet.

A project by Open Electronics demonstrates how to build and program such a device. Its hardware side consists of an Arduino with two shields, and the software side is an Android application. The tutorial shows in details how each shield will work, and also how to setup and prepare the mobile application.

Parts needed for the project:

  • An Arduino Uno board or equivalent (e.g. Fishino Uno);
  • An ArdIR shield:An Arduino shield that allows creating a programmable infrared universal remote manageable from the Internet. It simulates the remote control of TVs, home appliances and air conditioners, by transmitting the same data to the desired.
  • A Bluetooth shield:
    A shield for Arduino based on the RN-42 module. It also has a dip switch that allows you to set up the modes of operation of the module RN-42.
  • A smartphone or tablet with Android OS (version 4.1 or higher), of course complete with a Bluetooth interface.

The mobile application is compatible with Android OS devices of version 4.1 (jellybean) and higher. It needs two phases to be handled:

  1. Research and connection to the target Bluetooth device.
  2. Selection and activating one of the channels, for transmitting the code to the shield.

Once the connection with the Bluetooth shield is established and the channel is selected, the program will be ready to handle a subsequent command by the user and will be listening to possible result messages returned by the remote Bluetooth device.

There is no need for additional hardware parts and work, you only have  to assemble both shields on the Arduino board. But before that, you have to upload a sketch to Arduino for handling the ArdIR shield and managing the communication with the Bluetooth shield.

For more information about how the project works, the structure of the application and source files, you can read the original guide.

Next-generation Bluetooth Low Energy SoC from ST

Graham Prophet @ eedesignnewseurope.com introduces BlueNRG-2, the latest BLE solution from ST. He writes:
Introducing its latest-generation Bluetooth Low Energy (BLE) System-on-Chip, ST Microelectronics highlights low power, small size, and high performance to enable widespread deployment of energy-conscious, space-constrained applications with BLE connectivity. The device provides state-of-the-art security and is Bluetooth 5.0-certified
Next-generation Bluetooth Low Energy SoC from ST – [Link]

Pi Desktop Case – include peripherals too

The ‘Pi Desktop’ kit from element14 offers some great features like Wi-Fi, Bluetooth, a real-time clock, an interface for an mSATA-SSD hard drive, an optional camera, heat sink, a neat power switch and of course the sleek black case. [via]

The Raspberry Pi is a well designed, powerful and inexpensive board, but not a complete computer. Some distributors know you need more than just a plastic case and a mains-adapter power supply (or USB cable). The ‘Pi Desktop’ kit from element14 contains everything you need and more, turning your RPi into a fully fledged computer.

Pi Desktop Case – include peripherals too – [Link]

Add WiFi & Bluetooth Easily With Koala® Connect Modules

Clarinox Technologies Pty Ltd was formed with the aim of providing cost effective and innovative wireless embedded systems solutions to business. Due to the experience of the Clarinox team, more embedded systems are designed to develop leading edge solutions. In addition to delivering flexible and robust wireless protocol software for embedded systems developments.

Clarinox hottest products are Koala® Connect Modules! A compact option for adding Wi-Fi® and / or Bluetooth® to new and existing projects.

These modules will give you a stable environment while used with Koala® EVM, the first and only development board to support development for all major wireless technologies. It enables embedded systems developers to create both low and high power wireless systems communicating over Wi-Fi, Bluetooth Classic and Bluetooth Low Energy. It provides a fast and cost effective way to commence embedded wireless development with all major wireless technologies.

Each module features a single onboard processor to drive the user application in addition to multiple wireless protocols. The modules available are:

Koala® Connect Modules
KM-141201 (20 x 30mm BT/BLE)
KM-153101 (20 x 34mm Wi-Fi+BT/BLE)

Carrier Board for Koala® Connect
KC-018102

Sensor Modules
KM-990501 Sensor Board

The Koala EVM and wireless module family will help shorten development time, reduce development costs, and open the door to new possibilities for wireless device features.

And these are the specifications

Hardware Specifications

MCU: STM32F411 (Bluetooth/BLE), STM32F412 (Wi-Fi + Bluetooth/BLE)

Wi-Fi Radio: TI WL1831MOD / WL1837MOD

  • 802.11 a/b/g/n
  • 2.4 GHz & 5 GHz
  • -96.3dBm RX Sensitivity
  • STA, AP & Wi-Fi Direct Modes

Bluetooth / Bluetooth LE Radio: TI WL1831MOD / WL1837MOD

  • Dual-mode Bluetooth & Bluetooth Low Energy
  • Bluetooth v4.1 Compliance and CSA2 Support
  • Host Controller Interface (HCI) Transport for Bluetooth Over UART

I/O Signals: ADC, GPIO, I2C, I2S, SPI, UART, USB

Industrial Temperature Grade: -40°C to +85°C

Software Specifications

Supported Technologies: Wi-Fi WLAN, Wi-Fi Direct Concurrent Operation (Multichannel, Multirole), Bluetooth, Bluetooth LE

You can get your own products from Clarinox by filling this inquiry. More details about Koala Connect Modules are available here, also a start manual for KoalaEVM is available here.

Bluetooth Smart module is only 11x8x1.8mm

By Julien Happich @ eedesignnewseurope.com:

Amber wireless GmbH’s AMB2621 Bluetooth Smart module is a 2.4 GHz BLE wireless module based on the Bluetooth Smart 4.2 standard, measuring only 11x8x1.8mm and offered with or without integrated antenna.

Arduino-Programmable ESP32 Development Board

Ezsbc, an American embedded control solutions retailer, had produced a new development board that simplifies working with ESP32 module and makes it programmable via USB using the Arduino IDE.

The ESP32 is a low cost, ultra low power microcontroller with integrated Wi-Fi & dual-mode Bluetooth, which employs a dual-core Tensilica Xtensa LX6 microprocessor. ESP32 is created and developed by Espressif Systems for mobile devices, wearable electronics and IoT applications. It is a successor to the ESP8266 microcontroller.

Other than the ESP32 module, the board has an FTDI FT231XS USB to Serial converter, a 3.3V LDO, reset and flash switches and a multi color LED. The module can be programmed directly from the Arduino environment with 921600 bps upload speed.

It supports auto-download and will automatically be set in download mode by the downloader. Once the download is complete the board will be reset, just like a normal Arduino board.

Features of the ESP32 board:

  • 240 MHz dual core Tensilica LX6 microcontroller with 600 DMIPS
  • Integrated 520 KB SRAM
  • Integrated 802.11BGN HT40 Wi-Fi transceiver, baseband, stack and LWIP
  • Integrated dual mode Bluetooth (classic and BLE)
  • 16 MByte flash
  • 2.2V to 3.6V operating voltage
  • On-board PCB antenna
  • 3 x UARTs, including hardware flow control
  • 3 x SPI
  • 2 x I2S
  • 12 x ADC input channels
  • 2 x DAC
  • 2 x I2C
  • PWM/timer input/output available on every GPIO pin
  • SDIO master/slave 50 MHz
  • Supports external SPI flash up to 16 MB
  • SD-card interface support

The board is available for $17 on tindie store. Datasheet, documentation, and schematics are also available there.

Embedded IoT gateway, in a 17 x 25 mm footprint

Lantronix, Inc. has added the xPico 200 family of embedded IoT gateways that measure 17 by 25 mm, to rpvide secure Ethernet, Wi-Fi and/or Bluetooth connectivity for smart IoT solutions. by Graham Prophet @ edn-europe.com:

The xPico 200 series will feature enterprise security, networking intelligence, and pre-integration with Lantronix’s MACH10 management software platform in a compact footprint that enables the functionality of a powerful IoT device gateway to be integrated into machines not previously practical.

Embedded IoT gateway, in a 17 x 25 mm footprint – [Link]