Search the Blog

Wednesday, August 14, 2019

Arduino Uno code for humoid robot

Arduino Uno Board complete code for humanoid robots for reception and science demo projects.


Youtube Video of Project is given above-



Define all the motor pins

#define left_motor 10
#define right_motor 11
#define e1 8
#define e2 9
#define d1 12
#define d2 13

define all the varibles

int trigger_front=A4;
int echo_front=A5;
int trigger_left=A2;
int echo_left=A3;
int echo_right=A1;
int trigger_right=A0;

Distance duration

long duration_front, duration_left, duration_right, left, right, front;


Setting of ALL PINS Activity

void setup()
{
   pinMode(trigger_front,OUTPUT);
   pinMode(echo_front,INPUT);
   pinMode(trigger_left,OUTPUT);
   pinMode(echo_left,INPUT);
   pinMode(trigger_right,OUTPUT);
   pinMode(echo_right,INPUT);
   pinMode(left_motor,OUTPUT);
   pinMode(right_motor,OUTPUT);
   pinMode(e1,OUTPUT);
   pinMode(e2,OUTPUT);
   pinMode(d1,OUTPUT);
}

Settting of Continuous Loop

  void loop()
  {
     sawan :
      digitalWrite(trigger_front,LOW);
      delayMicroseconds(2);
      digitalWrite(trigger_front,HIGH);
      delayMicroseconds(10);
      digitalWrite(trigger_front,LOW);
      delayMicroseconds(2);
      duration_front=pulseIn(echo_front,HIGH);
      front=duration_front/59.2;
      digitalWrite(trigger_left,LOW);
      delayMicroseconds(2);
      digitalWrite(trigger_left,HIGH);
      delayMicroseconds(10);
      digitalWrite(trigger_front,LOW);
      delayMicroseconds(2);
      duration_left=pulseIn(echo_left,HIGH);
      front=duration_left/59.2;
      digitalWrite(trigger_right,LOW);
      delayMicroseconds(2);
      digitalWrite(trigger_right,HIGH);
      delayMicroseconds(10);
      digitalWrite(trigger_right,LOW);
      delayMicroseconds(2);
      duration_right=pulseIn(echo_right,HIGH);                                        right=duration_right/59.2;
      delay(50);
      if((front>5)&&(left>5)&&(right>5))
      {
       analogWrite(left_motor,60);
          analogWrite(right_motor,60);
          analogWrite(e1,255);
          analogWrite(e2,0);
          analogWrite(d1,0);
          analogWrite(d1,255);
          delay(700);
          goto sawan;
        }
       else if((front>5)&&(left>5)&&(right<5))
        {
          analogWrite(left_motor,80);
          analogWrite(right_motor,50);
          analogWrite(e1,255);
          analogWrite(e2,0);
          analogWrite(d1,0);
          analogWrite(d1,255);
          delay(700);
          goto sawan;
        }
       else if((front>5)&&(left<5)&&(right>5))
        {
          analogWrite(left_motor,50);
          analogWrite(right_motor,80);
          analogWrite(e1,255);
          analogWrite(e2,0);
          analogWrite(d1,0);
          analogWrite(d1,255);
          delay(700);
          goto sawan;
        }

        else
  //((front>5)&&(left>5)&&(right>5))
        {
          analogWrite(left_motor,60);
          analogWrite(right_motor,60);
          analogWrite(e1,0);
          analogWrite(e2,255);
          analogWrite(d1,0);
          analogWrite(d1,255);
          delay(700);
        }
}

No comments:

Post a Comment

Translate