Can any one please help me to convert this code from motorsheild v1 to v2

This is the code (BLUETOOTH_CAR.ino - Google Drive) please help me.

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

You are welcome on this forum! You are working on an informatic project and what is most needed in an informatic project is information imagine: do the other users here in the forum have a clear picture of what you are trying to do?

To speed up finishing your project you should invest some time into writing additional information I'm 100% sure that this WILL speed up finishing your project.

So please go through this checklist and if you find an item you haven't posted yet post it

  • did you write which exact type of microcontroller you are using?
  • description of your programming skills and knowledge
  • description of your knowledge about electronics
  • description of the functionality you want to have written in normal works avoiding programming terms
  • do you have an oscilloscope? Yes / No
  • do you have a digital multimeter (DMM) Yes / No)
  • your age
  • did you post your complete sketch?
  • if relevant did you post a link to a datasheet of each component you are using?
  • if relevant did you post a handdrawn schematic or your wiring?
  • if you got a compiler-error. Did you post the complete compiler-output into a code-section?

If you don't post all this information because you want a "quick answer" to your detail problem It is very likely to turn out that all that happens is having mutliple waiting-times with mutliple asking back for details until the other users do have a clear picture of what you want to do.

best regards Stefan

This compiles without error or warning. I don't know if it works on your hardware:

//Arduino Bluetooth Controlled Car
//Before uploading the code you have to install the necessary library
//Note - Disconnect the Bluetooth Module before hiting the upload button otherwise you'll get compilation error message.
//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install 
//After downloading the library open Arduino IDE >> go to sketch >> Include Libray >> ADD. ZIP Libray >> Select the downloaded 
//ZIP File >> Open it >> Done
//Now You Can Upload the Code without any problem but make sure the bt module isn't connected with Arduino while uploading code

#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Get pointer to the four motor ports
Adafruit_DCMotor *motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *motor2 = AFMS.getMotor(2);
Adafruit_DCMotor *motor3 = AFMS.getMotor(3);
Adafruit_DCMotor *motor4 = AFMS.getMotor(4);

char command; 

void setup() 
{       
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.
}

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;
    }
  } 
}

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

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

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

void right()
{
  motor1->setSpeed(255); //Define maximum velocity
  motor1->run(FORWARD); //rotate the motor clockwise
  motor2->setSpeed(255); //Define maximum velocity
  motor2->run(FORWARD); //rotate the motor clockwise
  motor3->setSpeed(255); //Define maximum velocity
  motor3->run(BACKWARD); //rotate the motor anti-clockwise
  motor4->setSpeed(255); //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
}

thanks you are my best freind thhanks it compiled thank you so much i was go so streesed with it thank you so much

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.