5v high input to store rpm

i am trying to get rpm from a 5v high hall input
1 pulse per revolution. max 4500 revs
i am thinking about reading the pulses (or pulse) in a small amount of time and then multiply that up to a minute scale.

my math in there seems to be going backwards on the counting. lol
need to get rid of the timeout i think

int pin = 2;
unsigned long duration;
unsigned long RPM;

void setup() {
  Serial.begin(9600);
  pinMode(pin, INPUT);
}

void loop() {
  duration = pulseIn(pin, HIGH);
  RPM = duration / 1000;
  Serial.print(RPM);
  Serial.println(" RPM");
}

then i would like to use the rpm data and have it add some output values

  if (RPM>= 1000) pulse_time+=5;         
  else if (RPM>= 2000) pulse_time+=10;         
 else if (RPM>= 3000) pulse_time+=15;   
 else if (RPM>= 4000) pulse_time+=20;

Rather than use pulseIn() set up an interrupt to trigger every time there is a pulse. Have a look at this code that is derived from a project where I control the speed of a small DC motor.

const byte fwdPin = 9;
const byte revPin = 10;
const byte potPin = A1;

int potVal;
int pwmVal;

unsigned long revMicros;
unsigned long prevRevMicros;
unsigned long revDuration;
unsigned long revCount;

unsigned long prevDisplayMillis;
unsigned long  displayInterval = 1000;

    // variables for the ISR
volatile unsigned long isrMicros;
volatile unsigned long isrCount;
volatile bool newIsrMicros = false;



void setup() {
    Serial.begin(115200);
    Serial.println("SimpleISRdemo.ino");
    pinMode (fwdPin, OUTPUT);
    pinMode (revPin, OUTPUT);

    isrCount = 0;
    attachInterrupt(0, revDetectorISR, RISING);
}

//==========

void loop() {
    getIsrData();
    if (millis() - prevDisplayMillis >= displayInterval) {
        prevDisplayMillis += displayInterval;
        showData();
        readPot();
        updateMotorSpeed();
    }
}

//===========

 void readPot() {
    potVal = analogRead(potPin);
}

//===========

void updateMotorSpeed() {
    pwmVal = potVal >> 2;

    digitalWrite(revPin,LOW);
    analogWrite(fwdPin, pwmVal);
 }

//===========

void getIsrData() {
    if (newIsrMicros == true) {
        prevRevMicros = revMicros; // save the previous value
        noInterrupts();
            revMicros = isrMicros;
            revCount = isrCount;
            newIsrMicros = false;
        interrupts();
        revDuration = revMicros - prevRevMicros;
    }
}

//===========

void showData() {
    Serial.println();
    Serial.println("===============");
    Serial.print("PWM Val "); Serial.println(pwmVal);
    Serial.print("  Rev Duration ");
    Serial.print(revDuration);
    Serial.print("  Rev Count ");
    Serial.print(revCount);
    Serial.println();
}

//===========

void revDetectorISR() {
    isrMicros = micros();
    isrCount ++;
    newIsrMicros = true;

}

This assumes there is one pulse per revolution. It has worked for me up to about 18,000 RPM and I reckon it can work at even higher speeds.

...R

thanks for the reply
your code is very over whelming for me to look at. lol
i will try and see if i can make sense of it

is there any snow balls chance in hell that something any where near this would possibly function? lol
no conversions of speed but just raw input PWM

int Hall = 2;
int pulse_time; 
int injector = LED_BUILTIN; 

