กลับไปหน้ารวมไฟล์
hc-05-with-arduino-using-sensors-3e15f8-en.md

One of the main applications of Bluetooth devices is to send sensor data to another device or use it to make real time calculations to do a specific task or simply display the end result. This data can also be used to automate tasks, control devices and much more.

In this tutorial, we will learn to send sensor data from an Arduino to an app on our smart phone.

Software -

To receive the sensor data, we will use The Arduino Bluetooth Terminal ( click here to download )

Hardware -

Many types of sensors are compatible with the Arduino and can be used with the HC-05 Bluetooth module easily. In this tutorial, we will see how to transmit this sensor data to an app. The HC-05 is a popular Bluetooth module commonly used with Arduino boards for wireless communication. It allows you to establish a wireless link between your Arduino project and other devices, such as smartphones, tablets, or other microcontrollers, enabling you to control or exchange data wirelessly.

Here are some key features and details about the HC-05 Bluetooth module:

  1. Bluetooth Version: The HC-05 module supports Bluetooth version 2.0+EDR (Enhanced Data Rate), providing a relatively stable and reliable connection.
  2. Serial Communication: The module uses a serial communication interface to communicate with the Arduino. It connects to the Arduino board using the UART pins, labeled as RX (receive) and TX (transmit).
  3. Operating Modes: The module has two primary operating modes: Command Mode (AT Mode) and Data Mode (Receiving and Sending data). In AT Mode, you can send configuration commands to the module, specifying parameters such as the Bluetooth name, PIN code, and operating mode. In Data Mode, you can send and receive data.
  4. Power Supply: The HC-05 module requires a power supply of around 3.3V. However, it is usually tolerant of 5V logic levels, making it compatible with most Arduino boards.

In this project we will use input data from a 10k Ω potentiometer (we can use any other sensor). As per the schematic (at the bottom of the page) the middle pin of the potentiometer is the data output pin and the other 2 pins are GND and VCC (this can be interchanged as we don't specifically use it except for power). Here, the data is sent to analog pin 1 (A1) of our Arduino from where it is sent to the smartphone via the HC-05.

To send multiple data inputs, we simply wire them to the Arduino and store them in a variable which is sent over the smartphone via code.

Though we are using the HC-05 Bluetooth module for this project which is very cheap and durable, we use a voltage divider circuit to make sure that the RXD pin doesn't get damaged. It is made by attaching a 1k Ω potentiometer across RXD and Pin 11 and a 2k Ω potentiometer across RXD and Ground.

Code -

The code you provided is an Arduino sketch that sets up a SoftwareSerial communication with a Bluetooth module and reads the value from a potentiometer. It then maps the potentiometer value from the range of 0-1023 to the range of 0-180 and sends it over Bluetooth.

Let's go through the code step by step:

Including Libraries:

  1. The code begins by including the SoftwareSerial library, which allows serial communication on digital pins other than the default RX and TX pins of the Arduino.

Initializing Variables:

  1. The code declares a SoftwareSerial object named "bluetooth" and defines pin 10 as the RX pin and pin 11 as the TX pin for the Bluetooth module. Additionally, it declares a variable named "potentiometer" of type int to store the potentiometer pin number. This is defined as "A1".

Setup Function:

  1. In this function, we initialize the Bluetooth communication at a baud rate of 9600 and set the variable "potentiometer" as an input.

Loop Function:

  1. It reads the value from the potentiometer using "analogRead()", and maps the value from 0-1023 to 0-180 degrees using "map()". It then sends the mapped value over Bluetooth using the "bluetooth.print()" function. A semicolon (";") is added as a *delimiter to separate values. Then, there's a delay of 20 milliseconds before the loop repeats.

Note:

  1. For best results, don't replace the TX and RX pins of the Bluetooth module and follow all the proper instructions in the Hardware section.
  2. A delimiter is a symbol or character used to separate individual pieces of data within a larger sequence. In this case, we use the semicolon to let the app know that the data has ended and make it wait for the next piece of data. Without this line, the app won't know when the data has ended and will continue adding the older data to the newly updated one.
  1. Additionally, make sure you have the required libraries installed. In this case, you need to have the "SoftwareSerial" library installed in your Arduino IDE. You can install it by going to "Sketch > Include Library > Manage Libraries" and searching for "SoftwareSerial".

APP -

Application Instructions Set Up:

  1. Power the Arduino.
  1. Now, the HC-05 module should blink rapidly.
  1. Next, open the app.
  1. Allow it to access Bluetooth settings.
  1. In the list, select HC-05.
  1. Select receiver mode.
  1. Now the module should blink once every 2 seconds.
  1. Here, click the link 🔗 icon on the bottom right hand corner.
  1. It will load for some time now.
  1. Afterwards, this is what you will see -

EXPANDED TECHNICAL DETAILS

Wireless Serial Sensor Telemetry

This project provides a professional framework for streaming real-time sensor data from an Arduino to a smartphone or PC via Bluetooth.

  • HC-05 Master/Slave Pipeline: Configures the HC-05 module using AT commands. The Arduino captures data from multiple sensors (e.g., Temp, Light, Motion) and packs them into formatted strings sent over a 9600-baud UART link.
  • Android Terminal Interface: Uses a standard Bluetooth Terminal App. The user can see the sensor values in real-time and send character-based commands back to the Arduino (like "L" for LED Toggle).

Scalability

  • CSV Data Packing: The firmware formats the output as Sensor1,Sensor2,Sensor3, making it easy for the receiving side to parse the data for charting or logging.

ข้อมูล Frontmatter ดั้งเดิม

title: "HC-05 with Arduino using Sensors"
description: "Learn how to send sensor data using an Arduino"
author: "uniostar"
category: "Lab Stuff"
tags:
  - "Communication"
  - "Home Automation"
  - "Monitoring"
  - "Remote Control"
  - "Smart appliances"
  - "Security"
  - "Tracking"
views: 294
likes: 1
price: 1120
difficulty: "Easy"
components:
  - "1x HC-05 Bluetooth Module"
  - "1x 10k Variable Resistor"
  - "1x 2K Resistor"
  - "1x 1k Resistor"
  - "1x Breadboard - 830 contacts"
  - "1x Arduino Nano"
  - "1x Electrical Cables"
tools: []
apps:
  - "1x Arduino IDE"
  - "1x Arduino Bluetooth Terminal"
downloadableFiles: []
documentationLinks: []
passwordHash: "9de6095cdcdd3732df7811d6c59762655319510588346881ed27f26c38249d3e"
encryptedPayload: "U2FsdGVkX1/8yBaI314aaWQ8WLQXVeMzn5U+rY0Z9EtRjviIPV1xtUYf/MqWg0zdhnJ3JYzEPZ+iSgQnZVfxDh/QtEi+43QDkcdv2iuyw0DSbVo7tgwsf8aj1lqtETtscgUDr4cOA9KnlWTWiA8gFg=="
seoDescription: "Learn how to connect HC-05 with Arduino to transmit sensor data wirelessly via Bluetooth in this step-by-step guide."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/hc-05-with-arduino-using-sensors-3e15f8_cover.jpg"
lang: "en"