Thanks to Joe at V7media and to Zack at Unaffiliated Productions for the Great shots.






// Basic Bluetooth test sketch 5a for the Arduino Mega.
// AT mode using button switch
// HC-05 with EN pin and button switch
//
// Uses serial with the host computer and serial1 for communication with the Bluetooth module
//
// Pins
// BT VCC to Arduino 5V out. Disconnect before running the sketch
// BT GND to Arduino GND
// BT RX (through a voltage divider) to Arduino TX1 (pin 18)
// BT TX to Arduino RX1 (no need voltage divider) (pin 19)
//
// When a command is entered in to the serial monitor on the computer
// the Arduino will relay it to the Bluetooth module and display the result.
//
char serialByte = '0';
const byte LEDPIN = 13;
void setup()
{
pinMode(LEDPIN, OUTPUT);
// communication with the host computer
Serial.begin(9600);
Serial.println("Do not power the BT module");
Serial.println(" ");
Serial.println("On the BT module, press the button switch (keep pressed, and at the same time power the BT module");
Serial.println("The LED on the BT module should now flash on/off every 2 seconds");
Serial.println("Can now release the button switch on the BT module");
Serial.println(" ");
Serial.println("After entering AT mode, type 1 and hit send");
Serial.println(" ");
// wait for the user to type "1" in the serial monitor
while (serialByte !='1')
{
if ( Serial1.available() ) { serialByte = Serial1.read(); }
}
// communication with the BT module on serial1
Serial1.begin(38400);
// LED to show we have started the serial channels
digitalWrite(LEDPIN, HIGH);
Serial.println(" ");
Serial.println("AT mode.");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("The HC-05 accepts commands in both upper case and lower case");
Serial.println(" ");
}
void loop()
{
// listen for communication from the BT module and then write it to the serial monitor
if ( Serial1.available() ) { Serial.write( Serial1.read() ); }
// listen for user input and send it to the HC-05
if ( Serial.available() ) { Serial1.write( Serial.read() ); }
}
// Basic Bluetooth test sketch 5a for the Arduino Mega.
// AT mode using button switch
// HC-05 with EN pin and button switch
//
// Uses serial with the host computer and serial1 for communication with the Bluetooth module
//
// Pins
// BT VCC to Arduino 5V out. Disconnect before running the sketch
// BT GND to Arduino GND
// BT RX (through a voltage divider) to Arduino TX1 (pin 18)
// BT TX to Arduino RX1 (no need voltage divider) (pin 19)
//
// When a command is entered in to the serial monitor on the computer
// the Arduino will relay it to the Bluetooth module and display the result.
//
char serialByte = '1';
const byte LEDPIN = 13;
void setup()
{
pinMode(LEDPIN, OUTPUT);
// communication with the host computer
Serial.begin(9600);
Serial.println("Do not power the BT module");
Serial.println(" ");
Serial.println("On the BT module, press the button switch (keep pressed, and at the same time power the BT module");
Serial.println("The LED on the BT module should now flash on/off every 2 seconds");
Serial.println("Can now release the button switch on the BT module");
Serial.println(" ");
Serial.println("After entering AT mode, type 1 and hit send");
Serial.println(" ");
// wait for the user to type "1" in the serial monitor
while (serialByte !='1')
{
if ( Serial1.available() ) { serialByte = Serial1.read(); }
}
// communication with the BT module on serial1
Serial1.begin(38400);
// LED to show we have started the serial channels
digitalWrite(LEDPIN, HIGH);
Serial.println(" ");
Serial.println("AT mode.");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("The HC-05 accepts commands in both upper case and lower case");
Serial.println(" ");
}
void loop()
{
// listen for communication from the BT module and then write it to the serial monitor
if ( Serial1.available() ) { Serial.write( Serial1.read() ); }
// listen for user input and send it to the HC-05
if ( Serial.available() ) { Serial1.write( Serial.read() ); }
}
Command Comment
AT Serial communications test.
Returns “OK”.
AT+VERSION? Get the firmware ID/version number.
Returns “+VERSION:2.0-20100601″.
AT+ORGL Resets the module to the factory default settings.
Returns “OK”.
AT+RESET Restarts the module. Some times required for changes to take place.
AT+NAME? Get the device name. Requires pin 34 to be HIGH. If the pin is not HIGH the HC-05 will not reply.
Returns the device name such as “+NAME:H-C-2010-06-01″.
AT+NAME=newName Change the modules name to newName.
Returns an “OK” if successful.
AT+ADDR? Query the module mac address. Returns a hex value in the form “+ADDR:1234:12:123456″.
AT+UART? Query the baud rate used for UART serial communication. This is the speed a host device like an Arduino uses to talk to the BT module. It is not the the speed used to send wireless signals between different modules.
Returns the baud rate, stop bit, parity bit in the form “+UART:38400,0,0″
AT+UART=baudRate,stop,parity Set the baud rate used for serial UART commincation.
baudRate is one of the following decimal values:
4800
9600
19200
38400
57600
115200
230400
460800
1382400
stop is the stop bit. Either 0 or 1
parity is the parity but. Either 0, 1, or 2.
0 = none.
1 = odd.
2 = even.
i.e. “AT+UART=38400,0,0″
AT+STATE? Query the current device state.
Replies with one of the following:
INITIALIZED
READY
PAIRABLE
PAIRED
INQUIRING
CONNECTING
CONNECTED
DISCONNECTED
UNKNOWN
AT+ROLE? Query the current role. Returns 0,1, or 2.
0 = slave mode
1 = master mode
2 = slave echo mode.
AT+ROLE=x Set the module mode.
Where x = 0,1, or 2.
AT+ROLE=0 puts the HC-05 in to slave mode.
AT+ROLE=1 puts it in to master mode.
AT+ROLE=2 puts it in to slave echo mode.
Returns “OK” if successful.
In Slave echo mode, the module echos back the data it receives.
AT+CMODE? Query the current connection mode. Returns the connection mode value (0,1,2) in the form “+CMOD:0″.
0 = Manual connection.
1 = Auto connection on start.
2 = Slave loop mode.
AT+CMODE=x Set the connection mode.
Where x can be 0,1, or 2. For CMODE to work, the module has to be in master mode (“AT+ROLE=1″).
0 = Manual connection: The remote device address must be specified to make a connection.
1 = Auto connect: Connect to any module/last connected module on start.
2 = Slave loop mode.
AT+PSWD? Query the current PIN.
Returns a 4 digit decimal number.
AT+PSWD=xxxx Set the PIN code used for pairing
xxxx = a 4 digit decimal number.
AT+PAIR=address,timeout Attempt to PAIR with a remote Bluetooth device.
The address must be in the form 1234,56,abcedef (notice the commas).
timeout is a decimal value that sets the length of time to try.
“AT+PAIR=98d3,32,70facf, 9″ attempts to PAIR with a slave module with the address 98d3:32:70facf for 9 seconds. If pairing is not successful within 9 seconds a”FAIL” error message is given.
The SPP has to be initialized before using the AT+PAIR command.
AT+INIT Initialize the Serial Port Profile (SPP)
This is required by some of the other commands.
“AT+INIT” requires pin34 to be HIGH. If the HC-05 is in AT command mode but pin34 is not HIGH the module will not reply.
If AT+INIT is used and SPP has already been initialized the “ERROR(17)” error message is given.
If a command requires SPP and it has not been initialized a “ERROR(16)” error message is given.
// testing a stepper motor with a NO2C and DRV8825 driver board or equivalent
// Stepper should Step out (extend) and Step In (retract)
// this version uses delay() to manage timing
byte directionPin = 25;
byte stepPin = 24;
int numberOfSteps = 250;
byte Enablepin = 27;
int pulseWidthMicros = 200; // microseconds
int millisbetweenSteps = 20; // milliseconds - or try 1000 for slower steps
void setup() {
Serial.begin(9600);