The hand mechanism starts by poking the mouth of the birdlike mechanism, we’ll call it Bird. Once the Bird senses the finger coming closer (using photo sensors), it will close its beak. When this is happening, the finger will move back to avoid the biting beak by sensing a change of light using photosensors as well. This becomes a back and forth exchange between the two mechanisms without the intervention of a human.

Arduino Code for Hand

#include <Servo.h&gt;

Servo myservo;  


void setup() {
  myservo.attach(9);  
  Serial.begin(9600);
  myservo.write(90) ;
}

void loop() {
    Serial.println(analogRead(A0));

    while (analogRead(A0) &gt; 850){
    myservo.write(180);
    delay(1000);
    }
      myservo.write(90);
      delay(1000);                   
  }


Arduino Code for Bird

#include <Servo.h&gt;
Servo mouth;
void setup() {
  mouth.attach(9);
  // put your setup code here, to run once:
 pinMode(2,INPUT);
 Serial.begin(9600);
}

void loop() {
  Serial.println(digitalRead(2));
  while (digitalRead(2) != 1){
    delay(1200);
    mouth.write(80);
    delay(500);
    mouth.write(0);
    
    }
  
}