detect impuls button press

I have a impuls relais (Eltako) that I use to control my lights at home. I already have a working setup where I "simulate" a button press by using relais and an Arduino (relais not really needed, but I had them lying around).
This allows me to remotely activate my lights (I made small REST service for it).

Now I want to detect a physical press of a button but my arduino so I can register this press in my backend application (I'm using home-assistant).

But the voltages don't match and I'm not sure what I do best.. I think would need a voltage splitter, but no sure how to connect it..

Below is a schema of the current situation. (symbols are not 100% correct, but I think it's clear)

Use an optocoupler.

For AC, you can use a series capacitor (rated for that AC voltage) as the main current limiting device, together with a resistor to limit surge on first contact, and an AC optocoupler.

The output transistor of the optocoupler connects between an Arduino input and ground, using a pinMode of INPUT_PULLUP. Note that the input will be chopped with the AC cycle so you need to poll it regularly and implement a smoothing function.

Thx for the info…

But I want to avoid working on the 240 AC voltage side (= lamp side).

Is it not possible to detect the press of the switch (at 24V DC side). In assumption that pressing the switch turns on the light (not 100% sure off-course, as the actual turning on is done by the impuls relais)

Then you would still use an optocoupler. Your drawing is a little misleading reflecting DC use with transformers as drawn. Anyway, to detect if 24 VDC is present or not an opto coupler as suggested is a good choice.

Ron

Yes sorry for the wrong symbol..

I guess I could use something like this then?

Hoi Cuball, welkom terug.

You've connected your relay parallel to the existing hardware switch that was already part of the original setup.
So now your Arduino or the switch can control the module, but they are unaware of each other's existence and/or controls.

How about connecting the original switch to your Arduino instead of the module's 24 volts ?
That way the Arduino always knows the state (i assume that's what you're after), and will be in full control of the module.
There are of course pros and cons to this, it's up to you to weigh those.

Link corrected (and also, it was a mobile link,not a proper one!): 5v to 24v 4 channel optocoupler isolation board isolated module plc signal level voltage converter board 4bit Sale - Banggood.com

That particular opto board is to use a 5 V (Arduino, DC) device to switch a 24 V DC input to some other system. That does not sound like what you actually wanted to do. :astonished:

MAS3:
How about connecting the original switch to your Arduino instead of the module's 24 volts ?
That way the Arduino always knows the state (i assume that's what you're after), and will be in full control of the module.
There are of course pros and cons to this, it's up to you to weigh those.

Yes, that's an option but I would prefer not to touch the current setup, so that my impuls relais is always the "master". I want to track the current state using the Arduino by capturing the button presses.

Paul__B:
That particular opto board is to use a 5 V (Arduino, DC) device to switch a 24 V DC input to some other system. That does not sound like what you actually wanted to do. :astonished:

No you are right, it's the opposite I want. Something like this then ?

Yes, that looks right.

Found the photo:


Note you are sensing the DC side of the apparatus.

Paul__B:
Note you are sensing the DC side of the apparatus.

Yes, I'll capture the physical button presses, connected to the 24V DC power. This will always work, even if the button press is very short ? There is no minimum duration for detection ?

The electronics on that PCB have no parts that are meant to create a delay, or do so as some side effect (there are no capacitors visible).
The delay that will occur (there will always be some delay) is too small to matter and you'd need some quite advanced equipment to measure that.

The delay inside your Arduino to see the pulse and handle it will be much, much larger.
And your coding will be the largest influence on that.
Polling the input pin often enough will help, and being smart about when you will actually register a pulse too.
Depending on the size and efficiency of your sketch, you might want to use certain pins with hardware to handle occasional and short pulses.
But it's most likely that you won't need such pins.
Mind that human fingers controlling the switch are extremely slow compared to the rest of the circuit.

Another tip:
You've been busy with this over the last 5 years, probably whenever you had some spare time so not 5 years non stop.
Did you ever try to find out how the module you have, registers the button presses ?
Does it switch immediately at pressing the switch, or does it switch upon release of that button ?
If it has some decent documentation, that should state when that happens.

I'd try to have your Arduino use the same way in handling the signal.

By the way:
How will you know the module's state upon the start of your Arduino ?

Thanks for the response.

Polling the input pin often enough will help, and being smart about when you will actually register a pulse too.

What exactly do you mean by being smart, I was thinking of using MQTT to send a message after pulse detection.

You've been busy with this over the last 5 years, probably whenever you had some spare time so not 5 years non stop.
Did you ever try to find out how the module you have, registers the button presses ?

Well, I haven't done much since then... The Arduino worked perfectly for the last years and I never had to look at it again. I can control the lights perfectly (Arduino is running a small webpage/REST service that I use to control the lights via my cellphone,laptop,device ...)
I just restarted since a week because I'm playing with home-assistant now. I can integrate my current setup by calling my Arduino as REST services, that works perfectly, without any modifications. It's just missing the extra touch of knowing the state of the everything and displaying it in the home-assistant front-end.

Does it switch immediately at pressing the switch, or does it switch upon release of that button ?
If it has some decent documentation, that should state when that happens.

It switches on the rising edge of the pulse, but there's a little catch. When I hold the signal high, it will start dimming the lights. This is however a nice to have to control, or something for in the future. Currently I simulate this by providing the "duration" of the pulse when I do a REST call to my Arduino.

How will you know the module's state upon the start of your Arduino ?

The idea is that the state is kept in home-assistant, so the Arduino will be stateless..

Cuball:
What exactly do you mean by being smart, I was thinking of using MQTT to send a message after pulse detection.

MQTT comes after detection.
But you want to prevent false detections, which can have multiple causes.
So be sure the button was pressed, and be sure you will not detect multiple presses when there was only a single long press.

I just restarted since a week because I'm playing with home-assistant now.
I can integrate my current setup by calling my Arduino as REST services, that works perfectly, without any modifications.
It's just missing the extra touch of knowing the state of the everything and displaying it in the home-assistant front-end.
It switches on the rising edge of the pulse, but there's a little catch.
When I hold the signal high, it will start dimming the lights.
This is however a nice to have to control, or something for in the future.
Currently I simulate this by providing the "duration" of the pulse when I do a REST call to my Arduino.

The idea is that the state is kept in home-assistant, so the Arduino will be stateless..

I'm sorry, but i don't understand that.
Do you want to assume (instead of measuring it) where you will start, and so also assume all next controls based on that first assumption ?

To me, knowing each and every keypress that has occurred since you started looking, doesn't tell you anything about which light will be turned on or off, and in case it'll be on, at which brightness level it will be.

The dimmer part is new, and adds another dimension to all of this.

But you want to prevent false detections, which can have multiple causes.
So be sure the button was pressed, and be sure you will not detect multiple presses when there was only a single long press.

Using pinMode (INPUT_PULLUP) should not make difference between a long press and short press I guess ?

I’m sorry, but i don’t understand that.
Do you want to assume (instead of measuring it) where you will start, and so also assume all next controls based on that first assumption ?

To me, knowing each and every keypress that has occurred since you started looking, doesn’t tell you anything about which light will be turned on or off, and in case it’ll be on, at which brightness level it will be.

You are correct, that’s a bit of a “flaw” in my solution… Measuring the input switches doesn’t guarantee that the state is kept in sync with the real state (for example a power failure or something, will not update the state).

I have 2 things to say about that :

  1. I’m OK with it, as we have a “all lights out” button. That’s a functionality built-in the impulse relais I use. So when I press this button, I will “reset” the state of all lights. That button is pressed quite often here at home (when leaving the house etc.). So after this button press, I know all lights are out for sure and can update state accordingly.
    Using this technique I try to minimize the chance of having a different state’s in my software compared to the real situation.

2)I monitor the output of my impuls relais, that way I know the exactly the state of the lights. I’m just a bit “reluctant” about this, as this is working on the 240V part of the circuit and connecting it to the arduino, while the other solution is just low voltage and no real risks…

I found this as possible solution for number 2 (with galvanic separation) : GitHub - edvler/ON_OFF_Detection_230V_24V_arduino: Detect if a power source is powerd on or off. It dosen't matter what power source it is. It could be a 230V AC or a 12V DC or a 24V DC. You only need a suitable signal light!!
But it’s a lot of work to implement… Wiring all those signal lights, photoresistors etc… I don’t think I want all that stuff in my switchboard.

The dimmer part is new, and adds another dimension to all of this.

Yes, but not all lights are dimmable… It’s difficult to program the dimming function… And as told before, currently a nice-to-have but not mandatory :slight_smile:

This is how it works (snippet from the manual)

Short-time control commands switch on/off, permanent control varies the brightness to the maximum level. An interruption of control changes the direction of dimming. The setting of the brightness level is stored after switching off. In case of a power failure the switching position and the brightness level are stored. If applicable the dimmer will be switched on at the stored brightness level after the supply voltage is recovered.

Cuball:
Using pinMode (INPUT_PULLUP) should not make difference between a long press and short press I guess ?

Indeed, it doesn't.
And if any, it will do better at differentiating multiple (extremely short) presses.
But the switches we use in our country to control the lights in our houses, weren't designed to accommodate such short presses, and neither is the human doing that.

But do you have a way to register the button being short pressed to turn the light on or off, or long pressed to dim the light that was already on, and will be on after that long press too ?
Or will your dimming action also make your ESP think the light is off ?

I'm OK with it, as we have a "all lights out" button. That's a functionality built-in the impulse relais I use. So when I press this button, I will "reset" the state of all lights. That button is pressed quite often here at home (when leaving the house etc.). So after this button press, I know all lights are out for sure and can update state accordingly.
Using this technique I try to minimize the chance of having a different state's in my software compared to the real situation.

OK, yet another dimension.
If you are monitoring that button too, you'll be able to reset and synchronise.

I monitor the output of my impuls relais, that way I know the exactly the state of the lights. I'm just a bit "reluctant" about this, as this is working on the 240V part of the circuit and connecting it to the arduino, while the other solution is just low voltage and no real risks...

I found this as possible solution for number 2 (with galvanic separation) : (link)
But it's a lot of work to implement.. Wiring all those signal lights, photoresistors etc... I don't think I want all that stuff in my switchboard.

That solution tries to see (with the LDR) whether the light is on or not.
A light that is not lit, doesn't necessarily mean the switch isn't on, your bulb may be defective too for instance.

It's difficult to program the dimming function..

I think this isn't something you need to implement right now, but i also think it wouldn't be too difficult to create that.

What would you recommend in this case ?

A) Monitoring the input (= detecting the button presses)
B) Monitoring the output ( = detecting if there's 240V going to the lamps)

It depends on what you want or need to do.
Monitoring can do more than what you're asking for above.
If you monitor the 230 volts to see whether the light is switched on, you can also see whether the bulb draws any current.
If it doesn't while the voltage is present, the bulb or the wiring is defective (open).
If it draws too much current (the breaker should switch off) you've got a short or a bulb about to blow (in about a second).

But you're planning to handle the dimmer controls somewhere in the future.
That means you need to look at the button presses (or analyse the 230 volt waveform).
You could figure out some way to determine how long a button has been pressed (it's not too complicated to do that), and to interpret that as an on/off signal, or as a dimmer control signal.

I don't want to (need to, or will) tell you what to do.
But i'd like you to think ahead and be aware of the pros and contras of any of the possible choices (which includes the risks of handling lethal voltages).
I stipulated some of the contras you might have missed yet.
It's up to you to figure out some way to handle them or, accept them.

Ok, I have enough information now, I'll order some components and experiment a bit :slight_smile:
Thx for the input!