bluetooth - CourseReps/ECEN489-Fall2015 GitHub Wiki

Bluetooth

Bluetooth is a wireless technology for short distance data transmission. Signal is in form of High Frequency Radio Waves which moves from 2.4 to 2.485 GHz. Connection range is practically 10 meters, but theoretically it should just be within 100 meters. Bluetooth does not have multi-threading function which means it can only pair with one other device. Usually data is transferred from master to slave module but in some cases they can go one way or the other.

HC-06 Slave Module

Power input: +3.3VDC; The maximum serial baud rate: 1382400 bps

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(11,10);

void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
}

void loop() {
  if(BTSerial.available())
    Serial.write(BTSerial.read());
  if(Serial.available())
    BTSerial.write(Serial.read());
}

RN-42-SM Master/Slave Module

Still Light: Connecting with other device
Slow blink: On hold to receive signal
Fast blink: Action Mode

#include <SoftwareSerial.h>
int RX=13;
int TX=12;

SoftwareSerial Bluetooth(TX,RX);
void setup() {
  Serial.begin(9600);
  Bluetooth.begin(9600);
  Bluetooth.print("$");
  Bluetooth.print("$");
  Bluetooth.print("$");
  delay(100);
}

String result = "";

void loop()
{
  if(Bluetooth.available())  // If the bluetooth sent any characters
  {
    Serial.print((char)Bluetooth.read());
  }
  if(Serial.available())  // If stuff was typed in the serial monitor
  {
    Bluetooth.print((char)Serial.read());
  }
}