Skip to content

Instantly share code, notes, and snippets.

@bauerjj bauerjj/bluetooth-hc06.ino

Last active Apr 22, 2016
What would you like to do?
Arduino hc-06 example
* Simple routine that performs the following:
* 1. Blink the on-board status LED every 500ms
* 2. Configures the software UART on pins 2 and 4 (RX,TX)
* 3. Continuously sends the string "hello" to the bluetooth module every 500ms
* 4. If it receives a character from bluetooth, it echos it back
* @author
#include <SoftwareSerial.h> // use the software uart
SoftwareSerial bluetooth(2, 4); // RX, TX
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 500; // interval at which to blink (milliseconds)
int ledState = LOW; // ledState used to set the LED
void setup() {
pinMode(13, OUTPUT); // for LED status
bluetooth.begin(9600); // start the bluetooth uart at 9600 which is its default
delay(200); // wait for voltage stabilize
bluetooth.print(""); // place your name in here to configure the bluetooth name.
// will require reboot for settings to take affect.
delay(3000); // wait for settings to take affect.
void loop() {
if (bluetooth.available()) { // check if anything in UART buffer
bluetooth.write(; // if so, echo it back!
// Blink LED routine from
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
bluetooth.println("Arduino bluetooth"); // continously send this
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(13, ledState);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.