Arduino Bluetooth HC-05
I will summarize and share my experience with the Use of HC-05 Bluetooth module with the arduino. I bought it for Rs 840 Rs from ebay. It had 4 pins >>> VCC, GND, RXD, TXD;. Some modue comes with 6 Pins. For our application we dont need those.
First, I connected the bluetooth module with he arduino as per details below.
Arduino ----------- Bluetooth HC-05
5 V ----------- VCC
Gnd -------------- Gnd
Pin 10 as Rx --------- Txd
Pin 11as Tx --------- Rxd
I used digital Pins 10 and 11 as transreceiver pin with the help of softwareSerial.h library. It worked perfectly and connected my tablet using the arduino bluetooth application Arduino Bluetooth Terminal from google play by POWER7 NET.
I uploaded the below Arduino code as indicated by POWER7 NET ::
--------------------------------------------------------------------------------------
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
void setup() {
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()){
BluetoothData=Genotronex.read();
if(BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(ledpin,0);
Genotronex.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data ...
}
-------------------------------------------------------------------------------
It worked perfectly.
I thought to expand further and read other arcticles. Other articles on this subject showed scematics using as shift rigister. So by various readings I came to know that this HC-05 module with breakout is actually made for 3.3 volt and long operation with 5 V may fry it soon.
So I changed the connection as below::
Arduino ----------- Bluetooth HC-05
3.3 V ----------- VCC
Gnd -------------- Gnd
Pin 10 as Rx --------- Txd
Pin 11as Tx --------- Rxd (though potential divider using 2.2K and 1 K resistance so resulting v=3.3 V) one cane use POT also.
-----------------------------------------------------------------------------------------------------------
The code above can handle only one pin e.g. Digital pin 13. To use other Digital pins. I modified the program as below..
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
//Code modified by Rajeev Kumar
int pin=13 //default value
int status=0 //used for pin HIGH or LOW
void setup() {
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(13,OUTPUT);
pinMode(12,OUTPUT); //cannot use pin 11 and 10 as these used for serial and connected to BT moudule.
pinMode(9,OUTPUT);// on can add more.
Genotronex.println(" enter a for pin 13 and 1 or 0 for high and low" )
}
void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()>=2) //take two no serial input once and then go ahead. First i stuck here and and read a lot documentation.
{
pin = Genotronex.read();
status = Genotronex.read();
digitalWrite(pin-84,staus-48); // serial take char single charachter as input so calculation done to change to decimal value
Genotronex.println("LED On D13 ON ! ");
}
}
delay(100);// prepare for next data ...
}
---------------------------------------------------------------------------------------------
So see above code. for pin 13 tya a (lower case) and 0 or 1 for high low at the serial input from your tablet.
you can type a1 (for pin 13 high) and a0 (for pin 13 low). The serial port read one by one and take two inputs to serial.read() function.
First, I connected the bluetooth module with he arduino as per details below.
Arduino ----------- Bluetooth HC-05
5 V ----------- VCC
Gnd -------------- Gnd
Pin 10 as Rx --------- Txd
Pin 11as Tx --------- Rxd
I used digital Pins 10 and 11 as transreceiver pin with the help of softwareSerial.h library. It worked perfectly and connected my tablet using the arduino bluetooth application Arduino Bluetooth Terminal from google play by POWER7 NET.
I uploaded the below Arduino code as indicated by POWER7 NET ::
--------------------------------------------------------------------------------------
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
void setup() {
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()){
BluetoothData=Genotronex.read();
if(BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(ledpin,0);
Genotronex.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data ...
}
-------------------------------------------------------------------------------
It worked perfectly.
I thought to expand further and read other arcticles. Other articles on this subject showed scematics using as shift rigister. So by various readings I came to know that this HC-05 module with breakout is actually made for 3.3 volt and long operation with 5 V may fry it soon.
So I changed the connection as below::
Arduino ----------- Bluetooth HC-05
3.3 V ----------- VCC
Gnd -------------- Gnd
Pin 10 as Rx --------- Txd
Pin 11as Tx --------- Rxd (though potential divider using 2.2K and 1 K resistance so resulting v=3.3 V) one cane use POT also.
-----------------------------------------------------------------------------------------------------------
The code above can handle only one pin e.g. Digital pin 13. To use other Digital pins. I modified the program as below..
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
//Code modified by Rajeev Kumar
int pin=13 //default value
int status=0 //used for pin HIGH or LOW
void setup() {
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(13,OUTPUT);
pinMode(12,OUTPUT); //cannot use pin 11 and 10 as these used for serial and connected to BT moudule.
pinMode(9,OUTPUT);// on can add more.
Genotronex.println(" enter a for pin 13 and 1 or 0 for high and low" )
}
void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()>=2) //take two no serial input once and then go ahead. First i stuck here and and read a lot documentation.
{
pin = Genotronex.read();
status = Genotronex.read();
digitalWrite(pin-84,staus-48); // serial take char single charachter as input so calculation done to change to decimal value
Genotronex.println("LED On D13 ON ! ");
}
}
delay(100);// prepare for next data ...
}
---------------------------------------------------------------------------------------------
So see above code. for pin 13 tya a (lower case) and 0 or 1 for high low at the serial input from your tablet.
you can type a1 (for pin 13 high) and a0 (for pin 13 low). The serial port read one by one and take two inputs to serial.read() function.
Comments
Post a Comment