Of course Paul, the Shelly domotics cloud free service in the app is always active
How does your current system work with one wire, and how will Arduino make this one wire do what you want?
I would really like to show you the schematic diagram but I don't know how to post it.
- Take a photo.
- Click reply to start a post.
- Click the icon with the arrow pointing up.
- find and select the photo
- click reply to upload and finish the post.
Finally The drawing posted. Now from what I can realize, no one has posted the codes. I have never programmed so I would appreciate if someone can do this for me. Later on I will try to go on my own. I will repeat the sequence for the schematic: the keyboard generates a one shot dry contact when the combination is ok. The dry impulse goes to the input of the Arduino and from then the output for relay 1 goes up for 1 second and then goes off (one shot) at the same time a timer counts 10 seconds in these 10 seconds, if I make the keyboard combinate again, the same dry impulse goes up again and the Arduino this time activates relay 2 for 1 second. If I only go for the relay 1 and the 10 seconds expire, relay 2 cannot be activated and the logic can start all over. Having only 2 wires for the input of the Arduino, this is my best bet.
I think I understand...
- keypad entry combination talks to alarm system
- alarm system verifies combination
- alarm system sends "ok" to keypad
- keypad changes "one shot" level (0v to 5v or 5v to 0v)
- Arduino digital input senses "ok" level change and increments "okcount++"
- if "okcount == 1" then enable-relay-1 becomes ON for one second then OFF
- start ten-seconds timer...
(this is where I am lost... will the alarm system listening to the keypad for a good combination send another "ok"?)
- assuming alarm system sends another "ok" to keypad which changes "one shot" level again...
- increment "okcount++" to 2
- if "okcount == 2" energize relay2 ON for 1 second, (and assumed) OFF AND reset "okcount" to zero.
Am I close? Please make corrections.
I am calling a classic programmer here to peek at my (ill) logic ... @alto777 ... unless "she" has called summoned him to festivals in Ko:ln.
Below is a photo of the keyboard. Unfortunately there are only keyboards with one contact relay, that's the reason I need to install the Arduino logic that I'm searching for.
You're close but not that complicated. The alarm system does not exchange information with the keypad, the alarm system only wants one shot in input zone 1 to activate it and another one shot to disactivate it. Same thing for zone 2.
I am still uncertain of the flow. The Arduino needs some notification. What is that notification? What is the source (sender of the one shot)? From there we can work forward (toward the relays) and backward (toward the signal generation).
The relay inside of the keypad closes it's normally open dry contact for 1 second when you digit the right 4 number combination
Just the same as a button when it's pushed and released
Okay... this sounds like the system closes the relay for one second... and I am guessing the system does the ten-seconds timeout, waits for another combo, and initiates the second command/level/"ok"? Would you write the sequence of events in a list, similar to post #29? And what is the ground-referenced level coming out of the keypad?
It's interesting how a simple specification can give rise to many interpretations, and leave details underspecified.
I fed @mauror58's word salad, which wasn't too bad, to chatGPT just to see, and after a few backs-and-forths we decided
- Going HIGH pulses a relay
- next HIGH, if within 10 seconds, pulses the other
- if 10 seconds goes by, start next with relay1
I don't usually just dump a solution on these fora, but since this is still a mystery (to me) I wrote the below, which I think may be the simplest way to do what I hope is the task:
# define PRESSED LOW // Change to HIGH if button drives HIGH when pressed
# define ON HIGH // Change to LOW if relay module is active-LOW
# define OFF LOW // Change to HIGH if
const byte inputPin = 2; // Input signal pin
const byte relayPin[2] = {8, 9};
const unsigned long WINDOW = 4000UL; // 4 seconds: life is short! 10-second recovery window
const unsigned long PULSE = 777; // relay pulse duration
bool lastInput;
void setup() {
Serial.begin(115200);
pinMode(inputPin, INPUT_PULLUP);
for (byte ii = 0; ii < 2; ii++) {
pinMode(relayPin[ii], OUTPUT);
digitalWrite(relayPin[ii], OFF);
}
lastInput = digitalRead(inputPin) == PRESSED;
}
byte nextRelay = 0; // 0 means relay1 next, 1 for relay2
unsigned long windowTimer = 0;
unsigned long pulseTimer;
void loop()
{
unsigned long now = millis();
bool inputNow = digitalRead(inputPin) == PRESSED;
bool risingEdge = (inputNow && !lastInput);
bool fallingEdge = (!inputNow && lastInput);
lastInput = inputNow;
if (risingEdge) {
digitalWrite(relayPin[nextRelay], ON);
pulseTimer = now;
}
if (inputNow) windowTimer = now;
if (now - windowTimer >= WINDOW)
nextRelay = 0; // reset to use relay1 first
if (now - pulseTimer > PULSE) {
digitalWrite(relayPin[0], OFF);
digitalWrite(relayPin[1], OFF);
}
if (fallingEdge)
nextRelay = 1 - nextRelay; // switch to the other relay
delay(20); // poor man's debounce
}
It does not block. It uses edge detection as well as the button state. Debouncing is done with a loop throttle at ~50 Hz.
a7
I'll answer the last question first: the ground reference of the key pad (the ground of the 12 vdc) is isolated from the contact of it's internal relay therefore the 2 wires coming out of the internal relay can be connected directly to the input of the arduino with any polarity you wish (it can send 5 volts to the keypad and return 5 volts to the arduino for example). Here's the sequence of events:
- input goes high for 1 second
- output for relay 1 goes high for 1 second
- timer starts to count 10 seconds
- if input within 10 seconds goes high again, output for relay 2 goes high for 1 second
- if 10 seconds expire before the second time of input going high, it will only put in high the relay 1 output and the sequence restarts from the begining
Hey, it looks like we're going close to the solution so I'll try it with the emulator. Unless you did it yourself?
Yes, I tested this. I'll let you notice a feature that just happened into to behaviour of this sketch.
I'm not alla way to Koh Larn, but I am no longer in the lab, so… for wiring:
-
A pushbutton wired between ground and pin 2 for simulating the input (active LOW).
-
Two LEDs,each with a series current-limiting resistor, one set between pin 8 and ground, the other between pin 9 and ground, to observe the relay signals.
The poor man's debounce could be replaced with a millis()-based throttle, and you would recover 99 percent of the processor resources and have a free running loop where you could add functionality.
a7
Ok, no hurry...take your time.
Thanks


