notes on a way to check if an HC-05 is working properly (and also resetting it to factory default)
Restoring the HC-05 Bluetooth module to its default settings is essential for ensuring optimal performance and resolving configuration issues. This post provides a concise guide on resetting the HC-05 module using an Arduino UNO, detailing the necessary materials, setup, and a sample Arduino sketch to facilitate the process. By following these instructions, users can effectively reset their HC-05 modules, ensuring reliable Bluetooth communication in their projects. (It may not generalize to the entire HC-05 heterogeneity.)
Example
Materials
- Arduino UNO
- USB cable
- HC-05
- breadboard
- wires
Setup
Sketch
#include <SoftwareSerial.h>
SoftwareSerial btSerial(4, 7); //hc-05 RX, TX pins
int hcENpin = 8;
int hcPOWERpin = 12;
char c;
void setup() {
Serial.begin(115200);
Serial.println("setup hc-05 has started");
Serial.println("-----------------------");
hcfiverestore();
Serial.println("-----------------------");
Serial.println("setup hc-05 has ended");
digitalWrite(hcPOWERpin, LOW);
delay(100);
}
void loop() {
digitalWrite(hcENpin, LOW);
digitalWrite(hcPOWERpin, HIGH);
}
void hcfiverestore(){
pinMode(hcENpin, OUTPUT); //hc-05 EN pin
digitalWrite(hcENpin, HIGH); // AT commands mode (HIGH)
pinMode(hcPOWERpin, OUTPUT); //hc-05 power pin
digitalWrite(hcPOWERpin, LOW);
delay(100);
digitalWrite(hcPOWERpin, HIGH);
delay(1000);
btSerial.begin(38400);
delay(100);
btSerial.write("AT\r\n");
Serial.println("[>>] outgoing:");
Serial.print("AT\r\n");
delay(100);
c="";
Serial.println("[<<] return:");
while (btSerial.available() > 0) {
c = btSerial.read();
Serial.print(c);
}
btSerial.write("AT\r\n");
Serial.println("[>>] outgoing:");
Serial.print("AT\r\n");
delay(100);
c="";
Serial.println("[<<] return:");
while (btSerial.available() > 0) {
c = btSerial.read();
Serial.print(c);
}
btSerial.write("AT+ORGL\r\n");
Serial.println("[>>] outgoing:");
Serial.print("AT+ORGL\r\n");
delay(100);
c="";
Serial.println("[<<] return:");
while (btSerial.available() > 0) {
c = btSerial.read();
Serial.print(c);
}
btSerial.write("AT+NAME\r\n");
Serial.println("[>>] outgoing:");
Serial.print("AT+NAME\r\n");
delay(100);
c="";
Serial.println("[<<] return:");
while (btSerial.available() > 0) {
c = btSerial.read();
Serial.print(c);
}
btSerial.write("AT+ADDR?\r\n");
Serial.println("[>>] outgoing:");
Serial.print("AT+ADDR?\r\n");
delay(100);
c="";
Serial.println("[<<] return:");
while (btSerial.available() > 0) {
c = btSerial.read();
Serial.print(c);
}
btSerial.write("AT+ CMODE?\r\n");
Serial.println("[>>] outgoing:");
Serial.print("AT+ CMODE?\r\n");
delay(100);
c="";
Serial.println("[<<] return:");
while (btSerial.available() > 0) {
c = btSerial.read();
Serial.print(c);
}
btSerial.write("AT+STATE?\r\n");
Serial.println("[>>] outgoing:");
Serial.print("AT+STATE?\r\n");
delay(100);
c="";
Serial.println("[<<] return:");
while (btSerial.available() > 0) {
c = btSerial.read();
Serial.print(c);
}
btSerial.write("AT+ BIND?\r\n");
Serial.println("[>>] outgoing:");
Serial.print("AT+ BIND?\r\n");
delay(100);
c="";
Serial.println("[<<] return:");
while (btSerial.available() > 0) {
c = btSerial.read();
Serial.print(c);
}
}
References
Comments
Post a Comment