Let's Make Robots!

Controlling motor speed with 293 without a POT

This is my first step to robotics. In this project all i did was use an arduino with L293D to control the motor speed without a potentiometer. this was actually an assignment / a small test given to me by CtC (chris the carpenter). the motor is suppose to speed up and down with a delay. 

"stop - ramp up - hold - ramp down - stop"

motor_speed_control_code.pde1.79 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


a link to spi conections for the mega

50 (MISO) 51(MOSI) 52 (SCK),53,(SS),

It's nice for Patrick and CtC to help you along, but you need to do some homework.

It seems like you need some basic programming skills. Go to the LMR Primer and follow the links under Programming. There are three good resources for learning Arduino programming there.

#define motorpin1 3

#define motorpin2 4

#define enablepin3 8

int motorSpeed;

void setup(){

pinMode(motorpin1, OUTPUT);

pinMode(motorpin2, OUTPUT);

pinMode(enablepin3, OUTPUT);

digitalWrite(enablepin3, LOW);


void loop(){

digitalWrite(motorpin1, LOW);

digitalWrite(motorpin2, HIGH);

for(motorSpeed=0; motorSpeed<255; motorSpeed++){

analogWrite(enablepin3, motorSpeed);




for(motorSpeed=255; motorSpeed>=0; motorSpeed--){

analogWrite(enablepin3, motorSpeed);





You next misson, sir is to learn For-loops. I think the link to the arduino stuff is above.

Now we're getting somewhere. Very well done. I have not gone through the code yet but it looks like Pat is figuring out how to get you going a little cleaner.

That's it --you have my help on what ever you need.

Thank You :)

It is a start, but now I am extending the assignment. The code could be shortened and made better using a for loop http://www.arduino.cc/en/Reference/For

You do not need to keep writing the digital pins you use for direction unless you change the state of them.

An example of a for loop might be:

for(int x=0; x<255; x++){

analogWrite(enablepin, x); delay(20);


do something similiar for a ramp down.

thanx man lol....yea the way i did was the easyway...i knew there was another way but i couldnt understand it...so i guess i will try what u said.

Well, I guess you passed. Congratulations. Even better than making an LED blink.

thanks...i learned some programming doing flowcharts so i kind of had an idea on how the code should be like for the motor.