How to Fix this Arduino Car

// C++ code
//

define M1A 13

define M1B 12

define M2A 10

define M2B 9

define MAIN1 2

define MAIN2 3

void forward(unsigned long ms){
digitalWrite(M1A, HIGH);
digitalWrite(M1B, LOW);
digitalWrite(M2A, HIGH);
digitalWrite(M2B, LOW);
delay(ms);
}

void setup()
{//Setting all up as OUTPUTs
pinMode(MAIN2, OUTPUT);
pinMode(M1A, OUTPUT);
pinMode(M1B, OUTPUT);
pinMode(M2A, OUTPUT);
pinMode(M2B, OUTPUT);
}
void loop()
{
digitalWrite(M1A, LOW);
digitalWrite(M1B, LOW);
digitalWrite(M2A, LOW);
digitalWrite(M2B, LOW);

digitalWrite(MAIN1, HIGH);   //Turning on the two GearMotors
digitalWrite(MAIN2,HIGH);
forward(2000);
delay(2000);

forward(2000) 
  
;digitalWrite(M1A, HIGH); 
digitalWrite(M1B, LOW);
digitalWrite(M2A, LOW);
digitalWrite(M2B, HIGH);
delay(2000);

digitalWrite(M1A, LOW);  
digitalWrite(M1B, HIGH);
digitalWrite(M2A, HIGH);
digitalWrite(M2B, LOW);
delay(2000);

digitalWrite(M1A, LOW);  
digitalWrite(M1B, HIGH);
digitalWrite(M2A, LOW);
digitalWrite(M2B, HIGH);
delay(2000);

}

More information.

Please edit your post to add code tags.

For informed help, please read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.

In addition to @jremington response go through it

1 Like

This code was made to operate 2 gear motors to create a car that demonstrates the capability to turn left, and right as well as go backward and forwards for further info on code and circuitry access link to Tinkercad on the original post (at the bottom).

Nobody here is going to sign up for Tinkercad to answer your question.

Tell us what is not working ?

HI,
Export images from your Tinkercad project as jpg images and post them in a new post in this thread.

To add code please click this link;

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

1 Like

Sorry got this working but for some reason, it requires a laptop connection as a power source I need it to work off the 9V battery instead as it must operate independently. I'm not sure if the issue may be in the battery pack itself or the overall circuitry. Thanks for your help in advance.

Hi, @acemax

If you are using a PP3 smoke detector battery like this;
image
Then you will not get enough power from it to run your robot.

Tom.. :smiley: :+1: :coffee: :australia:

You haven't connected positive of battery to vin pin of Arduino

Once again I would like your advice as I am still unable to operate this car.

Try with a better battery. Or you can use two seperate 9v battery to power motor and Arduino

Can you post the pic of your actual circuit

Ya it will be helpful

1 Like

2 posts were split to a new topic: Arduino car problems

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