Showing posts with label Bluetooth. Show all posts
Showing posts with label Bluetooth. Show all posts

Wednesday, March 9, 2016

Bluetooth HC-05 module

Hi there! I bought a HC-05 bluetotth module and am writing a few lines because it is quite different to manage when compared with the previous HC-06 (which is quite easier). So, let's see:
On HC-06 to enter AT mode you just have to connect to the device before it synchronizes with a BT device. HC-05 needs the KEY or EN or ENABLE or WAKEUP pin to be connected to VCC (3.6 - 6V). An other way to achieve the AT mode is to press the available push-button to 'on' while booting the device, though this will lead to "mini" AT mode instead of "full" AT mode, and in "mini" mode not all AT commands might work.
So, let's see a list of the PINOUT:

KEY/EN: This pin has to be pulled high to enter "full" AT mode;
VCC: Indicated within a range of 3.6 to 6 volt;
GND: Ground;
RXD: Serial input pin;
TXD Serial output pin;
STATE: It's an output pin that can be connected to a LED (with a resistor) which will light up when a BT device is synchronized with the HC-05.

 Then, the console should be configured at 38400 baud (HC-05 default) and change "no line ending " to "both NL & CR".
With the console working type "AT" (without the quotes) on the serial monitor and press enter. if "OK" appears then everything is all right and the module is ready to take command. Now you can change the name of the module, retrieve address or version or even reset to factory settings. To see the default name, type AT+NAME. The name will be prompted, by default it is HC-05. To change the name just type AT+NAME=desired_name.
Important note: if the key pin is not high, (not connected to Vcc while receiving AT commands), it will not show the default name even after giving the correct command. You can still change the name by the command mentioned above. To verify if the name has really changed, search the device using your pc/mobile. The changed name will appear.
To change baud rate, type AT+UART=desired_baud_rate. Exiting AT mode will work by sending AT+RESET command.

Some useful HC-05 AT commands:
AT : Check the connection;
AT+NAME : See default name;
AT+ADDR : See default address;
AT+VERSION : See version;
AT+UART : See baudrate;
AT+ROLE: See role of bt module(1=master/0=slave);
AT+RESET : Reset and exit AT mode;
AT+ORGL : Restore factory settings;
AT+PSWD: See default password;
More detailed AT commands are given in the 1st pdf.

HC-06 AT commands are more limited, though it'll do the job.
AT : Check the connection;
AT+NAME: Change name. No space between name and command;
AT+BAUD: Change baud rate, x is baud rate code, no space between command and code;
AT+PIN: Change pin, xxxx is the pin, again, no space;
AT+VERSION: Shows version;
More detailed AT commands are given in the 2nd pdf.

Wednesday, December 23, 2015

The bluetooth disruption

Well... As I needed some lighting at "Lantern Garden" I bought two 12 V/10W LED projectors and assembled them in the rural field, though I had a problem, where do I put the light switch? And what about rain? It will be ruined very soon... And humidity in the area is quite heavy, so I decided another way, but it needed planing and more hard-work!
At left you can see the light pole and water-resistant distribution box with the projectors assembled (they already have some corrosion because of humidity...).
My decision was to use a bluetooth device I bought for quite sometime now, and to increase the area covered by the signal I put a small waterproof box about 20 meters from the main box, as I need to light up outside the area and not inside it, otherwise I would enter the field without light.
The picture on the right has the bluetooth device already connected and about to be closed inside his "home". For getting it to work I assembled an arduino (wich gave me a huge headache with the resonators I bought, they simply didn't work!) which interprets the bluetooth signals and transfers it to digital/analog pins, at the moment it only lights the projectors, but.. the sky is the limit!
To drive the 12V/10W LEDs I used a TIP120, and it works fine as you can see on the picture on the right and the bluetooth signal gets quite far, I'd say.




Friday, January 9, 2015

HC-06 Bluetooth module with arduino.

Hi there! This is a short document/code to remind me what I have done with a HC-06 Bluetooth module and an arduino as it's not easy to collect the information I got here, it took me sometime.
Firstly, the module can be AT controlled and set some of the parameters as long as it's not paired with a device, so, we must first set the parameters and only afterwards play with devices. The password/pin of the device and name are not lost upon power off.
The AT available commands are:
- AT -> OK (shows status) 
- AT+VERSION -> OKlinvorV1.8 (shows firmware version)
- AT+NAMEARDUINO -> OKsetname (sets broadcast name to 'ARDUINO', kept after powerdown)
- AT+PIN1303 -> OKsetPIN (sets PIN to '1303', kept after powerdown)
- AT+BAUD4 -> OK9600 (sets the baudrate @9600,
   1---------1200
   2---------2400
   3---------4800
   4---------9600
   5---------19200
   6---------38400
   7---------57600
   8---------115200 ) 

Now, knowing this, let's PLAY!! ;)

// HC-06 Possible commands, HC-05 are different!
// ATTENTION!!! THESE COMMANDS WORK ONLY IF THE BLUETOOH IS
// NOT PAIRED WITH ANY DEVICE:
// «AT Mode: Before paired, it is at AT mode.
// After paired it’s at transparent communication.»
// (case sensitive commands)
// AT -> OK (shows status)
// AT+VERSION -> OKlinvorV1.8 (shows firmware version)
// AT+NAMEARDUINO -> OKsetname (sets broadcast name to
//   'ARDUINO', kept after powerdown)
// AT+PIN1303 -> OKsetPIN (sets PIN to '1303', kept
//   after powerdown)
// AT+BAUD4 -> OK9600 (sets the baudrate @9600,
//   1---------1200
//   2---------2400
//   3---------4800
//   4---------9600
//   5---------19200
//   6---------38400
//   7---------57600
//   8---------115200 )

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX, TX

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  BTSerial.begin(9600);
  Serial.println("Enter your AT command:");
}

void loop() // run over and over
{
  if (BTSerial.available())
    Serial.write(BTSerial.read());
  if (Serial.available())
    BTSerial.write(Serial.read());
}