hey guys im at my ends rope.
im.going to start fresh hopefully you can offer a
sketch that i can use to
make sure my l239d is working
and my power sources are correct
thank you.
hey guys im at my ends rope.
im.going to start fresh hopefully you can offer a
sketch that i can use to
make sure my l239d is working
and my power sources are correct
thank you.
In response to your original
In response to your original post, https://www.robotshop.com/letsmakerobots/james-robot-driving-me-crazy , ggallant said, " I would suggest that you separate the program into 3 individual programs (motor, servo, & sonar) and debug each module independently.“
Below the code from your original post with everything except the motor control removed. The main loop is reduced to a few static motor commands to test the motor/driver circuit.
I have breadboarded the L293d with two pager motors to test the code/circuit. Everything runs fine. Try doing this with each part of your project (ie, sonar, servo, etc). Make each function (ex. sonar) a seperate program and debug it. Once you have that function working, add it to your project and make sure it still works. If it does not work, then investigate why it does not work before you add more code. In the end, this will be a lot less trouble than trying to debug a larger program with many functions all at once.
#define LeftMotorForward 2
#define LeftMotorBackward 3
#define RightMotorForward 5
#define RightMotorBackward 4
void setup() //This block happens once on startup
{
Serial.begin(9600);
pinMode(LeftMotorForward, OUTPUT);
pinMode(LeftMotorBackward, OUTPUT);
pinMode(RightMotorForward, OUTPUT);
pinMode(RightMotorBackward, OUTPUT);
}
void loop() //This block repeats itself while the Arduino is turned on
{
moveForward();
delay(1000);
moveStop();
delay(500);
moveLeft();
delay(1000);
moveStop();
delay(500);
moveRight();
delay(1000);
moveStop();
delay(500);
moveBackward();
delay(1000);
moveStop();
delay(500);
}
void moveForward() //This function tells the robot to go forward
{
Serial.println(”");
Serial.println(“Moving forward”);
digitalWrite(LeftMotorBackward, LOW);
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(RightMotorBackward, LOW);
digitalWrite(RightMotorForward, HIGH);
}
void moveBackward() //This function tells the robot to move backward
{
Serial.println("");
Serial.println(“Moving backward”);
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, HIGH);
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, HIGH);
}
void moveLeft() //This function tells the robot to turn left
{
Serial.println("");
Serial.println(“Moving left”);
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, HIGH);
digitalWrite(RightMotorBackward, LOW);
digitalWrite(RightMotorForward, HIGH);
}
void moveRight() //This function tells the robot to turn right
{
Serial.println("");
Serial.println(“Moving right”);
digitalWrite(LeftMotorBackward, LOW);
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, HIGH);
}
void moveStop() //This function tells the robot to stop moving
{
Serial.println("");
Serial.println(“Stopping”);
digitalWrite(LeftMotorBackward, LOW);
digitalWrite(LeftMotorForward, LOW);
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, LOW);
}
Good Luck!
Don M
My apologies
Sorry for that. Ok thanks to all your help, I started over
and discovered the issue was the shield. I just ran a test everything works. Robot is up and running.
Next I need to adjust the distances because its running into walls.
Thanks guys this is the moral booster I have been wanting