I completely disasembled the bot several time and finally figured out how to power each servo motor independently because a single 9v didm't provide enough power to move three motors and the sensor.
Then I went back to the simples version of my code. In this version, the ultrasonido sensor is not yet live because I just wanted to get everything actually working before I try to manipulate it to do specific actions.
Next Steps:
- walk forward
- detect an object
- look left then right
- determine the best course foward to avoid the obstacle
But for now, I feel this sense of relief that I can finally move forward with new code as everything is functioning.
Meet BB2A.
And here is the code for this iteration.
#include <Servo.h>
Servo frontServo;
Servo backServo;
Servo neckServo;
int centerPos = 90;
int frontRightUp = 72;
int frontLeftUp = 108;
int backRightForward = 75;
int backLeftForward = 105;
int lookLeft = 15;
int lookRight = 90;
void moveForward()
{
frontServo.write(frontRightUp);
backServo.write(backLeftForward);
delay (125);
frontServo.write(centerPos);
backServo.write(centerPos);
delay (65);
frontServo.write(frontLeftUp);
backServo.write(backRightForward);
delay (125);
frontServo.write(centerPos);
backServo.write(centerPos);
delay (65);
}
void sweep()
{
neckServo.write(centerPos);
delay (125);
neckServo.write(lookLeft);
delay (125);
neckServo.write(centerPos);
delay (125);
neckServo.write(lookRight);
delay (125);
}
void setup()
{
frontServo.attach(2);
backServo.attach(3);
neckServo.attach(6);
}
void loop()
{
moveForward();
delay(150);
sweep();
delay(150);
}