what input pin is it using?

ok so basically leave it there but take the internals out of it.

would this work or am i barking up the wrong tree?

volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;
int rpm1 =1;


void setup() {
  Serial.begin(9600);  
 pinMode(INPUT, rpm1);
}
void loop(){
  
   if(rpm1>=5) {
      rpm=(60000*rpmcount)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      //Serial.println(rpmcount,DEC);
      rpmcount = 0;
      Serial.println(rpm,DEC);
   }
}

"i will eventually need 3 hall inputs so how will i overcome that?"

You can have an interrupt on any pin, they are called PCINT.
See NickGammon's writeup on them here

You can keep the blinking led.
Move the blink part outside of the ISR. Set up a global byte variable and make it volatile to use as a blink flag, maybe call it bFlag. When the ISR runs, set that to 1 in the ISR. Then in loop() set up an if ( bFlag ) { } that makes the led blink and sets bFlag = 0.

So your ISR increments rpm count and flags the blink, it runs in next to nothing flat and is ready to service the next interrupt that fast.

IIRC you can set up any I/O pin to interrupt on Level Change. But look into things, maybe you don't need to use interrupts at all. Most things don't at 16 MHz.

You'd do better to learn how to use timers to run multiple tasks without using blocking code.
This is Nick Gammon's site, he's a master at explanations.

Joes:
would this work or am i barking up the wrong tree?

Wrong tree entirely. You have completely removed the interrupt handler now.

In your original sketch, this interrupt handler was called when you got a falling edge on pin 2:

void rpm_fun()
 {
      rpmcount++;
      digitalWrite(ledPin, HIGH);
      delay(50);
      digitalWrite(ledPin, LOW);
 }

These are the lines of code that turn ledPin HIGH, wait 50 milliseconds and then turn it LOW again:

      digitalWrite(ledPin, HIGH);
      delay(50);
      digitalWrite(ledPin, LOW);

If you take those three lines out it will no longer flash the LED and will no longer have that unwise delay() in the interrupt handler.

hi thanks for your replies on that link Gammon Forum : Electronics : Microprocessors : Interrupts there is a lot of stuff on that website to get your head wrapped around lol i have come up with this compiles fine but somethings telling me im missing something here?

volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
 {
 // handle pin change interrupt for D0 to D7 here
 }  // end of PCINT2_vect


void setup ()
  { 
  Serial.begin(9600);  
  // pin change interrupt (example for D0)
  PCMSK2 |= _BV (PCINT16);  // want pin 0
  PCIFR  |= _BV (PCIF2);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);   // enable pin change interrupts for D0 to D7
  }

void loop(){
  
   if(rpmcount>=5) {
      rpm=(60000*rpmcount)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      //Serial.println(rpmcount,DEC);
      rpmcount = 0;
      Serial.println(rpm,DEC);
   }
}

p.s i dont wont the led output

Joes:
somethings telling me im missing something here?

How about something to update rpmcount ?

volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
 {
   rpmcount;
 // handle pin change interrupt for D0 to D7 here
 }  // end of PCINT2_vect


void setup ()
  { 
  Serial.begin(9600);  
  // pin change interrupt (example for D0)
  PCMSK2 |= _BV (PCINT16);  // want pin 0
  PCIFR  |= _BV (PCIF2);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);   // enable pin change interrupts for D0 to D7
  }

void loop(){
  
   if(rpmcount>=5) {
      rpm=(60000*rpmcount)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      //Serial.println(rpmcount,DEC);
      rpmcount = 0;
      Serial.println(rpm,DEC);
   }
}

better?

better?

No try:-

rpmcount++;

You started with a sketch that did more or less what you wanted, in a fairly simple way - no messing with hardware registers and so on.

Why have you thrown that away and started again with a more complex approach?

o yes of course

here i am now with the 3x hall input's

volatile int rpm1count;
volatile int rpm2count;
volatile int rpm3count;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
 {
   rpm1count++;
   rpm2count++;
   rpm3count++; 
 // handle pin change interrupt for D0 to D7 here
 }  // end of PCINT2_vect


void setup ()
  { 
  Serial.begin(9600);  
  // pin change interrupt (example for D0,1,2)
  PCMSK2 |= _BV (PCINT16);  // want pin 0
  PCMSK2 |= _BV (PCINT17);  // want pin 1
  PCMSK2 |= _BV (PCINT18);  // want pin 2  
  PCIFR  |= _BV (PCIF2);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);   // enable pin change interrupts for D0 to D7
  }

void loop(){
  
   if(rpm1count>=5) {
      rpm=(60000*rpm1count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm1count = 0;
      Serial.println("rear left");
      Serial.println(rpm,DEC);
   }
   
      if(rpm2count>=5) {
      rpm=(60000*rpm2count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm2count = 0;
      Serial.println("rear write");
      Serial.println(rpm,DEC);
   }
   
      if(rpm3count>=5) {
      rpm=(60000*rpm3count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm3count = 0;
      Serial.println("rear prob");
      Serial.println(rpm,DEC);
   }
}

You started with a sketch that did more or less what you wanted, in a fairly simple way - no messing with hardware registers and so on.

Why have you thrown that away and started again with a more complex approach?

for a start i need 3 hall inputs as stated above but on the original code i could only run 2

So you have three sensors and you increment all three counters when any one goes off!!!

You don't use the pin change interrupt like that anyway.

So you have three sensors and you increment all three counters when any one goes off!!!

You don't use the pin change interrupt like that anyway.

ok could you show me a beter way of doing it?

Just check the pins with a port read at the start of loop() and don't fart around with delays or other blocking code. A fast loop() can read and evaluate, and report/store data for 3 pins many times per millisecond. Is > 1000 checks per second fast enough?

i could do it in a port read like you said but this will be linking up with some other code i already have, there is no delays in it will it still be fine as this might be seeing some high rpm's?

ok could you show me a beter way of doing it?

Better than "totally wrong and will not work at all", is easy.

This project:-
http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html
Uses the pin change interrupt to monitor 6 pulse inputs. Maybe looking at that code would help you.

now im more confused looking at that lol any one got a simple example thay can post?

New to forum, check your private messages... look upper right under the Search box.

yes and i do not have any new messages?

OOOOPS! Sorry, wrong thread!

How many reads/second will the high rpm's require? Assuming 1 magnet on a shaft at 10000 rpm I get ~167 reads/second giving 6 milliseconds per cycle though the sensor will be high for a much shorter time.
An Arduino running spare code can make digital reads with minor processing in under 5 microseconds. I have sensor code that does a digital read, unsigned long increment and unsigned long compare ( if statement ) is just over 1 usec per while loop. I give an extra 60 cycles for 5 usecs.

The code you showed in the first post has no foot-dragging parts and uses millis for timing.

You know that if you pass a magnet under a coil that the speed of the magnet will affect how much power is induced in the coil? So maybe you don't have to count rpms.

well my hall sensor is going to be an abs sensor on a car so theres quite a few triggers per revolution havent counted exactly but were looking at about 60, and the revolutions will depend on how fast the car is. so what do you think?