Autonomous Car

so im trying to do this basic code to get the motor to spin...

const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 9; // H-bridge enable pin

void setup()
{
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);

// set enablePin high so that motor can turn on: ADDED
digitalWrite(enablePin, HIGH);
}
void loop()
{
digitalWrite(motor1Pin, HIGH);
digitalWrite(motor2Pin, LOW);
}

if this is all correct it must be something with the connections i have. can someone verify this code should work so that i can move on from editing code to trying to fix my circuit.

also im using this schematic with the capacitor. http://itp.nyu.edu/physcomp/Labs/DCMotorControl im not using the switch though. is this schematic still good if i did everything but the switch?

is this schematic still good if i did everything but the switch?

Yes
but you need to use the code which dosent neeed a switch to activate the motor

exactly, so is the simple code i posted correct? because im still having issues and im not sure if its my code or my connections.

const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 9; // H-bridge enable pin

void setup()
{
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);

// set enablePin high so that motor can turn on: ADDED
digitalWrite(enablePin, HIGH);
}
void loop()
{
digitalWrite(motor1Pin, HIGH);
digitalWrite(motor2Pin, LOW);
}

well thats not going to work if you dont have a delay because the pin is switched too fast to make any sense to the motor

ok i understand. so with a delay(10000); to make it spin for 10 seconds is that code correct?

YES :slight_smile:

ok great. now i know my code works. now all i have to do is trouble shoot my connections... i wish i had an idea of where to begin..

i have already went two completely different ways. the first schematic and now im currently using the second. (minus the switch)

ok guys. so since with the help of newbie and a bunch of you ive finally figured out simple code that should make my motor spin the wheels. i need to figure out why it is not. so now i am on to my wiring. im using this schematic

what is crossed out in green i didnt use and i labeled and put in what i added. also im not using a 9v im using a 4 battery pack of AA batteries.

if anyone sees anything that i messed up or a better way to go about please post or message me. thanks a lot.

WEll you did wire up things corectly
And you Were right you didnt need that ground Extra And IS it Working :wink:

still not running. im at a lost considering my code and my wiring should both work. with other code i was trying i also made the led blink to see if the code was working at all and it was. i have no idea what to do as of right now. ive changed my wiring and coding twice with no success.

EDIT: im also going to get rid of the extra ground wire along with the two black wires to the left of it in the schematic because that side doesnt need ground because im not using it.

SECOND EDIT: im going to try a few things that will most likely not work (hard to be positive right now)

  1. changed to a 9v
  2. also im going to try to add simple LED code to see if thats getting sent to the board and being processed.

well where is your code ? abnd i just notice that your post is in the exhibition forum ;D

hah sorry when i first made my account i just kind of came on looked quickly and made on. if a mod wants to move it that would be great. i just now wrote up this code which the led is blinking but no motor movement.

#define m1p1 3 //motor one pin one
#define m1p2 4 //motor one pin two
const int ledPin = 13;
void setup()
{
pinMode (m1p1,OUTPUT);
pinMode (m1p2,OUTPUT);
pinMode(ledPin, OUTPUT);

blink(ledPin, 20, 100);
}
void loop()
{
digitalWrite(m1p1,HIGH);
digitalWrite(m1p2,LOW);
// drive motors forward set delay
delay(10000);
//now drive motors reverse both
digitalWrite(m1p1,LOW);
digitalWrite(m1p2,HIGH);
delay(10000);

}

void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs/2);
digitalWrite(whatPin, LOW);
delay(milliSecs/2);
}
}

Hmmm well but i see you use a enable pin in your schematic i guess pin 9 You need to put it high at all time to run the motors ! ( i didnt read the entire code )

Hi,

I don't know if this will help you but have a look anyway :stuck_out_tongue:

http://letsmakerobots.com/node/2074

Also while you're there have a look at some of the projects, there are a lot of ideas similar to yours and the community is really helpful :slight_smile:

i was planning on trying to bring in an enable pin the other day but i thought that had something to do with the switch and knowing when it was on. are you looking at the schematic that i edited with the green Xs? because it shows the switch crossed out. otherwise i dont see anything around pin 9 i will but an enablePin(HIGH) im my program a little later this morning and see how things go.

thanks again newbie for all the help.

are you looking at the schematic that i edited with the green Xs?

Yeah ! dont you see a blue colour wire goint from the first pin on l293 d from the right ? :-? :-?

ok so once again i went a completely different way and FINALLY success. i used the full schematic and didnt eliminate the switch and altered some code up and everything is working as of now.

now its time to start the real work.

FINALLY success............working as of now

:slight_smile:

now its time to start the real work

this time post in the interfacing forum :wink: