Project showcase
Proyecto: Arduino + Processing + Bluetooth HC-05

Proyecto: Arduino + Processing + Bluetooth HC-05

Bluetooth communication between Arduino and the PC using a small interface programmed in Processing.

  • 10,557 views
  • 0 comments
  • 5 respects

Components and supplies

About this project

In this project a bi-directional communication is made between our arduino card and our computer using the Bluetooth module HC-05, the interface in the computer was made in Processing. in which we select the position where we want the servo to turn and the sensor that is positioned on the servo will send us information about the recorded data, will detect objects between 20 and 30 cm, which will send us an alert that will turn on our Arduino LED like the one in the interface.

After having the elements we must first:

Configure Bluetooth Module HC-05.

Characterize Sensor SHARP 2Y0A21.

After having our SHARP sensor IR 2Y0A21 characterized and our Bluetooth module HC-05 configured as a slave through the AT commands, we prepare our circuit:

Thanks!!

Code

Arduino CodeArduino
#include <Servo.h>;
//#include <SoftwareSerial.h>;
float dataout;
String datain;
String id;
int dataID;
float data;
int SIR,dist,prom;

//SoftwareSerial BTserial(10,9);

Servo servo1;

void setup() {
//  BTserial.begin(9600);
  Serial.begin(9600);
  delay(1000);
  servo1.attach(20);
  pinMode(2,OUTPUT);//RED
  pinMode(3,OUTPUT);//GREEN
  pinMode(4,OUTPUT);//BLUE
servo1.write(90);
digitalWrite(3,HIGH);
delay(1000);
digitalWrite(3,LOW);
    digitalWrite(4,HIGH);
    delay(50);
    digitalWrite(4,LOW);
    dataout=servo1.read();
    Serial.print("S");
    Serial.println(dataout);
}

void loop() {
  prom=0;
  for(int i=0;i<=10;i++){
  SIR=analogRead(A0);
  dist=pow(10,log10(SIR/1821.2)/-0.65);delay(100);
  prom+=dist;
  }
  prom=prom/11;
  
  if(prom<30 && prom>20){
    digitalWrite(2,HIGH);
    Serial.print("D");
    Serial.println(prom);
     }else{
    digitalWrite(2,LOW);
    Serial.print("D");
    Serial.println(prom);
    
   }
   

  if(Serial.available()>0)
  {datain=  Serial.readStringUntil('\n');
        
    id=datain.substring(0,1);
    datain=datain.substring(1); 
    data=datain.toFloat();
      
  if(id=="S"){
    servo1.write(data);
    digitalWrite(4,HIGH);
    delay(50);
    digitalWrite(4,LOW);
    dataout=servo1.read();
    Serial.print("S");
    Serial.println(dataout);
  }
  }
  }
Processing CodeProcessing
 import processing.serial.*;
 
 Serial btserial;
 
 PShape l , r, flecha;
 float varin;
 boolean over;
 boolean click;
 float pos0=2, pos1=2, pos2=2, pos3=2, pos4=2, pos5=2, pos6=2, pos7=2, pos8=2;
 float datain, senIn, datasen;
 String bufferin,ID="uno", ID2="dos",data,data2;
 
 
void setup(){
  btserial=new Serial(this,Serial.list()[1],9600);
  
  printArray(Serial.list());
  background(20);
  size(600,200,P2D);
  smooth();
 
  

  
}

