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.
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:
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.
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.
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.
#include
- SN75370 Dual MOS Memory Interface Circuit
- Simple USB interface data acquisition system
- Isolated transmit/receive loop circuit (XTR105, RCV420)
- How to make a numeric keyboard using XIAO RP2040
- How to make a BLE-enabled smart light bulb using STM32
- Ultrasonic anti-theft alarm designed based on microcontroller and HC-SR04
- Cable test circuit
- A safe and reliable IC card reader/writer system circuit
- Microcomputer motherboard reset part circuit diagram
- Production of infrared receiving controller based on AT89C2051
- Development system using ASCII code keyboard
- Programmable digital clock circuit
- Multipurpose programmable time controller circuit
- Multi-channel programmable time controller circuit
- Programmable function generator circuit
- Programmable bandpass filter using dual T-bridge
- Simple programmable combination lantern circuit
- MC33269 programmable output regulated power supply
- Programmable switched capacitor low pass filter circuit diagram
- Gain Programmable Low Noise Differential Amplifier Circuit