void setup() {
                                          
    Serial.begin(9600);                         
   pinMode(Hall, INPUT_PULLUP);
   pinMode(injector,   OUTPUT);

void loop() {

pulse_time=2;

hall speed = digital read ( hall sensor x time or some crap?)
  if (hall speed>= 120 millisecond ) pulse_time+=1;        // Add  more ms     (500 rpm)
  if (hall speed>= 60   millisecond ) pulse_time+=2;        // Add  more ms     (1000 rpm)
  if (hall speed>= 30   millisecond ) pulse_time+=3;        // Add  more ms     (2000 rpm
  if (hall speed>= 20   millisecond ) pulse_time+=4;        // Add  more ms     (3000 rpm)

digitalWrite(injector,HIGH);                    // Turn the injector on

  delay(pulse_time);                              // Squirt!!!!!!

  digitalWrite(injector,LOW);

lol, ok i got something working!

int Hall = 2;                    // Digital Input pin for rotation sensor, one pulse per revolution
int injector = LED_BUILTIN;     // Digital Output Pin for turning on the injector solenoid
int TPS = A0;                  // Analog Input Pin for the throttle
int fuel_pump = 11;           // PWM for fuel pressure
int TPS_voltage;             // The analogRead value 
int pulse_time;             // Duration of injector pulse
unsigned long duration;    // hall sensor speed input based on time HIGH
int hall_time;            // amount of time of hall sensor being HIGH

void setup() {
                                          
    Serial.begin(9600);                         
   pinMode(Hall, INPUT_PULLUP);
   pinMode(TPS,         INPUT);
   pinMode(injector,   OUTPUT);
   pinMode(fuel_pump,  OUTPUT);

   // Make sure that the injector is initially turned off
   digitalWrite(injector,LOW);

   // Wait for the RPM pulse to go low before starting the loop
   while (digitalRead(Hall)==HIGH){}     // Wait for LOW

}  // End of setup

void loop() {

  analogWrite(fuel_pump, 100);            // PWM output , adjust for static fuel pressure!!!!
   
  // Wait for the the RPM sensor to go HIGH
  while (digitalRead(Hall)==LOW) {}      // Do nothing until the sensor goes high

  //  Hall sensor pulse detected so read the analog throttle setting
  TPS_voltage=analogRead(TPS);
            
  duration = pulseIn(Hall, HIGH);
   hall_time  = duration / 1000;             //   
   
  pulse_time=2;         // idle ms
  
  if (TPS_voltage>= 50) pulse_time+=2;           // Add  more ms 
    if (TPS_voltage>= 200) pulse_time+=2;        // Add  more ms   
    if (TPS_voltage>= 300) pulse_time+=2;        // Add  more ms   
    if (TPS_voltage>= 400) pulse_time+=2;        // Add  more ms   
    if (TPS_voltage>= 500) pulse_time+=2;        // Add  more ms   
    if (TPS_voltage>= 600) pulse_time+=2;        // Add  more ms   
    if (TPS_voltage>= 700) pulse_time+=3;        // Add  more ms   
    if (TPS_voltage>= 800) pulse_time+=3;        // Add  more ms  
    if (TPS_voltage>= 900) pulse_time+=4;        // Add  more ms   

     
  if (hall_time<= 120  ) pulse_time+=1;        // Add  more ms     (500 rpm)
  if (hall_time<= 80   ) pulse_time+=1;        // Add  more ms     (750 rpm)
  if (hall_time<= 60   ) pulse_time+=2;        // Add  more ms     (1000 rpm)
  if (hall_time<= 30   ) pulse_time+=3;        // Add  more ms     (2000 rpm
  if (hall_time<= 20   ) pulse_time+=4;        // Add  more ms     (3000 rpm)
  if (hall_time<= 15   ) pulse_time+=5;        // Add  more ms     (4000 rpm)

  //  Display pulse_time
  Serial.print(pulse_time);
  Serial.println("   Milli squirt");
  
  Serial.print(TPS_voltage);
  Serial.println(" TPS");

  Serial.print(hall_time);
  Serial.println("  hall time");

  Serial.println();        // space

  //  Turn the injector on, wait pulse_time milliseconds, turn the injector off
  digitalWrite(injector,HIGH);                    // Turn the injector on

  delay(pulse_time);                              // Squirt!!!!!!

  digitalWrite(injector,LOW);                     // Turn the injector off

   // Wait for the RPM pulse to go low before re-starting the loop
   while (digitalRead(Hall)==HIGH){}              // Wait for LOW
 
}  // End of loop()