Arduino yellow drummer robot?

I was looking at building a yellow drummer robot that I saw in Make 25. I don't have a Picaxe, the problem is that I have seen pictuures and videos of people that have used arduino but no detailed instructions. Can anyone give me a link to instructions or  give me tips. The best help I have had so far is the code. But how do I connect it up?
(I have a arduino deumonlatave, but it should still work).

// Yellow Drum Machine Program for Arduino Uno


// setup pins and variables for SRF05 sonar device
int echoPin = 12;                               // SRF05 echo pin (digital 12)
int initPin = 13;                               // SRF05 trigger pin (digital 13)
unsigned long pulseTime = 0;                    // stores the pulse in Micro Seconds
unsigned long distance = 0;                     // variable for storing the distance (cm)

// setup pins for drivetrain motors
int DCMotor1Drive = 10;                         // DCMotor1 Drive Pin (PWM 3)
int DCMotor1Reverse = 3;                        // DCMotor1 Reverse Pin (PWM 10)      
int DCMotor2Drive = 9;                          // DCMotor2 Drive Pin (PWM 6)
int DCMotor2Reverse = 6;                        // DCMotor2 Reverse Pin (PWM 9)

// setup pins for sonar pivot pager
int SensorPagerRight = 11;                        // SensorPager rotate right Pin (digital #)
int SensorPagerLeft = 5;                         // SensorPager rotate left Pin (digital #)

// setup pins for drumstick pagers
int Pager1 = 8;                           // Pager1 rotate forward Pin (digital #)
int Pager2 = 2;                         // Pager1 rotate reverse Pin (digital #)
int Pager3 = 1;

int speed = 0;
int averageDistance = 0;                        // stores the average distance value
int mode = 0;

// Function for sonar reader
int readsonar() {
  // variables to take x number of readings and then average them
  // to remove the jitter/noise from the SRF05 sonar readings
  const int numOfReadings = 10;                   // number of readings to take/ items in the array
  int total = 0;                                  // stores the cumlative total
 
  // create array loop to iterate over every item in the array
  for (int i = 0; i < numOfReadings; i++) {
  
    // Trigger sonar to take reading
    digitalWrite(initPin, HIGH);                    // send 10 microsecond pulse
    delayMicroseconds(10);                          // wait 10 microseconds before turning off
    digitalWrite(initPin, LOW);                     // stop sending the pulse
   
    // Read sonar distance
    pulseTime = pulseIn(echoPin, HIGH);             // Look for a return pulse, it should be high as the pulse goes low-high-low
    distance = pulseTime/58;                        // Distance = pulse time / 58 to convert to cm.
    total= total + distance;                        // add the reading to the total
  }
return total / numOfReadings;
}

// Drivetrain movement command functions
  /* Drivetrain Forward */
  int goforward(int speed) { 
    analogWrite(DCMotor1Reverse, 0);
    analogWrite(DCMotor1Drive, speed);
    analogWrite(DCMotor2Reverse, 0);
    analogWrite(DCMotor2Drive, speed);
  }
  /* Drivetrain Reverse */
  int goreverse(int speed) {
    analogWrite(DCMotor1Reverse, speed);
    analogWrite(DCMotor1Drive, 0);
    analogWrite(DCMotor2Reverse, speed);
    analogWrite(DCMotor2Drive, 0);
  }
       
  /* Drivetrain Turn Right */
  int goright(int speed) {
    analogWrite(DCMotor1Reverse, 0);
    analogWrite(DCMotor1Drive, speed);
    analogWrite(DCMotor2Reverse, 0);
    analogWrite(DCMotor2Drive, 0);
  }
  /* Drivetrain Turn Left full speed*/
  int goleft(int speed) {
  analogWrite(DCMotor1Reverse, 0);
  analogWrite(DCMotor1Drive, 0);
  analogWrite(DCMotor2Reverse, 0);
  analogWrite(DCMotor2Drive, speed); 
  }
 
  /*Drivetrain turn around*/
  int turnaround(int speed) {
     analogWrite(DCMotor1Reverse, 0);
     analogWrite(DCMotor1Drive, 255);
     analogWrite(DCMotor2Reverse, 255);
     analogWrite(DCMotor2Drive, 0);
  }
 
  /* Pager Pulse functions */
  int rightstick() {
    digitalWrite(Pager1, 0);
    delay(200);
    digitalWrite(Pager1, 1);
  }
 
  int leftstick() {
    digitalWrite(Pager2, 1);
    delay(200);
    digitalWrite(Pager2, 0);
  }
 
  int tailstick() {
    digitalWrite(Pager3, 1);
    delay(200);
    digitalWrite(Pager3, 0);
  }
 
  
