New here, first time posting. I want to add to the arduino insect bot

Well I am new here and this is my first post


Well I have build the arduino insect bot from the book Arduino bots and gadgets. It is in the picture. I have it working but I want to add a touch sensor and attach it to the shell. I have an idea on how to build it. I would use a small button attached to the shell with the lie going to analog A0 pin. This would stop the robot by centering the servos and giving it the ability to stop when the shell was pressed down.


Now the program is here.


#include <Servo.h>

Servo frontServo;
Servo rearServo;

int centerPos = 90;
int frontRightUp = 72;
int frontLeftUp = 108;
int backRightForward = 75;
int backLeftForward = 105;
int walkSpeed = 150; // how long to wait between steps
int centerTurnPos = 81;
int frontTurnRightUp = 63;
int frontTurnLeftUp = 117;
int backTurnRightForward = 66;
int backTurnLeftForward = 96;

// Ping Distance Measure
int pingPin = 4;
long int duration, distanceInches;
long distanceFront=0; //cm
int startAvoidanceDistance=20; //cm

long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 2;
}

long distanceCm(){
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
 
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
 
  distanceInches = microsecondsToInches(duration);
  return microsecondsToCentimeters(duration);
}

void center()
{
  frontServo.write(centerPos);
  rearServo.write(centerPos);
}

void moveForward()
{
  frontServo.write(frontRightUp);
  rearServo.write(backLeftForward);
  delay(125);
  frontServo.write(centerPos);
  rearServo.write(centerPos);
  delay(65);
 
  frontServo.write(frontLeftUp);
  rearServo.write(backRightForward);
  delay(125);
 
  frontServo.write(centerPos);
  rearServo.write(centerPos);
  delay(65);
}

void moveBackRight()
{
  frontServo.write(frontRightUp);
  rearServo.write(backRightForward-6);
  delay(125);
  frontServo.write(centerPos);
  rearServo.write(centerPos-6);
  delay(65);
  frontServo.write(frontLeftUp+9);
  rearServo.write(backLeftForward-6);
  delay(125);
 
  frontServo.write(centerPos);
  rearServo.write(centerPos);
  delay(65);
}

void moveTurnLeft()
{
  frontServo.write(frontTurnRightUp);
  rearServo.write(backTurnLeftForward);
  delay(125);
  frontServo.write(centerPos);
  rearServo.write(centerPos-6);
  delay(65);
  frontServo.write(frontLeftUp-+9);
  rearServo.write(backLeftForward-6);
  delay(125);
 
  frontServo.write(centerTurnPos);
  rearServo.write(centerTurnPos);
  delay(65);
}

void setup()
{
  frontServo.attach(2);
  rearServo.attach(3);
  pinMode(pingPin, OUTPUT);
}

void loop()
{
  distanceFront=distanceCm();
    if(distanceFront > 1){
      if (distanceFront<startAvoidanceDistance) {
        for(int i=0; i<=8; i++) {
        moveBackRight();
        delay(walkSpeed);
      }
     
      for(int i=0; i<10; i++){
        moveTurnLeft();
        delay(walkSpeed);
      }
     } else {
       moveForward();
       delay(walkSpeed);
     }
    }
}





I would like to know what line of code to add to receive input from pin AO and center the servo stopping the robot.






Picture of New here, first time posting. I want to add to the arduino insect bot
For best response you may want to post this question over in the Arduino Forums.

http://arduino.cc/forum/
kelseymh5 years ago
You'll probably get a faster response if you post a comment directly on the Instructable itself. Look for the big orange Add Comment link right below the text of every step.,
He says it's from a book...