Is my relay broken? Trying to control electromagnet with Arduiono.

Trying to use Arduino to control electromagnet. The magnet waits for the signal from Arduino to lock it just as it's supposed to but I cannot get it to open the lock. Even taking the power away from Arduino doesn't help. I have to take the power away from the cord that powers the magnet trough the relay.

This is the relay I'm using:
http://robotdyn.com/catalog/relays_switches/thyristor_ac_switch_3_3v_5v_logic_ac_dc_ac_220v110v_5a/

Here is a video showing the messy setup. I can add pictures if those help.

The code has the led and signal working opposite they should (lock when supposed to unlcok) but that's for testing purpouses. I wanted to see if it locks the magnet when I power it up or if it actually waits for the signal. Here is the code:

//Checks if the right switches are pressed down (green)

int GreenSwitch1 = 50;
int GreenSwitch2 = 51;
int GreenSwitch3 = 52;
int YellowSwitch1 = 30;
int YellowSwitch2 = 31;
int ledPin = 22;
int lockPin = 8;

void setup() {
  // Set up switches as INPUTS and the LED as OUTPUT
  pinMode(GreenSwitch1, INPUT);
  pinMode(GreenSwitch2, INPUT);
  pinMode(GreenSwitch3, INPUT);
  pinMode(YellowSwitch1, INPUT);
  pinMode(YellowSwitch2, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(lockPin, OUTPUT);
  Serial.begin(9600);
 
}

void loop() {
  
  // Check if the right LEDs are on
  if (digitalRead(GreenSwitch1) == HIGH && 
      digitalRead(GreenSwitch2) == HIGH && 
      digitalRead(GreenSwitch3) == HIGH && 
      digitalRead(YellowSwitch1) == LOW && 
      digitalRead(YellowSwitch2) == LOW)
  {
    digitalWrite(ledPin, HIGH); // Shut down the LED
    digitalWrite(lockPin, HIGH);
    Serial.println("You solved it!");
    delay(1000);
  }
  else
  {
    digitalWrite(ledPin, LOW); // Keep the LED on
    digitalWrite(lockPin, LOW);
    Serial.println("It's still locked");
    delay(1000);
  }
}

EDIT: Changed the relay link to manufacturer's site

Simplify your code so it just locks/unlocks your electromagnet. If it does, it's a sw problem. If not, hardware.

Your link doesn't work

Allan.

Hi,
Are you powering the electromagnet with DC current.
What is the output of your plug pack?

If you are the thyristor switching unit, it will not switch off until the current going through it drops to zero, that is why it unlocks when you turn off the supply.

You should be using AC to power the electromagnet with that thyristor switch.

Tom.. :slight_smile:

I'm using this to power it up trought the Thysistor. It's wrong one? That would explain why one has red/white wires and the other one black/white? I have absolutely no experience in electronics as you might have quessed.

https://m.aliexpress.com/item/32754975558.html

That's a 12v 1A dc psu.

If you use a thyristor/triac as a switch, once it's turned on, it'll never turn off.

You need a logic level mosfet - see attached diagram

Allan

soldrv.pdf (19.1 KB)

Will decode that diagram with google as soon as I get to home :slight_smile:

Would it be simpler/easier to use different switch or different power sorce? I will have to make multiples of these and havent ordered more than parts for couple of them yet.

Thanks for the help so far. I really do apriciate this.

Do you know what voltage/current your solenoid requires? ac or dc ?

This defines what you need to drive it.

Allan

12v dc it seems. Should I replace the switch? Get other type of solenoids (that's the magnet, right?) The only limit is that I want to be able to get the current from household plugs or whatever they are called in english? Wall sockets? I dont want to be worrying about batteries running out?

imppu:
12v dc it seems. Should I replace the switch? Get other type of solenoids (that's the magnet, right?) The only limit is that I want to be able to get the current from household plugs or whatever they are called in english? Wall sockets? I dont want to be worrying about batteries running out?

Main electricity will kill you.
Don't be messing with it unless you are properly trained.

A 5V or 12V power adapter is more than satisfactory and reduces the likely hood of you killing yourself and/or others.

My circuit in post #4 will be fine.

And buy a 12v wall wart to power the circuit. It will also power your arduino via the Vin pin.

Allan

The diagram makes some sense. I will most likely get a better hang of what it actually does when I construct it. Ordered te parts suggested there. Thank you.

12v wall wart is something I can't find. Or the 2 I find from aliexpress don't have eu plugs and are pretty expensive. Don't know what I should be searching for and don't have any local electronics shop.

Hi,
wall wart is yank for "plug pack"

Tom... :slight_smile:

Still don't get what I should order. "12v plug pack" search finds only battery packs with wall chargers. Sorry for being a hard case who doesn't understand the simplest things.

And I live in Finland so our voltage is different from US if that changes anything.

Hi;
If your solenoid works okay with the plug pack you have, then you can change the switching device.
Instead of the thyristor one you have you can use a relay or a MOSFET.
You must however use a diode across the solenoid to stop Back EMF spikes from causing damage.

Like in this circuit, your solenoid would be in place of the motor.

Tom.. :slight_smile:

That seems similliar to ehat Allan sent. I will do that as soon as I get the parts from china.

Thanks for the trouble again guys.