dontTouchMe!

dontTouchMe


robot runs away. Don't touch him!
 

mimicArm is shy and doesn't want to be touched.  This example is named for the best a capella song ever recorded.  Using the Sharp IR Distance Sensor mimicArm detects objects in front of it and backs away. 

Commands Used

if(conditional);
else if(conditional);
analogRead(pin);
robotMove(x,y);
robotJog(x,y);
delay(x);

Setup:

IR Distance Sensor Wiring

Connect your Sharp IR Distance to 5V, ground and pin A5 as shown.  Arduino is shown, but you can use the pins on your mimicArm controller that's attached to your Arduino.  Mount the IR Distance sensor in place of mimicArm's eyes. 

Download dontTouchMe.ino for Arduino

Cut and paste code:

#include <robot.h>

void setup() {
  robotActivate();   //let the robot know commands are coming
  delay(2000);       //let everybody boot up
}

void loop() {
  robotMode(arduino);  //set robot to accept Aruino commands
  robotMove(1, 127);   //move the base to center
  robotMove(3, 127);   //move the "elbow" to a neutral position

  if(analogRead(A5) > 250) robotJog(2,1);  //jog one unit if something is close
  else if(analogRead(A5) < 350) robotJog(2,-2);  //move forward if nothing is close
  delay(20);  
}