Error in running both the servos and the DC motors powering the wheels


hi.

if can me out issue, appreciate it.

im planning build robot car not can move wheels using 2 brushed dc motors, @ same time, can control gripper installed car well, uses servo motors set motion.

i choose run on car using l298p 2a motor shield placed on top of arduino uno.

so far, managed car moving using manual code attached power these dc motors.

and managed control servos gripper motion using servo code attached.

but now, decided combine 2 together, can control motors running wheels , servo motors together. problem that, servos still function expected, dc motors seem glitch out little. right dc motor moves how should be, left 1 doesn't respond well. here code:

int e1 = 5;
int m1 = 4;
int e2 = 6;
int m2 = 7;
char incoming_byte = 0;

#include<servo.h>

servo myservo1;
servo myservo2;
servo myservo3;
servo myservo4;


int pos = 0;


void setup() {
 // put setup code here, run once:
serial.begin (9600);
 pinmode(m1, output); //left wheel//
 pinmode(m2, output); //right wheel
 myservo1.attach(3);
 myservo1.write(70);
 myservo2.attach(5);
 myservo2.write(70);
 myservo3.attach(7);
 myservo3.write(25);





}

void loop() {
 // put main code here, run repeatedly:
if(serial.available()>0)
  {
    incoming_byte=serial.read();
 
     ////////////servo1////////////
     if(incoming_byte=='f')
   { myservo1.write(30);
   }
   else if(incoming_byte=='g')
   { myservo1.write(70);
   }
   else if(incoming_byte=='h')
   { myservo1.write(45);
   }
   else if(incoming_byte=='j')
   {
     myservo1.write(104);
     }
     else if(incoming_byte=='l')
     { myservo1.write(116);
     }

     ////////////servo2////////////
   if(incoming_byte=='e')
   { myservo2.write(30);
   }
   else if(incoming_byte=='r')
   { myservo2.write(45);
   }
   else if(incoming_byte=='t')
   {
     myservo2.write(70);
     }
     else if(incoming_byte=='y')
     { myservo2.write(104);
     }
    else if(incoming_byte=='u')
     { myservo2.write(116);
     }
      ////////////servo3////////////
   
   if(incoming_byte=='i')
   { myservo3.write(25);
   }
   else if(incoming_byte=='o')
   {
     myservo3.write(110);
     }
     else if(incoming_byte=='p')
     { myservo3.write(120);
     }


////////////forward////////////
   if (incoming_byte == 'w')
   {
     digitalwrite(m1, high);
     digitalwrite(m2, high);
     analogwrite(e1, 120);
     analogwrite(e2, 120);
   }
   else if (incoming_byte == 'x')    {

     digitalwrite(m1, high);
     digitalwrite(m2, high);
     analogwrite(e1, 0);
     analogwrite(e2, 0);

   }

   ////////////reverse////////////
   if (incoming_byte == 's')
   {

     digitalwrite(m1, low);
     digitalwrite(m2, low);
     analogwrite(e1, 60);
     analogwrite(e2, 60);
   }
   else if (incoming_byte == 'x')
   {

     digitalwrite(m1, low);
     digitalwrite(m2, low);
     analogwrite(e1, 0);
     analogwrite(e2, 0);
   }

   /////left/////
   if (incoming_byte == 'a')
   {
     digitalwrite(m1, high);
     digitalwrite(m2, low);
     analogwrite(e1, 120);
     analogwrite(e2, 120);
   }
   else if (incoming_byte == 'x')
   { digitalwrite(m1, high);
     digitalwrite(m2, high);
     analogwrite(e1, 0);
     analogwrite(e2, 0);
   }

   ////right/////
   if (incoming_byte == 'd')
   {
     digitalwrite(m1, low);
     digitalwrite(m2, high);
     analogwrite(e1, 120);
     analogwrite(e2, 120);
   }
   else if (incoming_byte == 'x')
   { digitalwrite(m1, high);
     digitalwrite(m2, high);
     analogwrite(e1, 0);
     analogwrite(e2, 0);
   }

  }

}


this 1 of first arduino projects. know may simple out there , can learn guys. sincerely appreciate if can me out.

thanks lot!

hi,
welcome forum.

please read first post in forum entitled how use forum.
http://forum.arduino.cc/index.php/topic,148850.0.html down item #7 how post code.
it formatted in scrolling window makes easier read.

can please post copy of circuit, in cad or picture of hand drawn circuit in jpg, png?

what powering project with?
the motor driver have chosen not efficient, loose 2v across start.

thanks.. tom... :)


Arduino Forum > Using Arduino > Programming Questions > Error in running both the servos and the DC motors powering the wheels


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???