Sreejith K K
User Experience Designer

















								
Arduino-code:

int motor_left[] = {2, 3};
int motor_right[] = {4, 5};
int fork_lift[] = {6,7};
int senpi1 = 8;
int senpi2 = 23;
int senpi3 = 10;
int obsti =  19;
int count = 0;
int count1 =0;


void setup() {
int i;
for(i = 0; i < 2; i++)
{
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
}
for(i = 0; i < 2; i++)
{
pinMode(fork_lift[i], OUTPUT);
pinMode(fork_lift[i], OUTPUT);
}
pinMode(senpi1, INPUT);
pinMode(senpi2, INPUT);
pinMode(senpi3, INPUT);
pinMode(obsti, INPUT);
}


void loop()
{
int obs = digitalRead(obsti);
int sp1 = digitalRead(senpi1); 
int sp2 = digitalRead(senpi2);
int sp3 = digitalRead(senpi3); 


if (obs == 0)
{
 if (sp1 == 0 && sp2 == 1 && sp3 == 1)
   { 
    turn_right();
    delay(25);
    motor_stop();    
  }
 else if(sp1 == 1 && sp2 == 0 && sp3 == 1)
 {
   drive_forward();
   delay(10);
   motor_stop();
 }
 else if(sp1 == 1 && sp2 == 1 && sp3 == 0)
  {
    turn_left();
    delay(25);
    motor_stop();
  }  
  else if(sp1 == 1 && sp2 == 1 && sp3 == 1)
  {
 drive_forward();
 delay(10);
 motor_stop();
  }
   else if(sp1 == 0 && sp2 == 0 && sp3 == 0)
   {
     motor_stop();
     if(count1 > 2)
      { 
       motor_stop();
      }
      else
        {
        fork_liftdown();
        fork_liftstop();
        delay(2000);
        fork_liftup();
        fork_liftstop();
        drive_forward();
        delay(10);
        }
     count1++;
      }                          
}
else
 {
   motor_stop();
 }
} 

void motor_stop(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], LOW);
delay(25);
}

void drive_forward(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}

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

digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}

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

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}
void fork_liftup()
{
  digitalWrite(fork_lift[1], LOW);
  digitalWrite(fork_lift[0], HIGH);
  delay(3000);
  digitalWrite(fork_lift[0], LOW);
  digitalWrite(fork_lift[1], LOW);
} 
void fork_liftdown()
{
  digitalWrite(fork_lift[0], LOW);
  digitalWrite(fork_lift[1], HIGH);
  delay(3000);
  digitalWrite(fork_lift[0], LOW);
  digitalWrite(fork_lift[1], LOW);
}
void fork_liftstop()
{
  digitalWrite(fork_lift[0], LOW);
  digitalWrite(fork_lift[1], LOW);
}