Arduino Uno, the most popular microcontroller among electronics enthusiasts and students, it’s easy to get started with embedded systems using the Arduino, but one downside of the Arduino is that it needs to be connected to a computer using a USB cable to upload code, as it’s already done on the There is no onboard support for wireless communication. Sometimes it can be difficult to interface the board with the PC if your project is fixed somewhere. The only way to solve this problem is to program the Arduino wirelessly. Over-the-air programming or OTA (over-the-air) programming can be easily done in ESP8266 and ESP32 because of their built-in Wi-Fi support. But in Arduino we have to program it wirelessly using bluetooth module. So here we will learn how to program Arduino via bluetooth.

required components

Arduino UNO

HC05 Bluetooth module

Jumper

1K, 2.2K resistors

Capacitance (0.1uF)

Power Adapter

Breadboard

HC05 Bluetooth module

The HC-05 module is a Bluetooth serial port protocol module designed for wireless communication between microcontrollers. The HC-05 Bluetooth module provides switching modes between master-slave configurations and communicates via serial communication at 9600 baud for easy interfacing with the controller. The HC05 module works on 3.3 V, but we can connect it to 5V supply voltage because the module has an onboard 5v to 3.3 V regulator.

Bluetooth is the easiest way to communicate wirelessly, and we have built many interesting projects with it, such as Bluetooth controlled robots, Bluetooth voice control, Bluetooth home automation, etc. You can view all bluetooth based projects here.

Program the Arduino via Bluetooth

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

#includeSoftwareSerial HC05(2,3); void setup() { serial number. start(9600); Serial.println("Enter AT command: "); HC05. start(38400); } void loop() { if (HC05. available()) Serial.write(HC05.read()); if (Serial.available()) HC05.write(Serial.read());}

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

#includeSoftwareSerial HC05(2,3);

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() { serial.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 issued to the HC05, if so it writes it to the Arduino serial monitor. The second condition checks if any command is sent to the Arduino serial monitor, if so it sends it to the HC05.

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

Next, connect the Arduino to the HC05 to enter the AT command mode. The same circuit diagram is as follows:

Before connecting the Arduino to the computer, press the keys first, then connect the Arduino to the computer. Press and hold 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 command, 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

AND+HEAT

After successfully testing the AT commands, simply remove all connections and connect as shown in the schematic below.

Power the Arduino with an adapter or a 9V battery. After that, go to “Devices” in the laptop, turn on the bluetooth, and connect the bluetooth module to the laptop.

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

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


#include
SoftwareSerial HC05(2,3);
void set()
{
SerialNumber.Start(9600);
Serial.println(“Enter AT command:”);
hc05.start(38400);
}
void loop()
{
if(HC05.available())
Serial.write(HC05.read());
if (Serial.available())
HC05.write(Serial.read());
}

Leave a Reply

Your email address will not be published.