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
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.
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);
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()