Help with Chess Puzzle & Solenoid Lock

Hi, I am in need of some help!

The premise of this project is part of a Harry Potter themed party, it is a chess board with reed switches underneath that when the correct pieces are placed on the correct spots creates a closed circuit, and unlocks a lock underneath the board containing a clue.

For the sake of testing I have just plugged pin 8 to GND and this prints "Circuit Closed" in the serial monitor, and when I disconnect it prints "Circuit Broken", which is what I would expect, except nothing happens with the lock.

I am sure I am missing something very simple, and would appreciate some help :blush:

Thanks,

Dan

const int isClosed = 8; // Arduino pin connected to the chess board
const int relayPin = A5; // Arduino pin connected to the relay

void setup() {
  Serial.begin (9600); // initialise serial
  pinMode (isClosed, INPUT_PULLUP); // set pin to pullup resistor
  pinMode (relayPin, OUTPUT); //set pin to output mode

  digitalWrite(relayPin, LOW); // lock the lock

}

void loop() {

  if (digitalRead (isClosed) == LOW) 
    {
      Serial.println ("Circuit Closed");
      digitalWrite(relayPin, HIGH); // unlock the lock in one second
      delay (1000)
      digitalWrite(relayPin, LOW); //lock the lock in ten seconds
      delay(10000);
      
    } else {
      Serial.println ("Circuit Broken");
      }

  
}

Those relay modules usually have an led to indicate it's energised or not: does yours have one, and is it behaving as expected?

edit: or is the issue that the relay is working (can hear it click?) and the solenoid isn't?

Thanks for the response! Yes it does have a green and red LED on...

And is the relay working, and the solenoid not; or is the relay not working?

I suspect the relay isn't switching because:

image

That means the relay's coil needs 12V... it does not mean it can switch 12V, that's what the other lines of white text tell you.

Ermm?

How?

edit: just in case any later readers are wondering where that quote came from, it's the now-deleted #4.

Ooops - thanks!

Ok I do have it plugged in with a 12V adaptor from mains, will that not work?

It's the solenoid that doesn't seem to do anything :cry:

But you (or at least, I) can't get a compile with this:

(delay 1000)

So the code you are running must be different from the one you posted.

Do you know for a fact that the relay is switching? Have you checked for continuity with your ohm meter, across the com and whichever nc/no connection you're using, while it's supposed to be switching?

That goes to the solenoid. You have only 5V into the relay coil from the Arduino 5V, afaics.

Ah!! That's probably it then! I will grab a 5V relay and see what happens there!!

Thank you so much for the help, I will let you know how I get on :blush:

(And yes I have corrected the delay syntax, I had added that after my initial compile.)

Ok so I have now used a 5V relay and am having the same problem. It doesn't appear to be switching?

The solenoid changes state if I switch the NC to the NO so it clearly works.

The only way I could get the red LED to come on the relay was to connect the pin labelled S to the 5V pin, the + to the GND pin, and the - to the A5 pin which doesn't sound right to me :confused:

I'm really sorry this is my first ever time using a relay!

I just found one like you have... post your current code, let me test.

Thank you so much!

const int isClosed = 8; // Arduino pin connected to the chess board
const int relayPin = A5; // Arduino pin connected to the relay

void setup() {
  Serial.begin (9600); // initialise serial
  pinMode (isClosed, INPUT_PULLUP); // set pin to pullup resistor
  pinMode (relayPin, OUTPUT); //set pin to output mode

  digitalWrite(relayPin, LOW); // lock the lock

}

void loop() {

  if (digitalRead (isClosed) == LOW) 
    {
      Serial.println ("Circuit Closed");
      digitalWrite(relayPin, HIGH); // unlock the lock in one second
      delay (1000);
      digitalWrite(relayPin, LOW); //lock the lock in ten seconds
      delay(10000);
      
    } else {
      Serial.println ("Circuit Broken");
      }

  
}

Your code works for me- I jumpered pin 8 to ground, and relay opens and closes as expectd, with the signal on A5. My meter shows the relay contacts open and close.

Weird, maybe I have a bad relay.

I only get continuity between NC and the common pin whether the relay is powered on or off and if
the circuit is broken or not.

And the relay doesn’t make any clicking.

Thanks for confirming the code is sound though, that’s one less thing to worry about.

Apart from having tested mine with meter, it gives a very clear click, and I can feel it "thunk" in my fingers. And it's literally the identical one to yours.

Perhaps you fried the arduino pin by wiring it wrong. I don’t have that type of relay but I would assume it is + to positive 5v, - to ground, S to signal which is the arduino pin that pulls to ground. I could be wrong and there should be a data sheet for the relay.

Try activating the relay without the arduino. Just wire it correctly and take the signal to ground.