Step 13: Upload the Code and Test
If you're not using an Arduino - review the code below to figure out what's going on. It's not rocket science.
You should have a working motor controller!
//pin 8 = direction
//pin 9 = enable
void setup() {
pinMode(8, OUTPUT); //set direction pin as output
pinMode(9, OUTPUT); //set enable pin as output
}
void loop() {
//start off going forward at 50% throttle
digitalWrite(8, HIGH); //forward
analogWrite(9,128); //50% PWM
delay(2000);
//full speed ahead!
digitalWrite(9, HIGH); //full speed
delay(2000);
//and stop for a while
digitalWrite(9, LOW); //turn enable pin off
delay(1000);
//now lets go backwards
digitalWrite(8, LOW); //backward
analogWrite(9,128); //50% PWM
delay(2000);
//and stop for a while
digitalWrite(9, LOW); //turn enable pin off
delay(1000);
}
Remove these ads by
Signing Up
















































Visit Our Store »
Go Pro Today »




what kind of 12v battery are you using?
I get the feeling something is fundamentally wrong because no power comes through to the motor when it's supposed to be running in reverse.
any ideas?
this might sound really generic - but I would triple-check all the wiriing.
is it possible anything is backwards / upside down?
I'm assuming you're not really using a stepper motor - but some kind of geared DC motor (stepper motors require very special drivers).
Good luck - let me know how it goes.
-RIch
anyways I ordered a motor controller because I'll need to use servos too. this was a good experiment and got us an A on our class project, so thank you.
if you poke around online - you should be able to find some relays that would work fine at lower voltages.
glad you got it working!
-Rich
is it possible you connected your battery to VSS instead of VIN? that might do it.
I've found pushing the reset button just before programming can help it take an upload (shouldn't need to do this - but sometimes helps)
also - trying another USB port might help.
-Rich
I only asked you because you seem to know more than me about this stuff and I was desperately trying to find the problem. The seller has agreed to ship me a new arduino provided I return the dead one. Going to be a long wait from hong kong.
on the other hand - if you're not even seeing it as a serial port - that does sound like a hardware issue.
i will mentiin that while I've generally had good luck with clone arduino (pretty mcuh anything from asia) - I've maybe had a few more issues with them than the ones actually from italy.
good luck!
-Rich
I went ahead and ordered a motor controller based on the L293D from ebay. Just waiting for it to arrive from hong kong...
Im planning on building an autonomous vehicle that uses skidstearing. So basically like a little tank. Ive got alot to learn. Right now im pretty much just finding tutorials like this and copy/pasting code. Ive yet to come up with anything on my own.
good luck with your robot!
copy/pasting is a pretty good way to learn stuff. I suspect a large amount of commercial software is developed like that...
-Rich