5V Relay activating without output voltage

Hello!
I am trying to use an Uno to control a solenoid lock via a Wiegand reader.
To switch the lock circuit I also installed a 5V relay, which worked fine when testing it, hooked up to my laptop USB.
When I installed the components to the door however, the relay now activates without getting an output signal from the signal pin.
Do I need something in between the relay and the arduino?

One weird thing I noticed is that when I apply a different power source to the Wiegand, it doesn't recognize the cards anymore.

Here is my wiring scheme:

Relay is a generic TongLing 5V from the local electronics store.

No, you need to show your code, a photograph (or photographs) of your wiring with all connections clearly visible and explain what power supplies you are using. The Web reference for the relay module and the Wiegand reader.

Your diagram shows something connected to "Vin" on the Arduino which makes no sense. You should not be using "Vin" or the "barrel jack" for any purpose; you need a 5 V power supply.

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/681307/2

Its not hard to provide a link

https://en.tonglingrelay.com/product/JQC-3FF-S-Z-5V-Buy-Relays-From-Tongling-Factory-1061.html?productCateId=25

Which tells us the coil resistance is 70 ohms and it takes 70mA.

But that is NOT the device you are using, which seems to be a relay MODULE. So please provide the right link to the module you are using.

WG reader:

Relay module

Sorry, as I am a new user, I can only post 2 links per post. To be continued!

Currently, the Arduino is powered via Barrel Jack.

Image of wiring:

As per the diagram:
Pin 2 and 3 - Green and white - Reader data
Pin 7 - Blue - Reader LED
Pin 8 - Yellow - Reader Buzzer
Pin 12 - Orange - Relay module signal

Purple - Relay module VCC (UNO Vin)
Blacks - GND (Relay module and Reader)
Red - Reader 5V

Image of power adapter:

My code:

#include <SoftwareSerial.h>

#include <EEPROM.h>
#include <Wiegand.h>

WIEGAND wg ;

// alarm state in the zero byte of EEPROM
// 0 - disabled, 1 - enabled
int eeepromAddr = 1;

// buzzer pin (yellow)
int buzzerPin = 8 ;
// pin to LED (blue). 0 - green, 1 - blue
int ledPin = 7 ;
// pin to relay signal
int relayPin = 12 ;




// array with keys
long keys [] = {21144, 8489017, 5710} ;
// number of keys
int keysCount = 3 ;

void setup () {
  pinMode (ledPin , OUTPUT) ;
  pinMode (buzzerPin , OUTPUT) ;
  pinMode (relayPin , OUTPUT ) ;

  // define the state of the alarm
  // enabled. turn on the blue LED
  digitalWrite ( ledPin, HIGH) ;



  if (EEPROM.read (eeepromAddr) == 1 ) {
    digitalWrite (ledPin , HIGH) ;

  }
  // disabled or undefined
  else {
    digitalWrite (ledPin , LOW) ;
  }
  digitalWrite (buzzerPin , HIGH) ;
  Serial.begin ( 9600 ) ;
  wg.begin () ;

}

void loop () {
  if (wg.available ()) {
    Serial.println (EEPROM.read (eeepromAddr)) ;
    long currentKey = wg.getCode () ;
    Serial.println (currentKey) ;

    // if the alarm is enabled
    if (EEPROM.read (eeepromAddr) == 1 ) {
      // a known key is supplied - disable the alarm
      if (keyCheck (currentKey)) {
        EEPROM.write (eeepromAddr , 0 ) ;
        digitalWrite (ledPin , LOW) ;
        digitalWrite (relayPin , LOW ) ;
        delay ( 10000) ;
        digitalWrite ( ledPin , HIGH);
        EEPROM.write (eeepromAddr , 1 ) ;
        digitalWrite ( relayPin , HIGH ) ;
      }
      // unknown key (here you can make a notification that someone tried to open it)
      else {
        unknownKey () ;
      }
    }
    // if the alarm is turned off and a known key is presented, turn on the alarm
    else {
      if (keyCheck (currentKey)) {
        EEPROM.write (eeepromAddr , 1 ) ;
        digitalWrite (ledPin , HIGH) ;
      }
      // unknown key (here you can make a notification that someone tried to open it)
      else {
        unknownKey () ;
      }
    }
  }
}

// function for checking if the key is matched
boolean keyCheck ( long currentKey) {
  for ( int i = 0 ; i < keysCount ; i ++) {
    if (keys [i] == currentKey) {
      Serial.println ( "COMPARE!" ) ;
      return true;
    }
  }
  return false;
}

// function for an unknown key
void unknownKey () {

}

Most of my code is from a tutorial from (mozgit. by) (again, 2 link limit, will post if necessary) and edited to fit my needs to the best of my knowledge.

Would a standard USB charger rated 5V/1A suffice?

That would be a far more appropriate source of 5 V.

If connecting (any) other things to the UNO, do not use the "barrel jack" or "Vin". :astonished:

I have since powered the Arduino with a 5V phone charger via the USB jack and the 5V relay module via a separate 5V charger, but now the relay module fails to switch open. What am I doing wrong now?

Not posting your updates. How do we know what your new wiring scheme or code looks like?

I have now tested the arduino and the relay module with this piece of code:

#include <SoftwareSerial.h>

#include <EEPROM.h>
#include <Wiegand.h>

WIEGAND wg ;

int relayPin = 11 ;
void setup() {
  // put your setup code here, to run once:
int ledPin=7;

  pinMode ( relayPin, OUTPUT );
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite (relayPin ,HIGH);
delay (2000);
digitalWrite (relayPin, LOW);
delay (2000);

}

Wierdly, the code only works correctly if both the Arduino and the relay module are powered from my laptop USB ports. If either is powered from a separate 5V USB phone charger, the setup does not work.

Seems to be the source of the issue. Post a pic of your setup with the USB chargers wired in. Are the grounds from both power thingies tied together?

Do you understand the concept of an electrical circuit?

That you need a ground (negative) connection between the relay module and the Arduino as well as the control connection, to permit the current to flow?

The ground of the two USB ports in the PC is the same.