Thursday, December 11, 2014

Today we are putting all the pieces together. We have properly attached a KeyesIR sensor to our tank and we have successfully detected output signals from the sensor if an object is placed 15 cm in front of it. If an object is detected in front of the tank the sensor will sent an output signal to the motor shield. The signal is then used as an input for the stepper motor code which tells the tank to turn or not. The tank is programed to turn to the right, only,  if an object is detected and will continue to turn until the sensor stops sending a signal saying somethings in front of it. here is the code:

int leftmotor = 1;
int rightmotor = 2;
int sensor = A0;

void setup()
{
  pinMode(A0, INPUT);
  pinMode(1,OUTPUT);
  pinMode(2,OUTPUT);
  
}

void right()
{
  digitalWrite(leftmotor, HIGH);
  digitalWrite(rightmotor, LOW);
}

void straight()
{
  digitalWrite(leftmotor, HIGH);
  digitalWrite(rightmotor, HIGH);
}

void loop()
{
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  if( analogRead(1))
  {
    straight();
  }
  else if( analogRead(0))
  {
    right();
  }
}

No comments:

Post a Comment