digitalread on a pin connected to a relay

Hi guys. I have a circuit that controls a dpdt relay. When the relay trips I want 5v to connect through the relay to a pin on the arduino uno and to do a digitalread on that pin in an “If” statement. Is this possible? I’ve tried it multiple ways and no luck so far. Below is my code with the relevant(I think) parts commented. Without the commented parts, and even with them, the rest of the code works perfectly.

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"

SdReader card; 
FatVolume vol; 
FatReader root; 
FatReader f; 
WaveHC wave; 
short pin2=7;
short pin3=8;
short pin4=9;

int freeRam(void)
{
extern int __bss_end; 
extern int *__brkval; 
int free_memory; 
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) - ((int)&__bss_end); 
}
else {
free_memory = ((int)&free_memory) - ((int)__brkval); 
}
return free_memory; 
} 

void sdErrorCheck(void)
{
if (!card.errorCode()) return;


while(1);
}

void setup() {
byte i;
Serial.begin(9600);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(17,INPUT);                    // This is the arduino input pin I am trying to use. 
digitalWrite (17, HIGH);              // I have tried setting it both HIGH and LOW with no useful results.
pinMode(pin2,INPUT);
digitalWrite (pin2, HIGH);
pinMode(pin3,INPUT);
digitalWrite (pin3, HIGH);
pinMode(pin4,INPUT);
digitalWrite (pin4, HIGH);
pinMode(14, OUTPUT);
digitalWrite (14, HIGH);
pinMode(15, OUTPUT);
digitalWrite (15, HIGH);
pinMode(16, OUTPUT);
digitalWrite (16, HIGH);
if (!card.init()) { 
sdErrorCheck();
while(1); 
}

card.partialBlockRead(true);

uint8_t part;
for (part = 0; part < 5; part++) { 
if (vol.init(card, part)) 
break; 
}
if (part == 5) { 

sdErrorCheck(); 
while(1); 
}




if (!root.openRoot(vol)) {

while(1); 
}


}


void loop() {
byte i;


if(digitalRead(17)==HIGH) {                            // This block of code plays the sound file, but it just 
playfile("SOUND3.WAV");                                // plays over and over whether the relay has been 
while (wave.isplaying) {}                                // tripped or not.
wave.stop();  
}

if(digitalRead(pin2)==HIGH) {
  playfile("SOUND2.WAV");
while (wave.isplaying) {}
wave.stop(); 
digitalWrite (16, LOW);
delay(1000);
digitalWrite (16, HIGH);
delay(1000);
}


if(digitalRead(pin3)==HIGH) {
playfile("SOUND3.WAV");
while (wave.isplaying) {}
wave.stop(); 
digitalWrite (14, LOW);
delay(1000);
digitalWrite (14, HIGH);
delay(1000);
}


if(digitalRead(pin4)==HIGH) {
playfile("SOUND4.WAV");
while (wave.isplaying) {}
wave.stop(); 
digitalWrite (15, LOW);
delay(1000);
digitalWrite (15, HIGH);
delay(1000);
}
delay(500);

}





void playfile(char *name) {
if (wave.isplaying) {
wave.stop(); 
}
if (!f.open(root, name)) {
return;
}
if (!wave.create(f)) {
return;
}
wave.play();
}

I was thinking that the wire connected to the pin from the relay may act as if not connected to anything before the relay trips and therefore be floating which isn't good. I'm just not sure of how this would work.

I have a circuit that controls a dpdt relay. When the relay trips I want 5v to connect through the relay to a pin on the arduino uno and to do a digitalread on that pin in an "If" statement. Is this possible?

How is pin 17 wired to the relay? Is the relay wired normally open or normally closed?

Typically to read the state of the relay with with dpdt, one side is active and driving something. The other side is unused. If the relay is NO, I would recommend that you wire pin 17 through that side to ground and set pinMode to INPUT_PULLUP. Pin 17 will read HIGH when the relay is open and LOW when closed.

This thread is a continuation of http://forum.arduino.cc/index.php?topic=500085