Arduino read pulse inputs

Hello. I have a simple question: I need arduino to read pulses in a period of time: example:

  • if 1 pulse in 3 second period: turn on the red LED
  • if 2 pulses in 3 second period: turn on the blue LED
    What would be the best way to do this.

What is producing the pulses?

What is the duration (in microseconds) of a single pulse?

...R

Start a timer with millis()
Run pulseIn() to capture pulses, and count them.
Use millis() to monitor time going by.
After 3 seconds, make your LED decision based on the count.

Using non blocking code, monitor your 0v to 5v pulse which goes to an Arduino input pin.

When the pin goes HIGH (or LOW) increment a counter then start a 3 second timer.

Continue to increment the counter each time a pulse occurs.

When the 3 second timer expires, look at the counter, control your LEDs, Reset the counter.

Repeat as needed.

Robin2:
What is producing the pulses?

What is the duration (in microseconds) of a single pulse?

…R

Let’s say 500 milliseconds each pulse from low to high. Example the blinker of your car. When you lock the car it blinks 1 time, when you unlock the car it blinks 2 times in 3 second period. I need arduino to distinguish between locking or unlocking the car by the amount of blinks in a period of time

CrossRoads:
Start a timer with millis()
Run pulseIn() to capture pulses, and count them.
Use millis() to monitor time going by.
After 3 seconds, make your LED decision based on the count.

Thanks

You will need to convert the car signal from 12v to 5v, probably an opto isolator of sorts.

The software solutions/ideas above should be a good start for you to follow.

Finalize your schematic and show it to us.

Write some code, we can help when you run into problems.

larryd:
You will need to convert the car signal from 12v to 5v, probably an opto isolator of sorts.

The software solutions/ideas above should be a good start for you to follow.

Finalize your schematic and show it to us.

Write some code, we can help when you run into problems.

Yes the +12v input signals will be converted with 2 resistors 100k and 22k as voltage divider and a NPN transistor to a 0v signal or LOW signal so I must use INPUT_PULLUP on the pinMode()

As for the

pulseIn(pin, value, timeout)

function that only returns the length of the pulse in microseconds

Hold on a minute, what is this NPN for? That is not in the usual voltage divider circuit. Please provide a schematic. It sounds like two kinds of solutions got thrown together into one. It doesn't sound right, or at least optimum.

arm575:
Let's say 500 milliseconds each pulse from low to high.

That is very slow by Arduino standards so should be easy to detect with digitalRead()s in loop()

...R