Relay pulse count

I have 1 relay that high low ever time and i want to read that how many time its high through esp8266
In simple i want to read its count.

I also trying using interrupt pin after some time its count wrong for example relay low to high 1200 times but my esp8266 shows 1126 times

Pls give me some

  1. interrupt is wrong approach. A simple polling loop will do, unless there's a LOT else going on.
  2. You MUST debounce the contacts; that's quite likely why you're getting spurious counts.

Nothing further of note unless you show us your code and schematic. This might help:

I've flagged this for moving to Programming by a Moderator.

Never heard of using a relay for input, looking forward to your wiring diagram and code.

I am adding my code plz check

As usual, revealing the code exposes bigger problems.

    delay(200);

In the middle of an interrupt?
I presume that's your debounce, but it's entirely the wrong approach. To sit in there for 200 ms blocks everything else happening on your processor.
Instead, just set a flag for contact close, and do the debounce processing in loop().

Of course, the plethora of other delays in your code will prevent you from doing much else anyway.

When i remove 200ms delay interrupt call 4 5 times in 1 count

And that's because the contacts are bouncing, as expected. You need to defend against that, but not in the interrupt routine.
Basically, note when a change happens, and don't accept another change for a period of time - but not using delay().

The reason I'm not being more explicit as to how to do it in your code is because there is so much that needs renovating there, I don't know where to begin; I'm also not familiar with FireBase, so there's that.

This is a problem so how to prevent from bouncing

As I said,

millis() is your friend.

How often does your relay change state?

thnx i should try

Its change about 600ms but some time its change about 100ms

Then I must ask, how did you expect to see every change with a 200 ms delay in the interrupt?

Is an optocoupler help me to prevent from bouncing

Still missing that schematic. Without it, your question is meaningless, because I don't know what you have wired presently.

Ooooo :pensive_face: by mistake i wrote this

Schematic can be pencil lines on paper, take a photo. Communicating what is wired to what is what I want to see - and not in a word salad.

I will added schematic