Day 8- Bluetooth Interface HC05

 Day 8-  Bluetooth HC05 & Make Bluetooth APP

Task

1) Bluetooth HC 05 introduction

2) Bluetooth car

3) How to Make Android App using Mit app Inventor

4) 4 ch Bluetooth Home Automation


HC-05 Bluetooth Module



HC-05 is a Bluetooth device used for wireless communication with Bluetooth enabled devices (like smartphone). It communicates with microcontrollers using serial communication (USART).

Default settings of HC-05 Bluetooth module can be changed using certain AT commands.

As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, there is no need to shift TX voltage level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module.

For more information about HC-05 Bluetooth module and how to use it, refer the topic HC-05 Bluetooth module in the sensors and modules section.




Send Message using Bluetooth HC-05 With Arduino



Here, we will transmit data from Smartphone via Bluetooth to the Arduino Uno and display it on Serial Monitor of PC.

Download and install a Bluetooth terminal application on your phone and use it to connect to the HC-05 Bluetooth module.

Data is sent from the Smartphone using the Bluetooth terminal application.

-----------------------------------------------------------------------------------------------------------

#include<SoftwareSerial.h>

/* Create object named bt of the class SoftwareSerial */
SoftwareSerial bt(2,3); /* (Rx,Tx) */

void setup() {
  bt.begin(9600); /* Define baud rate for software serial communication */
  Serial.begin(9600); /* Define baud rate for serial communication */
  Serial.println(" Ready for bt communication");
 
}

void loop() {
 
    if (bt.available()) /* If data is available on serial port */
    {
     Serial.write(bt.read()); /* Print character received on to the serial monitor */
     Serial.println("");
    }
}
--------------------------------------------------------------------------

How to make Bluetooth app







--------------------------------------------------------------------------------

How To Make Bluetooth CAR




//Arduino Bluetooth Controlled Car//
// Before uploading the code you have to install the necessary library//
//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install //

#include <AFMotor.h>

//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

char command;
int frontlights=14;
int backlights=15;
int horn=16;
int extra=17;

int speedx=255;

void setup()
{  

    pinMode(frontlights,OUTPUT);
    pinMode(backlights,OUTPUT);
    pinMode(horn,OUTPUT);
    pinMode(extra,OUTPUT);

   digitalWrite(frontlights,LOW);
    digitalWrite(backlights,LOW);
    digitalWrite(horn,LOW);
    digitalWrite(extra,LOW);
   
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.
  Serial.print("Bluetooth Car Ready");
}

void loop(){
  if(Serial.available() > 0){
    command = Serial.read();
    Stop(); //initialize with motors stoped
    //Change pin mode only if new command is different from previous.  
    Serial.println(command);
    switch(command){
    case 'F':  forward(); break;
    case 'B':  back();  break;
    case 'L':  left();  break;
    case 'R':  right(); break;

    case 'G':  fleft(); break;
    case 'I':  fright(); break;
    case 'H':  bleft(); break;
    case 'J':  bright(); break;
   
    case 'W':
      digitalWrite(frontlights,HIGH);
      break;
    case 'w':
      digitalWrite(frontlights,LOW);
      break;

      case 'U':
      digitalWrite(backlights,HIGH);
      break;
      case 'u':
      digitalWrite(backlights,LOW);
      break;

      case 'V':
      digitalWrite(horn,HIGH);
      break;
      case 'v':
      digitalWrite(horn,LOW);
      break;

      case 'X':
      digitalWrite(extra,HIGH);
      break;
      case 'x':
      digitalWrite(extra,LOW);
      break;

      case '1':   Serial.print("speed= 150");speedx=150;  break;
      case '2':   Serial.print("speed= 160");speedx=160;  break;    
      case '3':   Serial.print("speed= 170");speedx=170;  break;
      case '4':   Serial.print("speed= 180");speedx=180;  break;
      case '5':   Serial.print("speed= 190");speedx=190;  break;
      case '6':   Serial.print("speed= 200");speedx=200;  break;
      case '7':   Serial.print("speed= 225");speedx=225;  break;
      case '8':   Serial.print("speed= 235");speedx=235;  break;
      case '9':   Serial.print("speed= 245");speedx=245;  break;
      case 'q': Serial.print("speed= 255");speedx=255;  break;
    }
  }
}

void forward()
{
  motor1.setSpeed(speedx); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(speedx); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(speedx);//Define maximum velocity
  motor3.run(FORWARD); //rotate the motor clockwise
  motor4.setSpeed(speedx);//Define maximum velocity
  motor4.run(FORWARD); //rotate the motor clockwise
}

