Bluetooth Programmer

Bluetooth Programmer

Difficulty: Beginner

Bluetooth modules such as the HC-05 allows makers an easy to integrate solution for adding bluetooth capability to projects. These modules can be configured using AT commands and a home made programmer. In this tutorial I will show you how to make a bluetooth programmer that can be used with HC-05 bluetooth modules.

The below diagram shows the interconnections for the BT programmer;

 

In order to program a BT module you need to give it 5v, GND and attach the TX and RX pins to digital IO pins on the Arduino. In this example I decided to use pins 4 and 3. I also used pin 5 to put a logic high on the EN pin of the HC-05. This will put the HC-05 into AT command mode as soon as its inserted into the programmer so you don't need to mess about with the EN button. For this to work the programmer should be powered up then the HC-05 inserted after.

Once you've made the above circuit upload the below code to the Arduino;

/*
AUTHOR: David Bradshaw
DATE: 25 April 2019
*/

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(4, 3);

void setup()
{
	pinMode(5, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
	digitalWrite(5, HIGH);
	Serial.begin(57600);

	//A simple prompt incase you forget 
	Serial.println("When you apply power to the Arduino ensure that the button is held down on the HC-05 ");
	Serial.println("to put it into AT command mode or insert the HC-05 after power is applied.");
	Serial.println("If this is done correctly the LED will flash once every 2 seonds, if this happens the ");
	Serial.println("HC-05 is in AT command mode.");
	Serial.println("Ensure that BOTH NL AND CR are selected on you serial program. If the module is ready to be ");
	Serial.println("programmed the LED (pin 13) will be illuminated and if you type AT then press enter the module should");
	Serial.println("return the string OK.");

	Serial.println("for a list of AT commands and more information visit: https://www.l33t.uk/arduino_projects/bluetooth-programmer/");

	Serial.println("Enter AT commands:");
	BTSerial.begin(38400);  // HC-05 default speed in AT command more FOR HC-05= 38400, HC-08=9600, not sure about other BT modules
}

void loop()
{
	// Keep reading from HC-05 and send to Arduino Serial Monitor
	if (BTSerial.available())
		Serial.write(BTSerial.read());

	// Keep reading from Arduino Serial Monitor and send to HC-05
	if (Serial.available())
		BTSerial.write(Serial.read());
}
HC-05 Programmer Code

The above code creates a software serial connection to the HC-05. this will allow you to pass AT commands from the Arduino's serial port to the HC-05. Please note that the baud rate of the HC-05 is 38400 if you use a different bluetooth module this may differ. This baud rate is the AT command mode baud rate and can not be altered; it is different to the UART baud rate that can be altered for bluetooth communication. In order to program the HC-05 open the serial monitor, set the baud rate to 57600 (this is the baud of the hardware serial port) and type "AT", if the serial monitor returns OK then the HC-05 is ready for programming. I advise that you insert the HC-05 after the programmer has been powered up this will allow the HC-05 to go into AT command mode straight away.

The main loop of the program listens for commands from the serial monitor and relays them to the software serial port and vice versa allowing you to have full duplex communications with the HC-05 enabling it to be programmed via AT commands.

This document HC-05 AT Commands contains a list commands that can be used with the HC-05.

The below video shows how to use the Bluetooth programmer when configuring a HC-05 module;

Leave a Reply

Your email address will not be published.