Bluetooth module with arduino uno

Урок 15. Bluetooth модуль HC-06 подключение к Arduino. Управление устройствами с телефона.

ГЛАВНАЯ / Уроки и проекты / Урок 15. Bluetooth модуль HC-06 подключение к Arduino. Управление устройствами с телефона.

Очень часто в ваших проектах возникает необходимость в дистанционном управлении или передачи данных с ваших телефонных гаджетов.

Один из самых популярных и распространенных методов обмена данными посредством Bluetooth.

Сегодня мы разберем простые примеры как можно подключить Bluetooth модуль к Arduino и настроить дистанционное управление с телефона.

Нам понадобится:

Схема подключения Bluetooth к Arduino:

Подключать Bluetooth модуль к микроконтроллеру Arduino удобнее всего с помощью проводков ПАПА-МАМА.

Arduino Bluetooth
Pin 1 (TX) RXD
Pin 0 (RX) TXD
GND GND
5V VCC

Будьте внимательны, подключать подключать нужно TX -> RXD ,RX -> TXD.

Теперь необходимо записать пробный код программы:

Во время загрузки скетча необходимо что бы Bluetooth модуль был отключен от микроконтроллера arduino. В противном случае скетч не запишется, потому что связь с Bluetooth модулем происходит по одному и томуже порту RX и TX, что и USB.

int val; int LED = 13; void setup() < Serial.begin(9600); pinMode(LED, OUTPUT); digitalWrite(LED, HIGH); >void loop() < if (Serial.available()) < val = Serial.read(); // При символе "1" включаем светодиод if (val == '1') < digitalWrite(LED, HIGH); >// При символе "0" выключаем светодиод if ( val == '0') < digitalWrite(LED, LOW); >> >

После того как скетч записан и Bluetooth модуль подключен к Arduino, можно перейти к следующему шагу.

Подключение Bluetooth к телефону

Желательно в качестве источника питания для arduino использовать не USB, а внешний Блок питания на 9 В.

  1. Включаем Bluetooth на телефоне и ищем новые устройства
  2. Находим в списке расстройств «HC-06″ и подключаемся к нему.
  3. Телефон спросит пин-код. необходимо ввести «1234» или «0000«
  4. Ура. Устройство подключено.

Теперь нужно скачать bluetooth terminal на ваш телефон. Мы рассмотрим на примере платформы Android.

Вы можете установить разные bluetooth терминалы, как правило они отличаются только разными дизайнами, функционал от этого не меняется. Так же можно найти и терминал и для продуктов ios.

После того как мы установили терминал, запускаем его выбираем наш bluetooth модуль HC-06 и подключаемся к нему.

Пришло время попробовать проект в деле. Пишем в терминале цифру «0» и отправляем. Светодиод L который находится на плате arduino рядом с pin 13, должен погаснуть. Теперь отправим через терминал цифру «1» и светодиод L должен зажечься.

Демонстрация работы:


Домашняя работа:

  • Изменить скетч так, что бы светодиод зажигался и потухал с помощью одной и той же команды например «G».
  • Дописать скетч и научить его преобразовывать текстовые данные приходящие через блютус в цифровые и реализовать димер, зажигать светодиод с помощью ШИМ, на заданную яркость от 0 до 254 приходящую через bluetooth.
Читайте также:  Bluetooth aux адаптер рейтинг

Источник

How to Interface Bluetooth Module (HC-05) with Arduino Uno

The Arduino Uno is the most commonly used board of the Arduino family as it can be used for a variety of projects which also include some high-end projects as well. Similarly, there are a large number of devices that can be interfaced with the Arduino Uno board. The bluetooth module is an excellent communication device that can be interfaced with Arduino for short range communication. In this discourse we have interfaced a Bluetooth module with Arduino Uno.

Bluetooth module (HC-05)

The Bluetooth module is a device which is used for short range wireless communication to the respective connected device. This module uses serial port protocol for the wireless communication and comes with two configurations that are master and slave. In the master mode the module searches for the other devices to connect and can connect to the other devices. However in the slave mode the module cannot connect to the devices by itself. In short the master more the device control other devices and in slave mode the device is being controlled by some other device.

