Using Arduino and Bluetooth control a two-drive car

Bee

We just modified a two-driver car control by Arduino and Bluetooth module.  The control side used Freaduino 328 and two Joystick module and Bluetooth Shield to  send data.  The other  side used Arduino Pro and Bluetooth Bee to receive data and control the car. This modification just our step one. We will keep working for using Android phone to replace of Joystck  and Bluetooth Shield side and adding acceleration due to gravity futher.

Take a look at the demo video:

We will show you how to modiefied a two-driver car step by step, just follow me.

一:Preparation 

Control Side

Control side

Control side

 Arduino Control Side 

 

Car side

Car side

Car side

Two-Driver Car Side

二. Flow chart

 

 

 

 三. Code

Freaduino Control Side code


//

#include <NewSoftSerial.h>
#include <avr/pgmspace.h>

#define rxPin 2
#define txPin 3

NewSoftSerial mySerial(rxPin, txPin);

void setup()
{
  // define pin modes for tx, rx pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);

  mySerial.begin(9600);
  Serial.begin(9600);
}

void loop(){
   // 0.175 is for Correcting the pox to 90, servor pos defoult 90. This data you can change by yourself
   int posX=(int)analogRead(A0)*0.175;
   int posY=(int)analogRead(A1)*0.175;

   mySerial.print("x");
   mySerial.print(posX);
   mySerial.print("y");
   mySerial.print(posY);
   mySerial.println("End");

   Serial.print("x=");
   Serial.println(posX);
   Serial.print("y=");
   Serial.println(posY);

   delay(300);
 }

Arduino Control Side code


#include <NewSoftSerial.h>
#include <Servo.h>
#include <String.h>

#define rxPin 2
#define txPin 3
NewSoftSerial mySerial(rxPin, txPin);

Servo myservoX;  // create servo object to control a servo
Servo myservoY;                // a maximum of eight servo objects can be created

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
  myservoX.attach(5);  // attaches the servo on pin 9 to the servo object
  myservoY.attach(3);
}

void loop() {
  int i = 0, n=0, count=0;
  char someChar[32]={0};
  // when characters arrive over the serial port...
  if(Serial.available()) {
    do{
      someChar[i++] = Serial.read();
    }while (Serial.available() > 0);

    if(someChar[0] == 'x')
    {
      int flag = 1;
      while(flag)
      {
          if(Serial.available()) {
              do{
                    someChar[count++] = Serial.read();
              }while (Serial.available() > 0);

              if(strstr(someChar, "End"))
              { 
                flag=0;
                while(someChar[n] != 'y') n++;
                char tmpbufx[4] = {0};
                strncpy(tmpbufx, someChar, n);
                int posX = atoi(tmpbufx);
                myservoX.write(posX);

                n=0;
                char* str = strchr(someChar,'y');
                char tmpbufy[4] = {0};
                while(str[n] != 'E') n++;
                strncpy(tmpbufy, str+1, n-1);
                int posY = atoi(tmpbufy);
                if(posY>105) posY = 105;
                else if(posY<85) posY = 85;
                myservoY.write(posY); 
              }
          }
      }
    }
  }
}

 

四. Cautions :

  • Please set Bluetooth Shield to Atuo paired mode. You need enter AT mode, and used AT+CMODE=1  . Please make sure you Master and chient Bluetooth Module has the same pair password.

 

 

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 1 vote)

Related Posts

7 Comments

  1. www.youtube.com

    Precisely how have you start-up a web site? I actually want
    to start one up in connection with automobiles, yet do not appreciate how to get started.
    Pretty much any assistance is greatly appreciated ;-)

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
    Reply
  2. www.youtube.com

    I wish I could process my thoughts quicker. So want to
    setup a site like this.

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
    Reply
  3. sell my car ibstock

    Excellent point. Could not agree with you more.

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
    Reply
  4. buy my jeep

    Really dont want to overlook a future posts..

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
    Reply
  5. Borrego

    è isso aí irmão, se não for ja era, mas te certinho é assim mesmo, porque é ué.

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: -1 (from 1 vote)
    Reply
  6. nonojo

    Leading the fashion design, service to the people theme set to perfect the top French tradition of work.

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: -1 (from 1 vote)
    Reply
  7. John

    What R/C car are you using in this project? Brand and model please?

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: +1 (from 1 vote)
    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Go To Top