Solenoid Lock doesn't work

Hello all,

I am trying to make my Solenoid lock work as I expect. The code is simple - it should unlocks and locks again. The issue I face is that when I start my 12V power source the lock just unlocks and stays like this all the time and looks like the relay can't control it.

Here is my code:

#define RELAY_PIN 14

void setup() {
  // initialize digital pin  as an output.
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
}

void loop() {
  digitalWrite(RELAY_PIN, HIGH); // unlock the door
  delay(5000);
  digitalWrite(RELAY_PIN, LOW);  // lock the door
  delay(5000);
}

Here is my wiring:

Can someone advice?

Disconnect the solenoid and see if the relay activates. Check NO-COM with an ohmmeter, you should see it make & break. If no, check input wiring, else recheck 12v power wiring. Does the solenoid kick when tested on 12V power directly?
Do you have a snubber/kickback diode across the coil of the solenoid? It's REQUIRED.
How is Arduino powered?

1 Like

Does the relay logic level fits to logic level of ESP32?

2 Likes

also if the relay deactivates when it should!

Put some serial prints in there to see it the loop is actually running - or getting "stuck" somewhere...

Sounds like the issue is just what @ paulpaulson said. ESP32 has a 3.3v logic level and every relay I have seen has a 5v logic level, if that is the case you need to get a logic level shifter before doing anything with your script.

Hey guys, thank you all for your quick response. I already tried the lock and the relay separately - they work fine. The code also looks good. I am actually using ESP32Cam for the project. Let me upload some photos of the wiring:


The relayPin is on GPIO2. I am using a 5V power source from my laptop and 12V from a battery holder. The lock heats quickly also :smiley: . It could be realted to the logic level like @paulpaulson said.

Did you try the relay on its own, driven by the ESP ?

There's LEDs on the relay board - what do they show?

Please post links to the parts you are using - particularly the relay. As the others have said, are you sure it works on 3V?

That would be expected when it is being permanently energised.

Looks like you're doing that via a "hacked" USB cable?

Are you sure that this gives enough power to operate the relay?

Hi @awneil, that hacked cable surely works because I recently powered some servos with it. The relay is blinking green and red which means it works I think. Here is a link to the relay module: Модул 1 реле 5v - it's a Bulgarian site.

I can't read Bulgarian, but that certainly seems to be saying that it's a 5V relay:

You really need to confirm that!
Doesn't the supplier provide documentation?

If the relay is working, you should be able to hear it clicking - can you?

If it is a 5V relay, it's possible that your 3V is just enough to operate the LEDs, but not enough to activate the relay...

Yes, when I put the 5V cable in I can hear the relay clicking.

I think this might be the case ... So I need a level shifter after all, correct ?

This one looks very similar:

On that one, the red LED is labelled "PWR" (short for "Power"?), and the green is "SW":


image

I would guess this means that the red LED should stay on with the power, and the green one should go on/off according to whether the relay is activated?

Again, you should be able to hear the relay clicking...

Thanks! I will try with another relay module ... I think this one is not suitable for this wiring.

It's not about the wiring - it's about the voltage levels.

I tried a different relay module and it worked! I am very happy to see that I can continue my project now! Thank you @awneil and all of you who answered on this topic.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.