Best way to connect relay input controlled from external power

I have some relay that I wont to read ON/OFF status on I can select if the relay switch +5v or GND is this the best way to go? for your info the relay is power externally using 12-16 Volt

Sven Åke

Here is my suggestion.

Edit: Corrected error on schematic.

I have this relay B197 Relay card 12 V/DC
for 12v + and - and power is controlled by output from model railroad so that is separated from Arduino

so do that mean I can connect P to GND and S to pin that I read for ex pin2 as in this example from my first link?
and in program use pullup

void setup(){
  //start serial connection
  //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);


void loop(){
  //read the pushbutton value into a variable
  int sensorVal = digitalRead(2);
  //print out the value of the pushbutton
  // Keep in mind the pullup means the pushbutton's
  // logic is inverted. It goes HIGH when it's open,
  // and LOW when it's pressed. Turn on pin 13 when the
  // button's pressed, and off when it's not:
  if (sensorVal == HIGH) {
    digitalWrite(13, LOW);
  else {
    digitalWrite(13, HIGH);

should this work?
sorry for this beginners questions

Sven Åke

My apologies, I misunderstood the question and my schematic was in error. The digital output to the relay would be HIGH to energize the relay. It looks like you code would energize the relay while the button is held down. Is that the goal? Don't apologize for being new, we all were.

Thanks I will try that later

Sven Åke