2 pulses in 1 pulse out

I am doing an experiment with my e bike. Normally the magnet in the wheel activates a reed contact giving 1 pulse to the speed regulator resulting i a max. speed op 25kmh. I am looking for the code for Arduino when there are 2 pulses in and then 1 pulse out ( every 2 nd pulse in results in 1 pulse out). Who can give me the code?

What experience do you have in hardware and software ?

We can help you write the sketch.

Show us a schematic and the sketch you have written so far.

Before there were Arduinos, there were flip-flops.


The devil made me do it:



Hello Larry,

I do not have much experience. The sketch looks like this.

I just thought i could do this with Arduino. If i have the code i think i will get it to work.
I also think it must be quite a simple thing to built it with a board and components

Kindest regards,


I do need a way to built this:

With Arduino or just with components.

Kindest regards,

Sorry Larry, I do not understand…is this serious or humor?


This will divide the input pulse freqency by 2.

const byte inPin = 2;
const byte outPin = 4;

void setup()
   pinMode(outPin, OUTPUT);

void loop()

void checkPulse()
   static bool lastInState = LOW;
   static bool outState = LOW;
   bool inState = digitalRead(inPin);
   if (inState != lastInState)
      if (inState == LOW)
         outState = !outState;
         digitalWrite(outPin, outState);
      lastInState = inState;

Thankyou very much, you helped me a lot.
Kindest regards, Michael

@mikki01, your topic has been moved to a more suitable location on the forum.

If your problem is solved, you can tick the solution checkbook under the most useful reply. That way others that might have the same question know that a solution was provided.

  • Just count all input pulses (pulseCountIn)
  • Ă·2 output is just the status of bit 1 in pulseCountIn
  digitalWrite(pulseOutPin, pulseCountIn & 2);