how to fix

i have this code but it has erors i don't know enough about programing arduino to get it to work

#include <Servo.h>

/* 
 * My First Robot
 *
 * This robot drive around and avoids objects with the Ping sonar.
 *
 */
 
int motor_left[] = {3, 4};
int motor_right[] = {5, 6};
int pingPin = 9;

int servoPin = 2;
int servoRange[] = {500, 2500};  // The min/max pulse lengths to send to the servo
int servoRotateTime = 500; // How long it takes to turn the servo 180 degrees

int dangerDist = 300; // How far should something be before we react?
int servoTime = 700; // How long it takes to turn the servo
int turnTime = 250; // How long it takes to turn 90 degrees with the motors
 
Servo servo;

// This is called when the Arduino starts up
void setup(){
  Serial.begin(9600);
  printString("Start\n");
 
  // Setup motor
  int i;
  for(i = 0; i < 2; i++){
    pinMode(motor_left[i], OUTPUT);
    pinMode(motor_right[i], OUTPUT);
  }
  
  // Servo
  servo.attach(2);
  servo.setMinimumPulse(500);
  servo.setMaximumPulse(2500);
  turn_servo(100);
}

// Arduino calls this infinite loop after setup()
void loop(){ 

  int dist = read_ping(); // Read distance ahead

  // There's nothing right in front of us
  if(dist > dangerDist){
    Serial.println("All Good\n");
    drive_straight();
    delay(50);
  }
  // Object ahead, find a better route
  else{
    Serial.println("Object Ahead\n");
    change_direction();
    delay(50);
  }
}

// Something is in front of us, so find the best alternate route.
// Look left and right and decide which has more distance to drive.
void change_direction(){
  motor_stop();
  
  // Look left
  turn_servo(180);
  int left = read_ping_avg();
  
  // Look right
  turn_servo(10);
  int right = read_ping_avg();
  
  // Neither are good options, turn around
  if(left < dangerDist &&  right < dangerDist){
    turn_right();
    delay(turnTime * 2);
    drive_straight();
  }
  // Right is better
  else if(left < right){
    turn_right();
    delay(turnTime);
    drive_straight();
  }
  // Left is better
  else { 
    turn_left();
    delay(turnTime);
    drive_straight();
  }
 
}

// Read the distance from the Ping sensor
int read_ping(){
  int timecount = 0;
 
  /* 
   * Send trigger pulse to ping to tell it to start
   */
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(pingPin, HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(pingPin, LOW); // Holdoff
  
  /* 
   * Listen for echo pulses
   */
   
  // Wait for input
  int val = digitalRead(pingPin); // Append signal value to val
  pinMode(pingPin, INPUT); // Switch signalpin to input
  while(val == LOW) { // Loop until pin reads a high value
    val = digitalRead(pingPin);
  }
  
  // Count pulses
  while(val == HIGH) { // Loop until pin reads a low value
    val = digitalRead(pingPin);
    timecount = timecount +1;
  }
  
  delay(10);
  
  return timecount;
}

// Get the average distance from 3 pings
int read_ping_avg(){
  
  int total = 0;
  total += read_ping();
  total += read_ping();
  total += read_ping();
  
  int avg = total/3;
  
  return avg;
}

// Turn the servo to a degree between 1 - 180.
void turn_servo(int degree){
  int servoStopAt = 0;
  
  // Set stop time
  if(servoStopAt == 0){
    servoStopAt = millis() + servoRotateTime;
  }
  
  servo.write(degree);
  
  // Refresh until the servo is done moving 
  // (using approximate timing set by servoRotateTime)
  while(servoStopAt > millis()){
    delay(20);
    Servo::refresh();
  }
}

/*
 * Motor movements
 */

void motor_stop(){
  digitalWrite(motor_left[0], HIGH); 
  digitalWrite(motor_left[1], HIGH); 
  
  digitalWrite(motor_right[0], HIGH); 
  digitalWrite(motor_right[1], HIGH);
}

void drive_straight(){
  turn_servo(100); // Look straight ahead
  
  digitalWrite(motor_left[0], LOW); 
  digitalWrite(motor_left[1], HIGH); 
  
  digitalWrite(motor_right[0], HIGH); 
  digitalWrite(motor_right[1], LOW); 
}

void turn_left(){
  digitalWrite(motor_left[0], HIGH); 
  digitalWrite(motor_left[1], LOW); 
  
  digitalWrite(motor_right[0], HIGH); 
  digitalWrite(motor_right[1], LOW); 
}

void turn_right(){
  digitalWrite(motor_left[0], LOW); 
  digitalWrite(motor_left[1], HIGH); 
  
  digitalWrite(motor_right[0], LOW); 
  digitalWrite(motor_right[1], HIGH); 
}

any help greatily apreciated

First things, first. Please select modify in your post, select the code, and select the # button. This puts the code in a scrollable window, with a gray background. Much easier to read that way.

Then,

i have this code but it has erors i don't know enough about programing arduino to get it to work

My crystal ball is at the cleaners this week. My oujii board is missing a piece or two.

What errors? Errors when compiling? Errors when running?

Well, one at a time:

  1. There's no "printString" - use "serial.println".
  2. There's no "setMinimumPulse" or "setMaximumPulse", and the values you've given are the defaults anyway.
  3. there's no "refresh" method anymore, so it simply isn't needed.

When posting code, please use the "#" button on the editor toolbar.

Also, this isn't really a Development section sort of question.

sorry i did say i was new the errors are when i compile
where is the best place to post these tipe of questions

where is the best place to post these tipe of questions

You are developing software for the Arduino. Perhaps you should post issues with Arduino Software Development on the Arduino > Software > Development forum.

Oh. So you did.

the errors are when i compile

Man, this is like pulling teeth.

What errors are you getting? Have you fixed them?