Saturday, 21 December 2013

Resetting the Bluetooth module with AT commands

BT modules ceom with strange names and PIN codes. To pair with a Mac give your BT module a sensible name and the PIN 0000.

Like this

BT module configuration

Do not pair before this sketch, in order to send AT commands BT red LED must be flashing.

Set name to whatever_you_want, PIN to 0000, baud rate to 9600 using AT commands below:

/* BT module configure
BT flashing
send AT+NAMEWhatever_you_want
send AT+PIN0000
send AT+BAUD4
connections
Arduino       BT
5V            PIN 2 (VCC)
GND           PIN 3 (GND)
10            PIN 4 (TXD)
11            PIN 5 (RXD)
*/

#include "SoftwareSerial.h"

#define RXPIN 10 
#define TXPIN 11

SoftwareSerial BT(RXPIN, TXPIN); // create class BT

void setup()  
{
  Serial.begin(9600); // start USB
  BT.begin(9600); // start BT
}

void loop()
{
  if (BT.available())
  {
    Serial.write(BT.read()); // echo from BT
  }
 
  if (Serial.available())
  {
    BT.write(Serial.read()); // write AT command to BT
  }
}

No comments: