Hello All;
I am having some difficulty with a latching, dual coil relay. I will be using this relay to turn on a gas heater. In the future, this logic will be incorporated into my thermostat control project, but for now I am only doing a proof of concept with the relay, using a push button for the control. The relay is question is a Eletechsup LR12A01 Pro. There are four pins on the control side (VCC, GND, RESET, SET) and three on the output (NO, COM, NC). Here is a picture:
Here is a link to their product page, including a downloadable datasheet: LR12A01 DC 5V Magnetic Latching Relay Module
I have this connected to an ESP32-C3 Super Mini dev board. I also have a single push button which will pull a pin to ground on activation. My problem appears to be that whenever I have both the SET and RESET pins connected to pins on the ESP32, they are locked in a fight with one another. It's as if they are both attempting to SET or RESET the relay at the same time.
However, I can manually SET and RESET the relay by grounding the pins one at a time. When I do this I can hear the relay click, so I know it's working. To be more accurate, I can touch the pin of the one not last "clicked" with either GND or VCC to hear the relay click again. I suppose those pins are just looking for a change in the voltage, but I am not sure.
I scraped together a very basic sketch that I derived from others in the forums (and greater Interwebs). I have tried every combination of pulling the pins HIGH and/or LOW to trigger the relay, during both the initial void Setup() routine and my button's click event but have had no success. I should point out that occasionally the button click event does not register (i.e. I can see the Serial output had not updated). I think may have something to do with the SET/RESET fight I mentioned earlier, but perhaps not.
Could someone please look at the code below and tell me if I am making an obvious mistake?
//SAMPLE CODE FOR ESP32 C3 SUPER MINI
#include <OneButton.h> // This button library includes a deBounce function
#define LED_BUILTIN 8 // Internal LED
const int LEFT_BTN_PIN = 0; // SET Button pin
const int RELAY_PIN_SET = 6; // SET control for relay
const int RELAY_PIN_RES = 7; // RESET control for relay
bool rly_state = 1;
OneButton buttonLeft(LEFT_BTN_PIN, true);
void setup()
{
Serial.begin(115200);
while(!Serial){;}
buttonLeft.attachClick(clickLeft); // This attaches the click event to the OneButton control
pinMode(LED_BUILTIN, OUTPUT); // This is the ESP32's LED
pinMode(RELAY_PIN_RES, OUTPUT); // This is the relay's RESET pin
pinMode(RELAY_PIN_SET, OUTPUT); // This is the relay's SET pin
digitalWrite(LED_BUILTIN, HIGH); // LOW = ON; HIGH = OFF (with the ESP32-C3)
digitalWrite(RELAY_PIN_SET, HIGH); // Start with the relay in a known state
delay(1000);
digitalWrite(RELAY_PIN_RES, LOW); //
delay(200); // Pulse the RESET pin HIGH then LOW to put into RESET state (N.O. is open)
digitalWrite(RELAY_PIN_RES, HIGH); //
}
void loop()
{
buttonLeft.tick();
delay(50);
}
void clickLeft()
{
if (rly_state) // if the relay should be latched to the SET state
{
digitalWrite(RELAY_PIN_SET, LOW); // Set the SET pin HIGH
delay(200); // Hold the pin HIGH long enough to latch
digitalWrite(RELAY_PIN_SET, HIGH); // Set the SET pin LOW
digitalWrite(LED_BUILTIN, HIGH);
}
else // if the relay should be RESET
{
digitalWrite(RELAY_PIN_RES, LOW); // Set the RESET pin HIGH
delay(200); // Hold the pin HIGH long enough to latch
digitalWrite(RELAY_PIN_RES, HIGH); // Set the RESET pin LOW
digitalWrite(LED_BUILTIN, LOW);
}
Serial.println("State = " + String(rly_state));
rly_state = !rly_state; // toggle the relay state
}