Skip to content

Instantly share code, notes, and snippets.

@CodeNextAdmin
Created March 20, 2023 23:14
Show Gist options
  • Save CodeNextAdmin/4c16e52fa4514f36deea121bbd2e6da6 to your computer and use it in GitHub Desktop.
Save CodeNextAdmin/4c16e52fa4514f36deea121bbd2e6da6 to your computer and use it in GitHub Desktop.
arduino hc-06 BT Serial Test
/* Code Next Arduino Robotics club
* TEST your HC-06 with this sketch;
* - Give the Modle 5V of power (VCC)
* - Try some test commands: AT -> should reply OK
* - Rename it AT+NAMEyournewname -> should reply with OKsetname
* - Connecting to RX and TX pins (0, 1) gives an upload error if wired, use 10, 11 instead.
*/
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
// Connect the HC-06 TX to the Arduino RX on pin 10.
// Connect the HC-06 RX to the Arduino TX on pin 11
//
void setup()
{
Serial.begin(9600);
Serial.println("Enter AT commands:");
// HC-06 default serial speed is 9600
BTserial.begin(9600);
}
void loop()
{
// Keep reading from HC-06 and send to Arduino Serial Monitor
while (BTserial.available())
{
//this code runs if connecting via BT on another device
Serial.write(BTserial.read());
}
// Keep reading from Arduino Serial Monitor and send to HC-06
while (Serial.available())
{
//This runs while the communication is coming from the Serial USB
BTserial.write(Serial.read());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment