Trying to get motors to work

im currently programming an autonomous car and no matter what I do with the code my left wheel always turns forwards and not both directions like my right motor/wheel.

const int EN1=9;
const int MC1A=3;
const int MC2A=2;
const int DIST=A2;
const int EN2=5;
const int MC3B=6;
const int MC4B=7;

void setup()
{
  pinMode(EN1,OUTPUT);
  pinMode(MC1A,OUTPUT);
  pinMode(MC2A,OUTPUT);
  brake();
}

void loop()
{
  forward();
  delay(3000);
  brake();
  delay(1000);
  backward();
  delay(3000);
  brake();
  delay(1000);
}

void forward()
{
  digitalWrite(EN1,LOW);
  digitalWrite(MC1A,HIGH);
  digitalWrite(MC2A,LOW);
  analogWrite(EN1,255);
  digitalWrite(EN2,LOW);
  digitalWrite(MC3B,HIGH);
  digitalWrite(MC4B,LOW);
  analogWrite(EN2,255);
}

void backward()
{
  digitalWrite(EN1,LOW);
  digitalWrite(MC1A,LOW);
  digitalWrite(MC2A,HIGH);
  analogWrite(EN1,255);
  digitalWrite(EN2,LOW);
  digitalWrite(MC3B,LOW);
  digitalWrite(MC4B,HIGH);
  analogWrite(EN2,255);
}

void brake()
{
  digitalWrite(EN1,LOW);
  digitalWrite(EN2,LOW);
}

I switch the mc1a lows/highs but nothing, I change both motors and nothing changes. it just loves to go forward!

This is the h-bridge schematic I've been using but with 2 motors and 6 wires coming from the arduino and no pot instead.

So why not a correct schematic instead? Are you still using a 9 volt battery for both motors? What IC are you using for the h-bridge?

im just using what ive been provided by my instructor, i also cant find the correct schematic anywhere on google or even arduino and my h bridge is l2930. the arduino and batteries I have give an output of 11v which works.

I noticed that you declared the pinMode for EN1 but not for EN2. Could that be the problem?
MC3B and MC4B as well.

ill check that because i didnt even notice that (thanks)

That didnt do anything when it came to the direction the motor should be spinning :frowning:

What made You wire the things like this? Likely not throwing a dice.
Schematics for a setup like this are easily made using pen and paper. Adding pin designations and voila!

The only other thing I noticed is that pin 5 (which you are using for EN2) seems to have a special function that no other digital pin in that section of the board has. Maybe try moving EN2 from pin 5 to pin 4?

im just following the instructions man :sob:


so i go to h bridge and that's the schematic given already.

switched it as soon as i read your message and it didn't work either.

Please extract the schematic and post it here.

okay dude. idk what your not understanding but i dont have the correct schematic because there isnt one with an h bridge. ive searched for over a month now. ive given you what i have found and have been provided. do not ask for a schematic again because i will say this exact same thing and it will be a waste of both of our time. ive said it twice, this being the third. read carefully please and stop trying to get more stuff from me when i have provided what i have, there is nothing else to provide and there is nothing else to say besides read and listen and observe. if you dont read you dont learn, if you dont listen you dont learn, if you dont observe you dont learn. Im not telling you how to live your life but instead giving the best adivce to someone like you that i can give. youve asked 3 times and have gotten the same answer each, it should be quite obvious now.

True!

Read, and use this link: How to get the best out of this forum - Using Arduino / IDE 1.x - Arduino Forum

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