can we use same arduino programmed sketch for different motor drivers ?

i am expecting to build a bluetooth controlled 2WD robot using arduino. i need to use a pulolu dual VNH motor driver to run the two motors. i have a programmed arduino sketch that made for L293D Motor Shield .can i use that programmed sketch on my new robot that using pulolu motor driver without making any changes to code? if i need changes, what are they.? your help will make my project possible

http://www.apexelectrix.com/images/L293D_shield.JPG >> L293D MotorShield

https://a.pololu-files.com/picture/0J3747.1200.jpg?c4b8922dc1a9b571b95eacb6eb43a616 >> pulolu VNH driver

sort by: active | newest | oldest
hardarknight (author) 4 months ago

ANOTHER THING i should say i am so very new to arduino,

rickharris4 months ago

Yes / No.

It depends.

The sketch (programme) will be organised to use certain outputs as expected by the designed motor controler. If these outputs are compatable with the new controller then you should be Ok.

If not you need to change the programme - It is up to you to look carefully at the signals and see what you can make compatable.

hardarknight (author)  rickharris4 months ago

Can you say what are the changes sould i do.?

THIS IS THE SKETCH I PROGRAMMED TO USE IN L293D MotorShield

#include <AFMotor.h> //Adafruit Motor Shield Library. First you must download and install AFMotor library

#include <Servo.h> //Servo library. This is standard library. (Sketch -> Include Library -> Servo)

String voice;

AF_DCMotor motor1 (1, MOTOR12_1KHZ); //create motor #1 using M1 output on Motor Drive Shield, set to 1kHz PWM frequency

AF_DCMotor motor2 (2, MOTOR12_1KHZ); //create motor #2 using M2 output on Motor Drive Shield, set to 1kHz PWM frequency

Servo myServo; //define servo name

int LED1 = A0; //define LED 1 pin

int LED2 = A1; //define LED 2 pin

int buzzerPin = A2; //define buzzer pin

void setup()

{

Serial.begin(9600); //start serial communication

myServo.attach(10); //define our servo pin (the motor shield servo1 input = digital pin 10)

myServo.write(90); //servo position is 90 degrees

pinMode(LED1, OUTPUT); //A0 is output pin

pinMode(LED2, OUTPUT); //A1 is output pin

pinMode(buzzerPin, OUTPUT); //A2 is output pin

}

void loop()

{

while (Serial.available()){ //Check if there is an available byte to read

delay(10); //Delay added to make thing stable

char c = Serial.read(); //Conduct a serial read

if (c == '#') {break;} //Exit the loop when the # is detected after the word

voice += c; //Shorthand for voice = voice + c

}

if (voice.length() > 0){

if(voice == "*go ahead"){

forward_car();

}

else if(voice == "*go back"){

back_car();

}

else if(voice == "*turn right") {

right_car();

}

else if(voice == "*turn left") {

left_car();

}

else if(voice == "*turn on light") {

LED_on();

}

else if(voice == "*turn off light") {

LED_off();

}

else if(voice == "*buzzer") {

buzzer_on();

}

else if(voice == "*stop") {

stop_car();

}

voice=""; //Reset the variable after initiating

}

}

void forward_car()

{

motor1.run(FORWARD);

motor1.setSpeed(170);

motor2.run(FORWARD);

motor2.setSpeed(170);

delay(2000);

motor1.run(RELEASE);

motor2.run(RELEASE);

}

void back_car()

{

motor1.run(BACKWARD);

motor1.setSpeed(170);

motor2.run(BACKWARD);

motor2.setSpeed(170);

delay(2000);

motor1.run(RELEASE);

motor2.run(RELEASE);

}

void right_car()

{

myServo.write(0);

delay(1000);

myServo.write(90);

delay(1000);

motor1.run(FORWARD);

motor1.setSpeed(170);

motor2.run(BACKWARD);

motor2.setSpeed(170);

delay(1000);

motor1.run(RELEASE);

motor2.run(RELEASE);

}

void left_car()

{

myServo.write(180);

delay(1000);

myServo.write(90);

delay(1000);

motor1.run(BACKWARD);

motor1.setSpeed(170);

motor2.run(FORWARD);

motor2.setSpeed(170);

delay(1000);

motor1.run(RELEASE);

motor2.run(RELEASE);

}

void LED_on ()

