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);
        }
}

Arduino Uno board Code for maje robot with defined pattern

Arduino Uno board Code for maje robot with defined pattern ROBOTIcs



#define left_motor 10             // Left motor speed control;
#define right_motor 11              // Controls speed of the right engine;
#define e1 8                        // Controls the direction of rotation of the left engine;
#define e2 9                        // Controls the direction of rotation of the left engine;
#define d1 12                       // Controls the direction of rotation of the right engine;
#define d2 13                       // Controls the direction of rotation of the right engine;
int trigger_front = A4;             // Controls the impulse sent from the front sensor
int echo_front = A5;                // Controls the pulse received from the front sensor
int trigger_left = A2;              // Controls the impulse sent from the front sensor
int echo_left = A3;                 // Controls the pulse received from the front sensor
int trigger_right = A0;             // Controls the impulse sent from the front sensor
int echo_right = A1;              // Controls the pulse received from the front sensor
                                  // Configuration of input types of variables declared;
void setup()
{
pinMode(trigger_front, OUTPUT);              // Arduino signal output trigger forward
pinMode(echo_front, INPUT);                  // Arduino signal input echo front
pinMode(trigger_left, OUTPUT);               // Arduino signal output trigger forward
pinMode(echo_left, INPUT);                   // Arduino signal input echo front
pinMode(trigger_right, OUTPUT);              // Arduino signal output trigger forward
pinMode(echo_right, INPUT);                   // Arduino signal input echo front
pinMode(left_motor, OUTPUT);                  // signal output from the Arduino's left engine speed
pinMode(right_motor, OUTPUT);                 // signal output of the right engine speed Arduino
pinMode(e1, OUTPUT);                          // Arduino signal output control the direction of rotation of the left engine
pinMode(e2, OUTPUT);                           // Arduino signal output control the direction of rotation of the left engine
pinMode(d1, OUTPUT);                           // Arduino signal output control the direction of rotation of the right engine
pinMode(d2, OUTPUT);                            // Arduino signal output control the direction of rotation of the right engine
}
                                                // code without endless repetition of the project;
void loop()
{
// declaration of variables used for project control;
long duration_front, duration_left, duration_right, rightt, leftt, front;
// It is declared the corresponding inputs and outputs//signal of the ultrasonic sensor and stored by the sensor that converts variable//the speed of sound is 340m / s or microseconds per centimeter, as // the signal goes and returns this time is the sensor half being = Time / 29/2; // thus follows also the other two sensors
digitalWrite(trigger_front, LOW);
delayMicroseconds(2);
digitalWrite(trigger_front, HIGH);
delayMicroseconds(5);
digitalWrite(trigger_front, LOW);
duration_front = pulseIn(echo_front, HIGH);
front = duration_front/29/2;
digitalWrite(trigger_left, LOW);
delayMicroseconds(2);
digitalWrite(trigger_left, HIGH);
delayMicroseconds(5);
digitalWrite(trigger_left, LOW);
duration_left = pulseIn(echo_left, HIGH);
rightt = duration_left/29/2;
digitalWrite(trigger_right, LOW);
delayMicroseconds(2);
digitalWrite(trigger_right, HIGH);
delayMicroseconds(5);
digitalWrite(trigger_right, LOW);
duration_right = pulseIn(echo_right, HIGH);
leftt = duration_right/29/2;
analogWrite(left_motor, 0); //block to initialize the inputs with pulse 0 // or off;
analogWrite(right_motor, 0); //
analogWrite(e1, 0); //
analogWrite(e2, 0); //
analogWrite(d1, 0); //
analogWrite(d2, 0); //
if(front>8)
{
//the use of the four if's down if within that are to control // handling robot,
// in order to keep it following the right wall straight;
if(rightt >8 && rightt< 13) // If the distance to the right wall // is between 9 and 12 cm, the robot remains straight;
{
analogWrite(left_motor, 120);
analogWrite(right_motor, 120);
analogWrite(e1, 255);
analogWrite(e2, 0);
analogWrite(d1, 0);
analogWrite(d2, 255);
}
if(rightt >=13) //If the distance to the right wall is greater than or equal to 13 cm, the robot increases its left engine speed to approach the right wall;
{
analogWrite(left_motor, 140);
analogWrite(right_motor, 100);
analogWrite(e1, 255);
analogWrite(e2, 0);
analogWrite(d1, 0);
analogWrite(d2, 255);
}
if(leftt <=8) // if in case the distance from the wall to the left is less than or equal to 8 cm, the robot increases its right engine speed to distance the left wall;
{
analogWrite(left_motor, 140);
analogWrite(right_motor, 100);
analogWrite(e1, 255);
analogWrite(e2, 0);
analogWrite(d1, 0);
analogWrite(d2, 255);
}
if(rightt <=8) // if in case the distance from the wall to the right is less than or equal to 8 cm, the robot increases its right engine speed to distance themselves from the right wall;
{
analogWrite(left_motor, 100);
analogWrite(right_motor, 140);
analogWrite(e1, 255);
analogWrite(e2, 0);
analogWrite(d1, 0);
analogWrite(d2, 255);
}
}
if(leftt <=20 && rightt>20 && front <=8) right(); //if in case the distance // front is less than or equal to 8 cm, the distance to the right is greater than 20 cm and the distance // the left is less than or equal to 20 cm it calls the function dir ();
if(leftt >20 && rightt>20 && front <=8) right(); //If the distance to the front // is less than or equal to 8 cm, the distance from the right is larger than 20 cm and the distance to left // is greater than 20 cm tell it calls the function ();
if(rightt <=20 && leftt>20 && front <=8) left(); //If the distance to the front // is less than or equal to 8 cm, the distance from the right is less than or equal to 20 cm and the distance from the left // is greater than 20 cm it calls the function Left ();
if(rightt <=20 && leftt<=20 && front <=8) voltar(); //if in case the distance // front is less than or equal to 8 cm, the distance to the right is less than or equal to 20 cm and the distance // the left is less than or equal to 20 cm it calls the function back ();
}
void left() //function to make the robot turn 90 left if he did not have exit the front and right;;
{
analogWrite(left_motor, 0);
analogWrite(right_motor, 0);
delay(100);
analogWrite(left_motor, 120);
analogWrite(right_motor, 120);
analogWrite(e1, 0);
analogWrite(e2, 255);
analogWrite(d1, 0);
analogWrite(d2, 255);
delay(700);
}
void right() // function to make the robot turn 90 right up if you do not exit the front or the left;
{
analogWrite(left_motor, 0);
analogWrite(right_motor, 0);
delay(100);
analogWrite(left_motor, 120);
analogWrite(right_motor, 120);
analogWrite(e1, 255);
analogWrite(e2, 0);
analogWrite(d1, 255);
analogWrite(d2, 0);
delay(800);
}
void voltar() // function to make the robot turn 180 if he did not have exit the front, right and left;
{
analogWrite(left_motor, 120);
analogWrite(right_motor, 120);
analogWrite(e1, 255);
analogWrite(e2, 0);
analogWrite(d1, 255);
analogWrite(d2, 0);
delay(1400);
}

