conveyor belt controller wont keep working ?

hi . i am new at arduino and codding but inspite that i make a good project for me .
It is an easy conveyor belt controller project but i have some trouble with it .
here is the work flow .
First i enter a number for counter and it starts the motor , then a laser sensor count and stops the conveyor when product number equal to first number i enter .
then i want to restart the conveyor again only pressing " # " with the first number i entered .
If i want to change the number i will restart arduino .
please help me . this is my scratch ;

sorry for my english .

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Keypad.h>
byte motor = 4, laser_din = 2;
int sayac = 0, adet = 0;
const byte SATIR = 4;
const byte SUTUN = 3;
char tuslar[SATIR][SUTUN] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'},
};
byte rowPins[SATIR] = { 6, 7, 8, 9 };
byte colPins[SUTUN] = { 10, 11, 12 };
Keypad keypad = Keypad( makeKeymap(tuslar), rowPins, colPins, SATIR, SUTUN );
void setup() {
lcd.setBacklight(HIGH);
lcd.begin();
lcd.print("Adet Gir:");
pinMode(laser_din, INPUT);
pinMode(motor, OUTPUT);
}
void loop() 

{char tus = keypad.getKey(); 
if (tus)
{
lcd.print(tus);
adet = tus - 48;
}
if (digitalRead(laser_din) == 0) 
{
delay(20);
if (digitalRead(laser_din) == 1) 
{
lcd.clear();
sayac++;
lcd.print("Adet:");
lcd.println(sayac);
if (sayac == adet) 
{
digitalWrite(motor, HIGH);//Motor stop
lcd.println("Bitti");
sayac = 0;
adet = 0;
delay(5000);
lcd.clear();
lcd.print("Adet Giriniz:");
lcd.print(adet);
adet = 0;
sayac = 0;
}
}
}
if (tus == '*')
{
digitalWrite(motor, HIGH);//Durdur
lcd.print("Bitti:");
lcd.print(sayac);
adet = 0;
sayac = 0;
}
if (tus == '#')
{
digitalWrite(motor, LOW);//Başlat
lcd.print(sayac);
lcd.setCursor(0, 1);
lcd.print(tus);
}
}

To make it easier for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Also use the AutoFormat tool to indent your code for easier reading,

…R

      lcd.print("Adet:");
      lcd.println(sayac);

I don't know your native language but I can see you're printing one variable with a label belonging to another one. Always make the labels match the internal names of the variables.

When you get to the motor-stop state, you set adet and sayac to zero. So there's no memory of what adet was before. When you press # that information has been erased. You need one more variable to keep adetForRepeatAction (or some name that makes sense to you.)

hi. i translate my scratch to english . now i have another trouble with code . i dont know where i am wrong . when i enter a 2 digits number counter only count the second digit . example ; when i enter 29 it counts only 9 , if i enter 17 it stops on 7 ?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Keypad.h>//Keypad library added
byte relay = 4, laser_din = 2;
int counter = 0, piece = 0;
const byte ROW = 4;//4 row
const byte COLUMN = 3;//3 column
char keys[ROW][COLUMN] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'},
};//4X3 matris created
byte rowPins[ROW] = { 6, 7, 8, 9 }; //row digital pins
byte colPins[COLUMN] = { 10, 11, 12 };//column digital pins
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROW, COLUMN );//keymap created
void setup() {
lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it to LOW instead of HIGH
lcd.begin();
lcd.print("ENTER PIECE:");
pinMode(laser_din, INPUT);//laser sensor input
pinMode(relay, OUTPUT);//relay output
}
void loop() 

{char key = keypad.getKey(); //char read from keypad and sent to piece
if (key)
{
lcd.print(key);
piece = key - 48;//Char to int change
}
if (digitalRead(laser_din) == 0)
{
delay(20);//wait
if (digitalRead(laser_din) == 1)
{
lcd.clear();
counter++;//every piece crossed piece get one more
lcd.print("Piece:");
lcd.println(counter);//show counter on screen
if (counter == piece) //if counter equal to piece
{
digitalWrite(relay, HIGH);//relay stop
lcd.println("FINISH");//write finish
counter = 0;//reset counter
piece = 0;//reset piece
delay(5000);//wait 5 seconds
lcd.clear();
lcd.print("ENTER PIECE:");
lcd.print(piece);
piece = 0;
counter = 0;
}
}
}
if (key == '*')
{
digitalWrite(relay, HIGH);//stop
lcd.print("FINISH:");
lcd.print(counter);
piece = 0;
counter = 0;
}
if (key == '#')
{
digitalWrite(relay, LOW);//start
lcd.print(counter);
lcd.setCursor(0, 1);
lcd.print(key);
}
}

Hardly surprising, you overwrite piece every time you read a key. You need to accumulate what you’ve read in a zero terminated c string and then use atoi to calculate the number.

You need a string aka char array indeed, which holds the number you key in. Do something like:

char number[10]; // 9 digits + NULL
byte nDigits = 0;

loop() {
  char key = keypad.getKey(); //char read from keypad
  if (key && nDigits < 9) {
    number[nDigits] = key; // Store the key.
    nDigits++;  // Increase the counter to point to where the next is to be stored.
  }

  if (key == '#') { // start!
    number[nDigits] = '\0'; // Make sure it's NULL terminated.
    piece = atoi(number); // Convert string to int.
    nDigits = 0; // Reset the key counter.
  }
}

This allows you to enter a number of up to 9 digits long, then when pressing the # key you convert it into an int which is stored in variable piece.
Make sure you can not enter more than 9 digits - you must reserve one character for the terminating NULL.