Reading a pulsing input

Hi all

I have finally managed to break into my front gate controller which has an ‘Open Gate Indicator’ output. I have connected this output to the trigger side of a 24v relay and intend to connect the switched side of relay to connect a ground to an input pin on my Nodemcu (I believe I need to use one of the pins with internal pull-up).

The gate controller outputs 3 ‘pulse rates’
Opening = slow pulse (maybe every 500ms)
Open = high
Closing = fast pulse (maybe we’ve 200ms).

I would like to
A) drive Blynk LED to replicate gate controller output (ok with this just reading input pin high/low
B) Simple solution: create notification once only on first change in signal (from high to low, assuming I do indeed use pull-up).
C) slightly more complicated: in addition to a) a 2nd notification when input pin returns to high for say greater then 2 seconds
D) More complicated: create notifications for each of the 3 gate status (opening, open and closing).

Struggling a bit with options b) c) & d) and whether to use interval, interrupt, millis(), RTC or a combination of all the above.

To correctly notify I assume I need to be able to determine the pulse rate and then calculate whether it’s a slow or fast pulse. Calling a function with a timer feels problematic here as it may assume fast pulse if it is called towards the end of a pulse (if that make sense)

Would appreciate any thoughts/advice on which road to go down.

When you talk about “notifications” are you indeed talking about Blynk,push notifications, or do you mean a status indicator within the app?

I doubt very much whether a relay is the appropriate way to do this. They are slow, noises and not designed to be pulsed. A level shifter would be a better solution, but it depends on the voltages involved.

As far as detecting the pulses and decoding them, I’d probably use interrupts and millis comparison code to decode the statuses.


Thanks Pete

Probably both. I think I can relatively easily configure status indicator (led widget) in the app purely based on high/low.
But also want some level of push notification in case of an unexpected gate opening (think our dog has interrupted the photo sensors during closing manoeuvre , causing gates to re-open & she has escaped).

I’ll investigate interrupt & millis a bit more to figure out what this might look like.

As for use of relay, I believe gate controller is using a 24v pulsed dc output, and obviously needing to interface with the nodemcu. I have relay hooked up to gate controller already and sounds like it’s triggering as expected (but confirms your ‘noisy’ comment). Will see how I go by might looking into level shifter if there is one that will work with these voltages.



You should read about the restrictions for push notifications (frequency and numbers per 24 hour period) to ensure that they will meet your needs.

I meant this from an electrical point of view, not audio.

You should probaly use a transistor circuit to perform the switching rather than a relay or off the shelf logic level shifter.


The bit I think I’m going to struggle with is to limit the notification to only once per manoeuvre, as opposed to once every change in signal. I.e gate gets opened 4-5 times a day and each time there is 1 opening manoeuvre, 1 open manoeuvre, 1 closing manoeuvre and then 1 closed manoeuvre. So at a maximum would get 5 x 4 notifications per day.

Oh - my mistake. What are the ultimate consequences of using the relay? I.e is it going to interfere with the rest of my board working / not consistently pickup signals?

Is this the type of thing?!AUD!AU%20%247.12!AU%20%246.63!!!!!%402103222416595688491703727e3470!12000027136994076!btf&_t=pvid%3Aafcc01ac-40e3-42ce-b8f4-c5ddbd71c02a&afTraceInfo=1005003779011756__msite__c_ppc_item_bridge__xxxxxx__1659568849&spm=a2g0n.ppclist.product.0&gatewayAdapt=Pc2Msite

You should use a flag variable…

As I said originally, relays aren’t designed to be pulsed and generally don’t respond well when you do this.
When a relay is energised a solenoid system pulls the contacts closed. All physical switch contacts ‘bounce’ when they are made/broken, resulting in a random stream of rapid make/break events. This is electrical noise, and is particularly prevalent with mechanical relays.
You will struggle to differentiate between the electrical noise pulses, and the actual high/low pulses that you are attempting to decode.
In addition, your relay won’t perform consistently over time. Electrical noise tends to increase as the contacts become dirty, and the mechanical operation will vary as the internal solenoids wears, along with the return spring. So, what works now, with one particular relay, won’t work the same way in future or when the relay is replaced with a different one.

Maybe. Most of these level shifters are 5v to 3.3v but this one looks like it can tolerate 24v input, but it seems to want an output VCC of 12v. If it will work with a 5v output VCC then you’ll be fine.