{

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

}

void LED_off ()

{

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

}

void buzzer_on ()

{

tone(buzzerPin, 100);

delay(800);

noTone(buzzerPin);

}

void stop_car ()

{

motor1.run(RELEASE);

motor2.run(RELEASE);

}

iceng4 months ago

So I'm unfamiliar with VNH motor designation but scanning Pulolu litterateur I see a

Fleapower DC brush motor with a gearbox.. The block diagram of the 293 IC shows a full wave bridge that can be used to drive any kind of motor from DC to AC including some unipolar stepper motors.

Do you know what your motor specifications are ?

Speed, Torque, Current, Voltage, AC / DC, Phases ??

L293D.bmp
hardarknight (author)  iceng4 months ago

i am wishing to use a windshield wiper motors to do the project.because they are cheap and geared to high torque .i found the torque of that motor as 13.5 pound­feet and its run on 12v and below 15A .

I AM ADDING THE ARDUINO SKETCH HERE >>

#include <AFMotor.h> //Adafruit Motor Shield Library. First you must download and install AFMotor library

#include <Servo.h> //Servo library. This is standard library. (Sketch -> Include Library -> Servo)

String voice;

AF_DCMotor motor1 (1, MOTOR12_1KHZ); //create motor #1 using M1 output on Motor Drive Shield, set to 1kHz PWM frequency

AF_DCMotor motor2 (2, MOTOR12_1KHZ); //create motor #2 using M2 output on Motor Drive Shield, set to 1kHz PWM frequency

Servo myServo; //define servo name

int LED1 = A0; //define LED 1 pin

int LED2 = A1; //define LED 2 pin

int buzzerPin = A2; //define buzzer pin

void setup()

{

Serial.begin(9600); //start serial communication

myServo.attach(10); //define our servo pin (the motor shield servo1 input = digital pin 10)

myServo.write(90); //servo position is 90 degrees

pinMode(LED1, OUTPUT); //A0 is output pin

pinMode(LED2, OUTPUT); //A1 is output pin

pinMode(buzzerPin, OUTPUT); //A2 is output pin

}

void loop()

{

while (Serial.available()){ //Check if there is an available byte to read

delay(10); //Delay added to make thing stable

char c = Serial.read(); //Conduct a serial read

if (c == '#') {break;} //Exit the loop when the # is detected after the word

voice += c; //Shorthand for voice = voice + c

}

if (voice.length() > 0){

if(voice == "*go ahead"){

forward_car();

}

else if(voice == "*go back"){

back_car();

}

else if(voice == "*turn right") {

right_car();

}

else if(voice == "*turn left") {

left_car();

}

else if(voice == "*turn on light") {

LED_on();

}

else if(voice == "*turn off light") {

LED_off();

}

else if(voice == "*buzzer") {

buzzer_on();

}

else if(voice == "*stop") {

stop_car();

}

voice=""; //Reset the variable after initiating

}

}

void forward_car()

{

motor1.run(FORWARD);

motor1.setSpeed(170);

motor2.run(FORWARD);

motor2.setSpeed(170);

delay(2000);

motor1.run(RELEASE);

motor2.run(RELEASE);

}

void back_car()

{

motor1.run(BACKWARD);

motor1.setSpeed(170);

motor2.run(BACKWARD);

motor2.setSpeed(170);

delay(2000);

motor1.run(RELEASE);

motor2.run(RELEASE);

}

void right_car()

{

myServo.write(0);

delay(1000);

myServo.write(90);

delay(1000);

motor1.run(FORWARD);

motor1.setSpeed(170);

motor2.run(BACKWARD);

motor2.setSpeed(170);

delay(1000);

motor1.run(RELEASE);

motor2.run(RELEASE);

}

void left_car()

{

myServo.write(180);

delay(1000);

myServo.write(90);

delay(1000);

motor1.run(BACKWARD);

motor1.setSpeed(170);

motor2.run(FORWARD);

motor2.setSpeed(170);

delay(1000);

motor1.run(RELEASE);

motor2.run(RELEASE);

}

void LED_on ()

{

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

}

void LED_off ()

{

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

}

void buzzer_on ()

{

tone(buzzerPin, 100);

delay(800);

noTone(buzzerPin);

}

void stop_car ()

{

motor1.run(RELEASE);

motor2.run(RELEASE);

}