void draw(){
  
  textAlign(LEFT);
  fill(255);
  text("Arduino + HC05",10,20);
  
 
  textAlign(CENTER);
  text("Led",100,140);
  text("Servo",400,165);
  text("SHARP IR",230,35);
  text("Distancia:",230,80);
  fill(0);
  rectMode(CENTER);
  rect(230,94,58,18);
  fill(255);
if(senIn>80){text("F.D.R",230,100);}else{
  text(int(senIn),230,100);}
  
  image(img1,430,-10,200,60);
  image(img2,0,160);
  image(img3,448,170,150,33);
  
 // LED
  stroke(126);
 fill(200);
 ellipseMode(CENTER);
 if(mouseX>50 && mouseX<150 && mouseY>50 && mouseY<150)
  {fill(255);
      }
 
 if(ID2.equals("D") && senIn>20 && senIn<30){fill(255,0,0);}
 if(ID2.equals("D") && (senIn>=30 || senIn<=20)){fill(200);}
      ellipse(100,100,50,50);
   
   //Sensor SHARP
   rectMode(CENTER);
   fill(126);
   rect(230,50,60,20);
   rect(230,60,25,7);
   fill(150);
   rect(230,50,58,18);
   fill(0);
   ellipse(210,50,15,15);
   fill(255,0,0);
   ellipse(250,50,15,15);
   
   
  //Radar o Movimiento del Servo
  stroke(0);
  strokeWeight(3);
  //fill(56,206,56);
  fill(100);
  arc(400,150,200,200,-PI,0);
  //stroke(100,100,100);
  stroke(40);
  strokeWeight(1);
  line(400,150,400+(100*(cos(radians(22.5)))),150-(100*(radians(22.5))));
  line(400,150,400+(100*(cos(PI/4))),150-(100*(sin(PI/4))));
  line(400,150,400+(100*(cos(3*PI/8))),150-(100*(sin(3*PI/8))));
  line(400,150,400+(100*(cos(PI/2))),150-(100*(sin(PI/2))));
  line(400,150,400+(100*(cos(5*PI/8))),150-(100*(sin(5*PI/8))));
  line(400,150,400+(100*(cos(3*PI/4))),150-(100*(sin(3*PI/4))));
  line(400,150,400+(100*(cos(7*PI/8))),150-(100*(sin(7*PI/8))));
  
   
  
  if(mouseX>488 && mouseX<508 && mouseY>138 && mouseY<158)
  {over=true;if(datain!=pos0){fill(0,255,0);} 
  if(over && mousePressed){click=true;pos0=180.00;} 
  if(click){btserial.write("S"+pos0);}}else{fill(2,165,0);}
     if(ID!=null && ID.equals("S") && datain==180){fill(255,255,255);}    
   ellipse(498,148,20,20); //Elipse en 180
   
 
  if(mouseX>470 && mouseX<500 && mouseY>102 && mouseY<122)
 {over=true;if(datain!=pos1){fill(0,255,0);}
  if(over && mousePressed){click=true;pos1=157.50;} 
  if(click){btserial.write("S"+pos1);}} else{fill(2,165,0);}
      if(ID!=null && ID.equals("S") && datain==157){fill(255,255,255);}
   ellipse(490,112,20,20);//Elipse en 157.5
   

  if(mouseX>459 && mouseX<479 && mouseY>69 && mouseY<89)
  {over=true;if(datain!=pos2){fill(0,255,0);}
  if(over && mousePressed){click=true;pos2=135.000;} 
  if(click){btserial.write("S"+pos2);}}else{fill(2,165,0);}
      if(ID!=null && ID.equals("S") && datain==135){fill(255,255,255);}
    ellipse(469,79,20,20);//Elipse en 135
  
  
  if(mouseX>427 && mouseX<447 && mouseY>47 && mouseY<67)
  {over=true;if(datain!=pos3){fill(0,255,0);}
  if(over && mousePressed){click=true;pos3=112.500;} 
  if(click){btserial.write("S"+pos3);}}else{fill(2,165,0);}
      if(ID!=null && ID.equals("S") && datain==112){fill(255,255,255);}
  ellipse(437,57,20,20);//Elipse en 112.5
  fill(2,165,0); 
    
    if(mouseX>390 && mouseX<410 && mouseY>40 && mouseY<60)
  {over=true;if(datain!=pos4){fill(0,255,0);}
  if(over && mousePressed){click=true;pos4=90.000;} 
  if(click){btserial.write("S"+pos4);}}else{fill(2,165,0);}
      if(ID!=null && ID.equals("S") && datain==90){fill(255,255,255);}
  ellipse(400,50,20,20);// Elipse en 90
  
      if(mouseX>351 && mouseX<371 && mouseY>47 && mouseY<67)
  {over=true;if(datain!=pos5){fill(0,255,0);}
  if(over && mousePressed){click=true;pos5=67.500;} 
  if(click){btserial.write("S"+pos5);}}else{fill(2,165,0);}
      if(ID!=null && ID.equals("S") && datain==67){fill(255,255,255);}
  ellipse(361,57,20,20);// Elipse en 67.5

     if(mouseX>319 && mouseX<339 && mouseY>69 && mouseY<89)
  {over=true;if(datain!=pos6){fill(0,255,0);}
  if(over && mousePressed){click=true;pos6=45;} 
  if(click){btserial.write("S"+pos6);}}else{fill(2,165,0);}
      if(ID!=null && ID.equals("S") && datain==45){fill(255,255,255);}
    ellipse(329,79,20,20); // Elipse en 45

   if(mouseX>300 && mouseX<320 && mouseY>102 && mouseY<122)
  {over=true;if(datain!=pos6){fill(0,255,0);}
  if(over && mousePressed){click=true;pos7=22.5;} 
  if(click){btserial.write("S"+pos7);}}else{fill(2,165,0);}
      if(ID!=null && ID.equals("S") && datain==22.5){fill(255,255,255);}
    ellipse(310,112,20,20);// Elipse en 22.5
   
   
  if(mouseX>291 && mouseX<311 && mouseY>138 && mouseY<158)
  {over=true;if(datain!=pos8){fill(0,255,0);}
  if(over && mousePressed){click=true;pos8=0;} 
  if(click){btserial.write("S"+pos8);}}else{fill(2,165,0);}
      if(ID!=null && ID.equals("S") && datain==0){fill(255,255,255);} 
  ellipse(301,148,20,20);// Elipse en 0
  


if(btserial.available()>0)
 {bufferin=null;
   bufferin=btserial.readStringUntil('\n');
 if(bufferin!=null){
     println("ID= "+ID+" ID2= "+ID2);
  if(bufferin.substring(0,1).equals("S")){ //S180 D29
    ID="S";
  data=bufferin.substring(1);
  float indata=float(data);
  datain=indata;
  btserial.clear();}
  if(bufferin.substring(0,1).equals("D")){
    ID2="D";
  data2=bufferin.substring(1);
  float indata2=float(data2);
  senIn=indata2;
  println(datain);
  btserial.clear();}
 }
   }}  

  
void mouseReleased(){
 over=false;
 click=false;
 
}

Schematics

Squematic
Prarhc beglopwbqd

Comments

Similar projects you might like

Arduino Bluetooth Robot for Android Device

Project showcase by aip06

  • 7,786 views
  • 2 comments
  • 23 respects

Bluetooth Controlled Car

Project in progress by Saman Fernando

  • 438,758 views
  • 222 comments
  • 310 respects

Robotic Car controlledover Bluetooth with Obstacle Avoidance

Project showcase by S.Ranjith Reddy

  • 19,492 views
  • 9 comments
  • 27 respects

Bluetooth Controlled Bot (Using Adafruit L293D Motor Driver)

Project showcase by Chandran N

  • 13,989 views
  • 2 comments
  • 18 respects

Arduino – Bluetooth 12 Channel Relay App

by TayfMavi

  • 6,348 views
  • 3 comments
  • 10 respects
Add projectSign up / Login