Arduino Uno Code for lover robot


Arduino Uno Board Based project pof Lover Robot Code with Pin Digram and Details

Youtube Video for Demo

#include<Servo.h>
#define echoPin1 3
#define trigPin1 4
#define echoPin2 10
#define trigPin2 11
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
int amsl=5;
int amsr=6;
int amkl=7;
int amkr=8;
int head=9;
int aamsl;
int aamsr;
int aamkl;
int aamkr;
int ahead;
int Maximum=200;
int Minimum=0;
long duration1,distance1,duration2,distance2;

void setup()
{
  Serial.begin(9600);
  servo1.attach(amsl);
  servo2.attach(amsr);
  servo3.attach(amkl);
  servo4.attach(amkr);
  servo5.attach(head);
pinMode(trigPin1,OUTPUT);
pinMode(echoPin1,INPUT);
pinMode(trigPin2,OUTPUT);
pinMode(echoPin2,INPUT);
}


void loop()
{
  digitalWrite(trigPin1,LOW);
  digitalWrite(trigPin2,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1,HIGH);
    digitalWrite(trigPin2,HIGH);
    delayMicroseconds(10);
      digitalWrite(trigPin1,LOW);
        digitalWrite(trigPin2,LOW);
        duration1=pulseIn(echoPin1,HIGH);
     
        duration2=pulseIn(echoPin2,HIGH);
        distance1=duration1/58.2;
        distance2=duration2/58.2;
 if((duration1<40)&&(duration2<40))
 {
  for(aamsl=0;aamsl<90;aamsl++)
  {
    servo1.write(aamsl);
    servo2.write(aamsl);
  delay(15);
  }

  for(aamsl=0;aamsl<90;aamsl++)
  {
    servo3.write(aamsl);
    servo4.write(aamsl);
  delay(15);
  }
  delay(10000);
  for(aamsl=90;aamsl>0;aamsl--)
  {
 
    servo3.write(aamsl);
    servo4.write(aamsl);
  delay(15);
  }
  for(aamsl=90;aamsl>0;aamsl--)
  {
 
    servo3.write(aamsl);
    servo4.write(aamsl);
  delay(15);
  }

 }

}

Translate