Robotic hand project problem

Hello guys, so i made a 2DOF robotic hand using arduino, and i control the hand using 4x4 keypad , with ASK transmitter/reciever
the problem is, when i close the hand’s claw to hold something, using the “Claw_Close” function
the claw trying to close after it catches the item, and then the claw stuck and the whole project dont respond untill i reset the arduino, i think it happends cuz i try to close the claw to lets say 20 degree but the item makes the claw stop at 25 degree, so no respond…
any help with program please? i tryed everything

this is my all program:

#include <Servo.h> 
Servo servoHand; 
Servo servoClaw;
#define IN1 22
#define IN2 24
#define IN3 26
#define IN4 28
#define D8 30
#define D9 32
#define D10 34
#define D11 36
#define LED 41
#define ECHO 50
#define TRIG 51
volatile  int dig;
int duration,distance;
int val1=105,val2=85,val3=100;
boolean move_forw=false,key_flag=false;

 

void setup()
{
  Serial.begin(9600);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  pinMode(D8,INPUT);
  pinMode(D9,INPUT);
  pinMode(D10,INPUT);
  pinMode(D11,INPUT);
  pinMode(ECHO,INPUT);
  pinMode(TRIG,OUTPUT);
  pinMode(LED,OUTPUT);
  servoHand.attach(6);
  servoClaw.attach(7);
  digitalWrite(LED,1);
  servoHand.write(val1);
  servoClaw.write(val2);
  digitalWrite(TRIG,0);
  attachInterrupt(0, KB, RISING);
}

 

void loop ()
{
  if(key_flag==true)
  {
    execute(dig);
    key_flag=false;
  }
  if(move_forw)
  {
      if(check_dis())
      {
          STOP_move();
          digitalWrite(LED,0);
      }
      else
      digitalWrite(LED,1);
  }

 if(dig==3 || dig==7)
 {
  val3=val1-2;
      servoHand.write(val3);
      delay(3000);
 }

}
 

void KB()
{
  dig=digitalRead(D11)*8+digitalRead(D10)*4+digitalRead(D9)*2+digitalRead(D8);
  key_flag=true;
}
void execute(byte dig)
{
  switch(dig)
  {
    case 1:move_forward();
            break;
    case 4:move_left();
            break;   
    case 5:STOP_move();
            break;   
    case 6:move_right();
            break;  
    case 9:move_backward();
            break; 
    case 3:Hand_Up();
            break;
    case 7:Hand_Down();
            break;   
    case 11:Claw_Open();
            break;   
    case 15:Claw_Close();
            break;  
    default: break;    
  }
}
 

void move_forward ()
{
  digitalWrite(IN1,1);
  digitalWrite(IN2,0);
  digitalWrite(IN3,1);
  digitalWrite(IN4,0);
  move_forw=true;
}
void move_backward ()
{
  digitalWrite(IN1,0);
  digitalWrite(IN2,1);
  digitalWrite(IN3,0);
  digitalWrite(IN4,1);
  move_forw=false;
}
void move_left ()
{
  digitalWrite(IN1,0);
  digitalWrite(IN2,1);
  digitalWrite(IN3,1);
  digitalWrite(IN4,0);
  move_forw=false;
}
void move_right ()
{
  digitalWrite(IN1,1);
  digitalWrite(IN2,0);
  digitalWrite(IN3,0);
  digitalWrite(IN4,1);
  move_forw=false;
}

void STOP_move ()
{
  digitalWrite(IN1,0);
  digitalWrite(IN2,0);
  digitalWrite(IN3,0);
  digitalWrite(IN4,0); 
  move_forw=false;
}

void Hand_Up()
{
  do
  {  
    val1+=2;
    if(val1>120)
    val1=120;
    servoHand.write(val1);
    delay(80);
  }while(dig==3);
}

void Hand_Down()
{
  do
  {   
    val1-=2;
    if(val1<20)
    val1=20;
    servoHand.write(val1);
    delay(80);
  }while(dig==7);
}


void Claw_Open()
{
  do
  { 
    val2-=2;
    if(val2<85)
    val2=85;
    servoClaw.write(val2);
    delay(110);
  }while(dig==11);
}
void Claw_Close()
{
  while(dig==15)
  {   
    val2+=1;
    if(val2>115)
    val2=115;
    servoClaw.write(val2);
    delay(160);
  }
}















boolean check_dis()
{
  digitalWrite(TRIG,0);
  digitalWrite(TRIG,1);
  delayMicroseconds(10); 
  digitalWrite(TRIG,0);
  duration=pulseIn(ECHO,HIGH);
  distance=duration/56;
  if(distance<5)
  return true;
  else
  return false; 
}

and you can see the robot picture in attachment,
when i try to hold something with the claw, the program dont respond…
please give me anything T,T

sketch_apr11a.ino (3.13 KB)

If you get in the Claw_Close there is a loop there based on dig. Have you checked to see if it is stuck there in that loop? Have you checked to see what you are getting from those reads in KB (8,9,10,11)?

it is stuck on the loop i think because the claw trying to get to a angle of lets say ~100 but when it hold an item, it wont let it close lower then 105 degrees so it stuck on the loop and wont respond to anything else,,

The servo library doesn't care about the reaction of a servo. It may react strange on values outside the parameter range.

Like every DC motor, a servo can draw much current when blocked. This may cause a problem when the controller and servo are powered from the same supply.

by controller u mean the arduino or the transmitter? the transmitter is in another supply source, its sending the other values perfectly do you think if the arduino has is own supply source its gonna work?

The Arduino (contoller) deserves a stable operating voltage (Vcc), which should not be affected by any other components which draw possibly high currents from their supply. I.e. never connect servos to Vcc!

When you already use a power supply of at least 7V, to power servos or other components, you can use it to power the Arduino as well, because then the on-board voltage regulator will stabilize the Arduino Vcc.