Arduino code counting the encoder pulses dc motor

but it doesn't work.

Perhaps the problem is your assumption that 15000 somethings equals one second.

There are millis() and micros() functions that report elapsed time, so you don't have to guess how many iterations of loop() correspond to some amount of time.

You should have no trouble determining if the problem is the hardware or the software. If the number of pulses is increasing, at a reasonable rate, when the motor spins at a known speed, then the hardware (the encoder) iw working fine, and your means of counting is wrong. If the number of pulses is not increasing at a reasonable rate, when the motor spins at a known speed, then the encoder is not connected correctly.

What kind of encoder is it? Typically, an encoder requires two interrupt pins, so that you can also determine direction. If your motor only spins one direction, then getting the direction from the encoder isn't necessary.