void fright()
{
  motor1.setSpeed(speedx-(speedx/2)); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(speedx-(speedx/2)); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(speedx);//Define maximum velocity
  motor3.run(FORWARD); //rotate the motor clockwise
  motor4.setSpeed(speedx);//Define maximum velocity
  motor4.run(FORWARD); //rotate the motor clockwise
}

void fleft()
{
  motor1.setSpeed(speedx); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(speedx); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(speedx-(speedx/2));//Define maximum velocity
  motor3.run(FORWARD); //rotate the motor clockwise
  motor4.setSpeed(speedx-(speedx/2));//Define maximum velocity
  motor4.run(FORWARD); //rotate the motor clockwise
}

void back()
{
  motor1.setSpeed(speedx); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(speedx); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(speedx); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(speedx); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void bright()
{
  motor1.setSpeed(speedx-(speedx/2)); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(speedx-(speedx/2)); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(speedx); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(speedx); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void bleft()
{
  motor1.setSpeed(speedx); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(speedx); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(speedx-(speedx/2)); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(speedx-(speedx/2)); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void right()
{
  motor1.setSpeed(speedx); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(speedx); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(speedx); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
  motor4.setSpeed(speedx); //Define maximum velocity
  motor4.run(FORWARD);  //rotate the motor clockwise
}

void left()
{
  motor1.setSpeed(speedx); //Define maximum velocity
  motor1.run(FORWARD); //rotate the motor clockwise
  motor2.setSpeed(speedx); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(speedx); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(speedx); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void Stop()
{
  motor1.setSpeed(0); //Define minimum velocity
  motor1.run(RELEASE); //stop the motor when release the button
  motor2.setSpeed(0); //Define minimum velocity
  motor2.run(RELEASE); //rotate the motor clockwise
  motor3.setSpeed(0); //Define minimum velocity
  motor3.run(RELEASE); //stop the motor when release the button
  motor4.setSpeed(0); //Define minimum velocity
  motor4.run(RELEASE); //stop the motor when release the button
}
------------------------------------------------------------------------------

Bluetooth App for Home Automation

Download aia file


Download Apk file


#include <Wire.h>

char Received;

const int LED1=4;
const int LED2=5;
const int LED3=6;
const int LED4=7;

void setup() {
  Serial.begin(9600); /* Define baud rate for software serial communication */

  pinMode(LED1,OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(LED3,OUTPUT);
  pinMode(LED4,OUTPUT);

  digitalWrite(LED1,0);
  digitalWrite(LED2,0);
  digitalWrite(LED3,0);
  digitalWrite(LED4,0);

  Serial.begin(9600); /* Define baud rate for serial communication */
  Serial.println(" Ready for bt communication");
 
}

void loop() {
 
    if(Serial.available()>0)
 {
    Received = Serial.read();
    Serial.println(Received);
 }
if (Received =='a'){Serial.println("Relay 2 OFF"); digitalWrite(LED1,HIGH); Received ='o'; delay(250);}
if (Received =='A'){Serial.println("Relay 2 ON");  digitalWrite(LED1, LOW); Received ='o'; delay(250);}

if (Received =='b'){Serial.println("Relay 3 OFF"); digitalWrite(LED2,HIGH); Received ='o'; delay(250);}
if (Received =='B'){Serial.println("Relay 3 ON");  digitalWrite(LED2, LOW); Received ='o'; delay(250);}

if (Received =='c'){Serial.println("Relay 4 OFF"); digitalWrite(LED3, HIGH); Received ='o'; delay(250);}
if (Received =='C'){Serial.println("Relay 4 ON");  digitalWrite(LED3, LOW); Received ='o'; delay(250);}

if (Received =='d'){Serial.println("Relay 5 OFF"); digitalWrite(LED4,HIGH); Received ='o'; delay(250);}
if (Received =='D'){Serial.println("Relay 5 ON");  digitalWrite(LED4, LOW); Received ='o'; delay(250);}

if (Received =='z'){
 Serial.println("Relay 2 OFF"); digitalWrite(LED1, HIGH); delay(100);
 Serial.println("Relay 3 OFF"); digitalWrite(LED2, HIGH); delay(100);
 Serial.println("Relay 4 OFF"); digitalWrite(LED3, HIGH); delay(100);
 Serial.println("Relay 5 OFF"); digitalWrite(LED4, HIGH); delay(100); Received ='o';}

if (Received =='Z'){
 Serial.println("Relay 2 ON"); digitalWrite(LED1, LOW); delay(100);
 Serial.println("Relay 3 ON"); digitalWrite(LED2, LOW); delay(100);
 Serial.println("Relay 4 ON"); digitalWrite(LED3, LOW); delay(100);
 Serial.println("Relay 5 ON"); digitalWrite(LED4, LOW); delay(100); Received ='o';}

 delay(10);

    }

-------------------------------------------------------


No comments:

Post a Comment

Arduion Uno pin out