Calculation for heart beat sensor values

I’ve made a project based on heart beat sensor including the Audrino, the problem is I’m not getting the correct values of the heart rate, some times it’s going more than thousands, and some times it gives value even if the finger is not placed, can u please help me in getting the calculation of the raw values.