Wednesday, 22 August 2012

Computer controlled vehicle

Having tested out the motor controller its now time to put them together to make a simple vehicle. To try this out I just stuck the two robot feet together with gaffer tape:
I used some longer wires to connect them up to the Arduino so they could move around a bit.

I wired up a second motor controller on the breadboard, same as the first one. I made a video of doing this, which you can see here

I then wrote a more sophisticated version of the original sketch which allows me to send commands to the Arduino to get the vehicle to stop and go (as before) and turn right and left. Here it is:


//left and right motors
int motorPinL = 9;
int motorPinR = 10;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pins as an output.
  
   pinMode(motorPinL,OUTPUT);
   pinMode(motorPinR,OUTPUT);
   Serial.begin(9600);
  } 

// the loop routine runs over and over again forever:
void loop() {
  
  if (Serial.available() > 0)
  {
    char ch = Serial.read();
    // press 'g' to go:
    if (ch == 'g')
    { digitalWrite(motorPinL, HIGH);
      digitalWrite(motorPinR, HIGH);
    }
    if (ch == 's')
    // press 's' to stop:
    {digitalWrite(motorPinL, LOW);
    digitalWrite(motorPinR, LOW);
    }
    if (ch == 'r')
    // press 'r' to run just one motor:
    {  digitalWrite(motorPinL, LOW);
      digitalWrite(motorPinR, HIGH);
    }
    if (ch == 'l')
    // press 'l' to run the other motor:
    {
    digitalWrite(motorPinR, LOW);
    digitalWrite(motorPinL, HIGH);}
  }
}

This video shows the vehicle working:

All very well but now I need to look into how to make the vehicle more autonomous, so for example it can avoid obstacles.

No comments:

Post a Comment