Home > Microcontroller >Comprehensive Circuits > How to Program an Arduino via Bluetooth

How to Program an Arduino via Bluetooth

Source: InternetPublisher:风向西瓜 Keywords: Bluetooth Programming Arduino Updated: 2024/12/19

Arduino Uno, the most popular microcontroller among electronics hobbyists and students, using Arduino it is easy to get started with embedded systems but one disadvantage of Arduino is that it needs to be connected to a computer using a USB cable to upload the code as it does not have any onboard support for wireless communication. Sometimes it becomes difficult to connect the board with the PC if your project is fixed at some place. The only way to solve this problem is to program the Arduino wirelessly . Wireless programming or OTA (Over the Air) programming can be done easily in ESP8266 and ESP32 as they have inbuilt Wi-Fi support. But in Arduino, we have to use a Bluetooth module to program it wirelessly. So here we will learn how to program Arduino via Bluetooth.

Required Components

Arduino UNO

HC05 Bluetooth module

Jumper Wires

1K, 2.2K resistors

Capacitor (0.1uF)

Power adapter

Breadboard

HC05 Bluetooth module

HC-05 module is a Bluetooth serial protocol module designed for wireless communication between microcontrollers . HC-05 Bluetooth module provides switching mode between master and slave mode configuration and communicates through serial communication at 9600 baud rate for easy interfacing with controllers. HC05 module operates on 3.3 V but we can connect it to 5V supply voltage as the module comes with an onboard 5v to 3.3 V regulator.

poYBAGLyLPGARKv8AAQIKcnkQ68992.png

Bluetooth is the simplest wireless communication method and we have built many interesting projects using it like Bluetooth controlled robot, Bluetooth voice control, Bluetooth home automation etc. You can check all Bluetooth based projects here.

Programming Arduino via Bluetooth

To wirelessly program the Arduino, first, we must program the Arduino to respond to AT commands. To do this, connect the Arduino to the serial port of your laptop and upload the following code:

#include

The first two lines of code are used to include the SoftwareSerial library and define the transmitter and receiver pins for connecting to Bluetooth. The SoftwareSerial library is used to allow serial communication with digital pins other than the hardware Tx and Rx pins of the Arduino. Multiple software serial ports can be used for serial communication using the SoftwareSerial library.

#include

Now in the setup function, define the baud rate for the hardware and software serial ports. The baud rates for the hardware and software serial ports are 9600 and 38400 respectively.

void setup()
{
SerialNumber.Start(9600);
Serial.println("Enter AT command: ");
HC05.start(38400);
}

Two if conditions are used inside the loop function. The first condition checks if any command is given to HC05, if yes then it is written to the Arduino serial monitor. The second condition checks if any command is sent to the Arduino serial monitor, if yes then it is sent to the HC05.

void loop()
{
  if (HC05.available())
    Serial.write(HC05.read());
  if (Serial.available())
    HC05.write(Serial.read());
}

Next, connect Arduino to HC05 and put it into AT command mode. The circuit diagram for the same is as follows:

poYBAGLyLOuAKmePAADZTxpj0oA289.png

Before connecting the Arduino to the computer, press the button and then connect the Arduino to the computer. Keep pressing the button until the Bluetooth module LED starts blinking at 2 second intervals. The Bluetooth module LED blinks slower in command mode than in normal mode.

Now open a serial monitor and enter the following commands, in return the board will respond with “OK” every time the command runs successfully.

AT+ ORGL

AT+ROLE=0

AT+POLAR=1,0

AT+ UART=115200, 0, 0

AT+INIT

After successfully testing the AT commands, simply remove all connections and connect as per the diagram below.

pYYBAGLyLOaAEvB0AAJCONO9GQ8695.png

poYBAGLyLOKAYyqYAAWjhKEbPkY879.png

Power the Arduino using an adapter or a 9V battery . After that, go to Devices in your laptop, turn on Bluetooth, and connect the Bluetooth module to your laptop.

After the devices are paired successfully, the next task is to find the COM port of the HC05 Bluetooth module. To do this, go to the Device Manager and check the COM Port option. It will show two COM ports, one for incoming and the other for outgoing. When uploading the program, we need to select the second COM port number.

pYYBAGLyLN6AH3kwAABh_aZHJnM201.png

Now open Arduino IDE and select the blink program, choose the correct com port and hit the upload button. If everything goes well, the Arduino onboard LED will start blinking at 1 second intervals.

poYBAGLyLNqAY9FpAACm3ag937A673.png

#include

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号