To change the master slave configuration, we can use the AT commands of the Bluetooth module. Moreover, to use the AT mode we have to set the baud rate of 38400 and for serial communication we have to use the baud rate of 9600.

This module can connect the devices in the range of 10 meters of the Bluetooth and it works on the 2.4GHz frequency band. The Bluetooth module operates on the voltage ranging from 3.3 volts to 5 volts and has 6 pins in total and the description of each pin of the Bluetooth module is in the table below:

Pin Description
1-(EN) Pin for using the Bluetooth in command mode by setting the baud rate 38400 and giving this pin HIGH state. By default, the module is in the data mode, so this pin has a LOW state.
2-(Vcc) Pin for giving supply to the Bluetooth module that is 5 or 3.3 volts
3-(GND) Pin used to ground the Bluetooth module
4-(TXD) Pin used for transferring the data through Serial communication on the serial monitor of Arduino IDE
5-(RXD) Pin used for receiving the data through serial communication
6-(STATE) To check whether the module is connected or not this pin is mainly used

Interfacing Bluetooth module with Arduino Uno

The Arduino code for interfacing the Bluetooth module with Arduino Uno board is given followed by the schematic of the circuit designed for interfacing the Bluetooth module with Arduino Uno . We have used the following list of components for interfacing the Bluetooth module with Arduino Uno.

  • Arduino Uno
  • Connecting wires
  • Bluetooth module(HC-05)
  • One LED
  • One 220 ohm resistor

Hardware assembly for interfacing Bluetooth with Arduino Uno

To demonstrate the connections of the Bluetooth module with Arduino we have posted an image of the hardware assembly of the circuit.

In the circuit the yellow wire connects the LED with Arduino Uno and the brown color wires are connecting the data pins of the Bluetooth module.

We have connected the Bluetooth module with the supply using the 5 volts and ground pin of Arduino.

How to connect Arduino Bluetooth module (HC-05) with computer

To connect this module with the computer follow the steps given below:

First go to the settings option of the Windows and then click on the Bluetooth devices from there you can turn on the Bluetooth of your computer. To connect the device by paring it with your computer click on the “Add device” button.

Читайте также:  Nikon d5100 есть ли блютуз

After clicking a dialog box named “Add a device” is appeared, click on the first option that is Bluetooth:

Then you will see that the Bluetooth module (HC-05) will appear when your computer starts searching for the devices:

Click on the Bluetooth module that is “HC-05” and it will ask the password for pairing your computer with it. The passcode for pairing is “1234” by default.

Now we can see that the device is paired with the computer and is connected with it. You can see it in the bluetooth and devices menu in the setting of your computer.

To check on which COM the Bluetooth is connected to the computer we open the control panel and select the hardware and sound option is the control panel menu.

After that we go to the devices and printers option to see the devices connected with the computer. Here we have the Bluetooth module “HC-05” connected to our computer.

To check on which pin the module is connected we have to go to the properties of the Bluetooth module:

After that go to its hardware properties of the HC-05 and you will see in the device properties on which COM the Bluetooth is connected. Here on the COM 6 the Bluetooth is connected.

Arduino code to interface Bluetooth module (HC-05)

The Arduino code for interfacing the Bluetooth module is:

char data = 0 ; //declaring Variable for storing received data
void setup ( ) {
Serial. begin ( 9600 ) ; // baud rate for serial data transmission
pinMode ( 13 , OUTPUT ) ; /*assigning digital pin 13 to LED and giving it an output mode */
}
void loop ( ) {
if ( Serial. available ( ) > 0 ) // checks if any data is received
{
data = Serial. read ( ) ; */ Reading any receiving data and storing it into variable named data */
Serial. print ( data ) ; //displaying the data
Serial. print ( » \n » ) ; //adding space by giving a New line
if ( data == ‘1’ ) // when the value is equal to 1
digitalWrite ( 13 , HIGH ) ; // turn the LED
else if ( data == ‘0’ ) // when the value is equal to 0
digitalWrite ( 13 , LOW ) ; // turn off the LED
}
}

