Introduction: Bluetooth (Hc-05) With Arduino
Here's an Easy way to get along with the Bluetooth connected Arduino controlled by the Android device /Any mobile device /Internal serial monitor
Step 1: Connecting the Module (HC-05)
First make sure that your Arduino uno Board is working.
After checking the Board , now it's time to connect the Bluetooth module to the Arduino uno board
Step 2: Connection Configuration
You will find the 6 pins in the Bluetooth module
But it's enough to connect the 4 pins to work with the module ( leaving EN pin and STATE pin)
Connect the RX pin of module to TX (pin 1) from Arduino board
Connect the TX pin of module to RX (pin 0) from Arduino board
Connect the VCC pin of module to 3.3v pin in Arduino board
Connect the GND pin of module to GND pin in Arduino board
Step 3: C Program With Serial Window
The program in the image is to make yourself comfortable with working the Arduino board using the module to activate the led via entering 'a' and to deactivate via entering 'b' in the serial monitor/terminal software in android mobile
Basic Logic in the program
After uploading the program to the board with the respective connection
Open the serial window and enter 'a' to turn on the Pin 13 Led and enter 'b' to turn off the Led
Can be done in serial monitor or s2 terminal software
Step 4: Work With Terminal
To work via Serial monitor :
click the serial monitor an change the baud rate to 9600 and then start working with the monitor
To work via Terminal wireless using Android mobile :
Download the terminal software called S2 terminal for Bluetooth and do the following steps as in the image above
Connect the Bluetooth module with the mobile and then the module will have a light delay of 2 seconds to indicate that the module and the mobile has been connected /paired
Now you can enter the letters and check the working
You can modify it according to your wish ..…
7 Comments
Tip 4 years ago on Step 3
heres the code:
// scriptname for serial output
const char* host = "arduino_HC05-app";
int tx = 0;
int rx = 1;
char junk;
String inputstring = "";
void setup() {
Serial.begin(9600);
Serial.println("");
Serial.println(host);
pinMode (13, OUTPUT);
pinMode (tx, OUTPUT);
pinMode (rx, INPUT);
}
void loop() {
if (Serial.available()) {
while (Serial.available()) {
char inchar = (char)Serial.read();
inputstring += inchar;
}
Serial.println(inputstring);
while (Serial.available() >0){
junk = Serial.read();
}
if (inputstring == "A") {
digitalWrite (13, HIGH);
}
else if (inputstring == "B") {
digitalWrite (13, LOW);
}
inputstring = "";
}
}
4 years ago
worked for me (bluetooth at least, serial monitor not) great thanks!
also be helpful if you could upload the code please. I've added it as a tip under step 3
7 years ago
did your code work for you?
7 years ago
Hello to everyone.I have make a bleutooth robot which i can control it via android(tablet) and i have a problem with the code.I want from the robot to stop when connection lost or bluetooth disconnected.Now when the connection lost the robot go ahead and falls on the objects.How to add this line on the code?Can you help me please?The STATE pin of HC-05 when is HIGH is connected and when is LOW is disconnected.I put this on my code but it doesn't stop.Thank you for your time
The bluetooth that i use is HC-05
My code:
#include <Servo.h>
Servo SERVO_1; // Initialize Servo1
// Motor Control Variables
int PWM1 = 9;
int ENABLE1 = 8;
int PWM2 = 5;
int ENABLE2 = 7;
int PWM3 = 3;
int ENABLE3 = 4;
int PWM4 = 6;
int ENABLE4 = 12;
int STATE=2;
void setup() {
SERVO_1.attach(10);
Serial.begin(9600);
pinMode(ENABLE1, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE2, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE3, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(ENABLE4, OUTPUT); //Δήλωση όλων των μεταβλητών ως έξοδος
pinMode(STATE, INPUT);
}
void loop() {
if(digitalRead(STATE)== HIGH)
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
int incomingByte = Serial.read();
// action depending on the instruction
// as well as sending a confirmation back to the app
switch (incomingByte) {
case 'F':
moveForward();
Serial.println("Going forward");
break;
case 'L' : // Case 'L' is received,
SERVO_1.write (180); // Στρίψε Αριστερά.
SERVO_1.attach(10);
break;
case 'N':
turnright();
Serial.println("Turning right");
break;
case 'M':
turnleft();
Serial.println("Turning left");
break;
case 'O' : // Case 'L' is received,
SERVO_1.write (0); // Στρίψε Αριστερά.
SERVO_1.attach(10);
break;
case 'B':
moveBackward();
Serial.println("Going forward");
break;
case 'P':
SERVO_1.write(90); // Στρίψε Αριστερά.
SERVO_1.attach(10);
break;
case 'S':
moveNone();
Serial.println("Stopping");
break;
default:
// if nothing matches, do nothing
break;
}
}
}
void moveForward() {
// turn the driving motor on to go forwards at set speed
digitalWrite(ENABLE1, HIGH);
digitalWrite(ENABLE2, HIGH);
digitalWrite(ENABLE3, HIGH);
digitalWrite(ENABLE4, HIGH);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
}
void moveBackward() {
// turn the driving motor on to go backwards at set speed
digitalWrite(ENABLE1, LOW);
digitalWrite(ENABLE2, LOW);
digitalWrite(ENABLE3, LOW);
digitalWrite(ENABLE4, LOW);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
}
void turnright() {
digitalWrite(ENABLE1, HIGH);
digitalWrite(ENABLE2, HIGH);
digitalWrite(ENABLE3, LOW);
digitalWrite(ENABLE4, LOW);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
}
void turnleft() {
digitalWrite(ENABLE1, LOW);
digitalWrite(ENABLE2, LOW);
digitalWrite(ENABLE3, HIGH);
digitalWrite(ENABLE4, HIGH);
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
analogWrite(PWM3, 255);
analogWrite(PWM4, 255);
}
void moveNone() {
// turn the driving motor off
digitalWrite(ENABLE1, 0);
digitalWrite(ENABLE2, 0);
digitalWrite(ENABLE3, 0);
digitalWrite(ENABLE4, 0);
analogWrite(PWM1, 0);
analogWrite(PWM2, 0);
analogWrite(PWM3, 0);
analogWrite(PWM4, 0);
SERVO_1.detach();
}
7 years ago
Tanq for ur compliment bro....
Reply 7 years ago
NICE ONE TY
7 years ago
Great tutorial