puls

How can I make an output pulse for every 6 pulses in with arduino. I have 6 pulses per revolution which is coming from an rpm sensor which meassure rpm upto 2000rpm; So max 200 pulses per second and I need to generate one pulse per revolution for a stroboscope lamp so this can match the speed of my motor. Any suggestion?

You could count the incoming pulses and send a pulse to the strobe when the count gets to 6

Something like this:

  int count=0;
  while(count < 6){
      while(digitalRead(inputPin) == HIGH) 
            ; // wait for the pin to go high
      while(digitalRead(inputPin) == LOW)        
           ; // wait for the pin to go low
       count++ ;    
  }
  digitalWrite(outputPin); 
  count=0;

Here is the code I have written so far, will test it this week.. I added some question inside the code:

/*
 * RPM read sensor
 * 16 pulses per revolution
 */
 
int ledPin = 13;                // choose the pin for the pulse out
int inputPin = 2;               // choose the input pin (for the input puls)
int count = 0;                  // counter for the 6 pulses
long previousMillis = 0;        // will store last time pulse out was updated
long deltaT = 0;                // the time between pulses out
double rpm = 0;                 // the speed

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare pushbutton as input
  Serial.println("RPM Sensor initiated");

}

void loop(){
  
  previousMillis = millis();   
  while(count < 6){
      while(digitalRead(inputPin) == HIGH)
            ; // wait for the pin to go high
      while(digitalRead(inputPin) == LOW)        
           ; // wait for the pin to go low
       count++ ;  
         if(count==3){
           digitalWrite(ledPin, LOW);  // turn LED OFF
         }
           
  }
  
  deltaT = millis() - previousMillis;
  digitalWrite(ledPin, HIGH); // turn LED ON
  rpm = 60000/deltaT;
  Serial.println(int(rpm));  // Why cant this handle double ??????
  count=0; 
  
  
  // Does these instructions take so long time that we might miss the next pulse ???
}

The serial library doesn't support floating point. Will your measurement be accurate to a fraction of an RPM? And even if it was, do you really care? If you do, you there is example code for printing double value here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207226548/13#13

I don't think it matters if you miss a pulse while doing the stuff at the bottom of your loop. The RPMs are unlikely to be changing so quickly that the result will change if you delay a millisecond or two between measurements. What is it you are measuring?

Good luck

No, I was just curious why it didnæt support double... it doesnt really matter if I miss a pulse or two, so I think the code is just fine the way it is. I will make the rpm int instead and then try it out!!!

Thanks for the reply...

Adding support for floating point in the print class used by Serial would result in bloating every sketch with floating point support even if the sketch didn't use any floating point.

anyway, good luck with the rpm counter

Hmm, I couldn't get it to work, so I connect my GND or VCC through a switch to pin Digital pin 2 on my arduino? If I then press my switch 6 times it should turn the led on arduino board untill I have clicked 3 more times.

Do I need to enable iternal pull op or something? For some reason I can't get it to work.

so I connect my GND or VCC through a switch to pin Digital pin 2 on my arduino

yes connect the ground to this, not the Vcc.

Do I need to enable iternal pull op or something

Yes with a digitalWrite(pin,HIGH) after you have defined the pin as an input
OR
wire up a real resistor (between 1K and 10K) from the input to the Vcc