I have a Solarbotics motor driver board http://www.solarbotics.com/products/k_cmd/. A search doesn't bring up anything in detail about random dc motor direction and speed. I am not a skilled programmer. Does this involve pages of complicated code? I would appreciate advise.
Not at all, it should be fairly simple writing code actually!
I believe all you're going to need to do, is get two PWM pins, and connect them to the board!
MAKE SURE you do NOT use the arduino supply. And when you're using a second power supply.. whether it be battery or wall-wart, you need to connect the ground of the arduino to the ground of that supply as well.
Are you looking to do random direction and speed? Or is that just an issue you've come across?
It should be fairly simple writing code to do the random as well.
If nobody gives you a sample, or you don't get it figured out by the time I get home, I'll see what I can do to write up some demo-code:D
I am working on a stationary sculpture that will use motors to shake, swing, and plunge randomly when the viewer approaches. I have proximity sensors and a collection of children's toy parts to add sound and light. I am hoping to add other motors that activate by limit switches in the path of these two motors powered by the driver. The movement should be less predictable, more organic. I would certainly appreciate any code! Thank you.
!! That's a great idea! You HAVE to post some videos of the sculpture when it's all completed!
I did a search for the Arduino L293D, and came up with a link to well.. my favorite site!!
http://letsmakerobots.com/node/2074
He includes some very simple code there,
But NOTE:
the schematic for hooking up the L293D to the Arduino on that site is WRONG.
The pins from the arduino are good, but the power connections are.. funny. They will work, but could also damage your chip.
The best schematic I found was on the datasheet, page 8.
Also, take a look at this thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240090778
Hopefully these offer some insight!
I have a bunch of L293Ds.. bought 10 for like $10 or something.. still haven't used them, the motors I had.. well.. were crap-o-la and nearly impossible to remove. So I'm stuck with looking at them! (along with like $300 worth of stuff I've ordered, because I over order, haha)
But anyways, best of luck, and do keep us updated! This sounds like an interesting project:D
This code will do random speed but how do I add random direction?
int randNumber; // variable to store the random value
int motor = 10; // motor
void setup() {} // no setup needed
void loop()
{
randomSeed(millis()); // sets millis() as seed
randNumber = random(255); // random number from 0-255
analogWrite(motor, randNumber); // outputs PWM signal
delay(3500); // pauses for half a second
}
You will have a pin that controls the direction of the motor.
Put it in a variable and call it dir so all you need to add is:-
if(random(100) > 50) digtialWrite(dir, HIGH); else digtialWrite(dir, LOW);
also put the
randomSeed(millis()); // sets millis() as seed
into setUp() as you don't want it initialising each time round the loop.
Thank you so much! This code is working great:
int randNumberSpeed; // variable to store the random speed value
int randNumberDir; // variable to store the random direction value
int motorSpeed = 10; // motor speed
int motorDir = 9; // motor direction
void setup()
{
randomSeed(millis());
}
void loop()
{
randomSeed(millis()); // sets millis() as seed
randNumberDir = random(255); // random number from 0-255
analogWrite(motorDir, randNumberDir); // outputs PWM signal
delay(3500); // pauses for half a second
randNumberSpeed = random(255); // random number from 0-255
analogWrite(motorSpeed, randNumberSpeed); // outputs PWM signal
delay(500); // pauses for half a second
}