//Operational Modes

  //Target Seeking Mode
 int findtarget() {
   int Center = readsonar();
   if (Center > 50) 
     goforward(255); //Go forward!
   else
     mode = 1; //
 }
 
  //Fine-Tune Targeting Mode
 int lockontarget() {
    // Reading and moving the sonar
    int Center = readsonar();
    digitalWrite (SensorPagerLeft, 1);
    digitalWrite (SensorPagerRight, 0);
    delay (500);
    int Left = readsonar();
    digitalWrite (SensorPagerLeft, 0);
    digitalWrite (SensorPagerRight, 1);
    delay (500);
    int Right = readsonar();
    digitalWrite (SensorPagerLeft, 0);
    digitalWrite (SensorPagerRight, 0);
    delay (500);
   
    //Speed and Direction Control
     if ((Center < Right) && (Center < Left)) { 
       if (Center > 50) 
         goforward(255); //Go forward!
       else if (Center > 7)
         goforward(128); //
       else
         mode = 2;
     }
     else if ((Right < Center) && (Right < Left)) {
       if (Right > 50) 
         goright(255); //Go forward!
       else if (Right > 7)
         goright(128); //
       else
         mode = 2;
     }
     else if ((Left < Center) && (Left < Right)) {
       if (Left > 50) 
         goleft(255); //Go forward!
       else if (Left > 7)
         goleft(128); //
       else
         mode = 2;
     }
 }

//LET THE BEAT DROP!
int makesomenoise() {
   tailstick();
   rightstick();
   leftstick();
   delay (500);      
   tailstick();
   rightstick();
   leftstick();
   delay (500);
   tailstick();
   rightstick();
   leftstick();
   delay (500);
   tailstick();
   tailstick();
   tailstick();
   tailstick();
   rightstick();
   leftstick();
   tailstick();
   rightstick();
   leftstick();
   delay (500);
   tailstick();
   rightstick();
   leftstick();
   delay (500);
   mode = 3;
}
 
   //Go Somewhere Else//
 int runaway()
 {
   goreverse(255);
 }
    
        
// setup
void setup() {
  pinMode(DCMotor1Drive, OUTPUT);                     // sets DCMotor1Drive as output
  pinMode(DCMotor1Reverse, OUTPUT);                   // sets DCMotor1Reverse as output
  pinMode(initPin, OUTPUT);                           // set init pin 13 as output
  pinMode(echoPin, INPUT);                            // set echo pin 12 as input
  pinMode(Pager1, OUTPUT);
  pinMode(Pager2, OUTPUT);
  pinMode(Pager3, OUTPUT);

  digitalWrite(Pager1, 1);
  digitalWrite(Pager2, 0);
  digitalWrite(Pager3, 0);
 
 // initialize the serial port, lets you view the
 // distances being pinged if connected to computer
 //    Serial.begin(9600); 
 }

void loop()
{
  if (mode == 0)
    findtarget();
  else if (mode == 1)
    lockontarget();
  else if (mode == 2)
  {
    makesomenoise();
    turnaround(255);
    mode = 0;
  }
  // Serial.println(mode, DEC);         // print out the average distance to the debugg
}
 


Picture of Arduino yellow drummer robot?
AndyGadget5 years ago
 
Full information for the YDM (Yellow Drum Machine) is on LetsMakeRobots and in the related threads.  The YDM was created by Frits, the webmaster of LMR.  There's also several similar builds by other people.