Pedal Cadence (RPM) using Hall Effect sensors - Need some fresh eyes!

Hello all,

I am trying to obtain the RPM of the crank arms on a bicycle.
I have set it up on a stationary bicycle with two hall effect sensors in different positions on the rotation.
The idea is to use the first hall effect sensor (HE01) to measure the cadence and the second sensor (HE02) to confirm the sensors have been triggered.
The RPM is not being calculated properly and I cant not figure out why...
Anyone with any suggestions or critique would be greatly appreciated.

Thanks for taking the time to look at my problem.

If you need anymore information please let me know.

int RPM;
long newCtime = 0;
long newLastCt = 0;
long Ctime = 1000; // give this an initial value so that you can calculate debounceDelay
long lastCt = 0;
int HE01 = A0; // this is the analog pin
int HE02 = A1; // this is the analog pin
const int trigNum=840;
const int trigNum2=520;
boolean HE01trig = false;

void setup() {

  Serial.begin(9600);

}

void loop() {
  // collect sensor data
  int HE01val = analogRead(HE01); 
  int HE02val = analogRead(HE02); 

  // model data

  if(HE01val > trigNum) {
    newCtime = millis() - lastCt;
    newLastCt = millis();
    HE01trig = true;

  }

  if(HE01trig == true){
    if(HE02val > trigNum2){
      Ctime = newCtime;
      lastCt = newLastCt;
      RPM = 60000/Ctime;
      HE01trig = false;
    }
  }

  if(newCtime > Ctime){
    Ctime = newCtime;
    RPM = 60000/Ctime;
  }

  // update display

  Serial.print("Cadence = "); 
  Serial.println(RPM);

}

Roughly what frequency are you expecting? An analogRead takes around 104 µS.

Not fast.

Would like it updates every 250-500ms at least. A high RPM in this will be around 130-140.

The RPM is not being calculated properly and I cant not figure out why...

What values are you getting? What are you expecting? "My code doesn't work" is nowhere near as good as "My code does XXX, but I expect it to do YYY".

You have way too many time-related values. All you need is this time and last time. Names like thisTime and lastTime would be good.

Why are you counting anything? You never actually use the count(s).