Great, glad to hear you got it working!
Yes, if you have the motors set to neutral and they are still moving (or trying to move), then you can use a screwdriver to turn the potentiometer in them to tune them (there's a little hole on either the side or back).
The wiring looks good, nice work!
Question regarding the code.
With the #define statement, does the value that comes after it mean much, other than the fact that it sets the state apart from other states?
The syntax for the #define statement is:
#define token value
Where "token" is the alias you want to use for "value." All it means is that you can use "token" instead of "value" in your program. So, for example, suppose that you have a function call like this in your program:
setMotor(180);
You could make a define like this:
#define FULL_SPEED 180
And use it like this:
setMotor(FULL_SPEED);
So when you run the program, the compiler just replaces the "token" with the "value" everywhere in your program.
However, important note: I've noticed that the Arduino compiler doesn't allow defines to be used in some functions. That's why in the program in the tutorial I declared the pin numbers as "const int," like this:
const int ultrasonic2TrigPin = 9;
I initially tried using #define statements, but the compiler wouldn't let me for some reason (a const int is a variable of type integer that remains constant throughout the program).
I'm working on writing code that when an object is detected, instead of turning left it takes measurements from both sides and follows the longer path. Also, and suggestions for this would be appreciated, as I'm new to C/Arduino.
Great idea! So do you have three ultrasonic sensors hooked up, one on the front and one on each side?
To know when to turn, and what way to turn, you'll need to measure the distance in front of the robot and check if it's less than some amount that you define (which means there's something in front of it), then you can check the distances on the left and right and based on which has a larger value, turn that direction and then drive straight again.
The best way to implement this would be using something called a finite state machine, but that's kind of challenging to learn, so I'd suggest getting something like the following pseudocode working first:
// get distances from all three ultrasonics
if(front ultrasonic < some distance) // if there's an object in front of the robot
{
if(left ultrasonic > right ultrasonic) // if the path on the left is larger than on the right
{
// set the motors to turn left
// use delay() to keep the robot turning for however many milliseconds it takes it to turn 90 degrees
}
else // if the path on the right is larger than on the left
{
// set the motors to turn right
// use delay() to keep the robot turning for however many milliseconds it takes it to turn 90 degrees
}
}
else
{
// set the motors to drive forward
}