In this code we have changed the state of the LED by sending data to the Bluetooth module. The code for interfacing the Bluetooth is compiled in such a way that first we have declared the variable in which the data will be stored. After that in the setup function, we have given the baud rate for the serial communication and assigned mode and pin to the LED.

In the loop function we have used the function Serial.available() to check if any data is entered using the serial monitor. After that to read the data if received we have used the function Serial.read() and then this data is printed in the serial monitor using the function Serial.print().

Next, we have used the if conditions using the digitalWrite() function. If 1 is entered in the serial monitor of COM6 on which the Bluetooth is connected then turn on the LED and if 0 is entered in the serial monitor of COM6 the LED will turn off.

Note: There might be different ports for each computer on which the Bluetooth module is connected. Here in our case it is COM6.

Hardware implementation of interfacing Bluetooth module (HC-05) with Arduino Uno

To give the input to the Bluetooth we have to select the port on which the Bluetooth is connected. We can do this by going into the tool menu in the Arduino IDE and then clicking on port option and then selecting the port of the Bluetooth.

Читайте также:  Сколько заряжать bluetooth гарнитуру

Here in our case, it is connected at COM6 so we will select COM6 and below on the serial monitor we can see that in the gray tab the COM is changed from COM4 to COM6:

When we give the input of 1 using the serial monitor by writing 1 in the gray bar and pressing ctrl+Enter:

Now if we enter 0 in the serial monitor the LED will turn off:

Conclusion

The Bluetooth module is a small range wireless communication device that can be used for various purposes like sending of data or controlling of devices connected with it. Furthermore, it can be interfaced with Arduino Uno and can be used in multiple projects where wireless communication is required for a small range. In this write up we have interfaced the Bluetooth module with Arduino Uno and controlling the LED by sending data through the Bluetooth module.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.

Источник

Interfacing HC-05 Bluetooth Module with Arduino Uno

I am a blogger and robotician who works on different electronic projects. I work on hobby projects and sharing my knowledge through this platform. I do work on Arduino, microcontrollers, IoT, Raspberry Pi, circuit designing and PCB designing.

Ligo George says:

sarah ansari says:

Hey, I am working on a project which uses Bluetooth HC-05 as one of its components. If there are multiple inputs then where is the data of all the inputs stored? Is it in the sd card of the phone?

Matrix Keypad

Reading Multiple Pressed Keys from Matrix Keypad using PIC Microcontroller

I have already post about Interfacing Matrix Keypad with PIC Microcontroller. I suggest to read that article before reading this. Read More

LCD Custom Characters

Custom Characters on LCD using PIC – MikroC

I hope that you already go through our tutorial, Interfacing Character LCD with PIC Microcontroller — MicroC Pro. These character. Read More

Diptrace

Getting Started with DipTrace

DipTrace is a software that allows you to create simple and complex Printed Circuit Boards from schematic diagrams to layouts. Read More

PWM - Pulse Width Modulation

Generating PWM with PIC Microcontroller – MPLAB XC8

Pulse Width Modulation (PWM) is the one of the simple and most commonly used technique to produce analog voltages from. Read More

json

Calling API using ESP8266

The objective of this tutorial is to explain how to do HTTP JSON GET requests using an ESP8266 and Arduino. Read More

Push Button Switch

Using Push Button Switch with PIC Microcontroller

Introduction This article is meant for beginners in the field of microcontrollers. When I started with microcontrollers, as everyone I also. Read More

Interfacing DC Motor with Atmega32 Microcontroller

In some of your electronic projects you may want to control a DC Motor with Atmega32 Microcontroller. We can’t connect. Read More

DS1307 RTC

Interfacing Real Time Clock (RTC) DS1307 with PIC Microcontroller

DS1307 is a low power serial real time clock with full binary coded decimal (BCD) clock/calendar plus 56 bytes of. Read More

Analog to Digital Converter

Using ADC of PIC Microcontroller – MPLAB XC8

In this tutorial we will learn, how to use the ADC module of a PIC Microcontroller using MPLAB XC8 compiler. Read More

Using UART of PIC Microcontroller – Hi Tech C

UART stands for Universal Asynchronous Receiver / Transmitter. It is a serial communication interface which uses two lines for sending. Read More

Источник

Оцените статью
Adblock
detector