I posted this last week and changed my inputs to be INPUT_PULLUP and set the software to look for a LOW signal. Which works great when I just a little jumper from ground to pins 2-7 my corisponding outputs go low triggering pins 8-13 so when 2 is low pin 8 goes low and fires a relay, 3 goes low and fires 9 low and so on. My problem is when I actually attach my wire to my switch out in the field and trigger a contact closure on pin 2 all outputs go low? what am I missing. Do i need a resister some where. I am using this 4 channel relay board, 4 Channel 5V Relay Module - Wiki , it says it only need 15-20ma of current per relay so if all 4 are fired it is only drawing 80ma of power so i should be under what the limit of 200ma is. Here is my code, i am at a lost as to why a contact closure would cause this to happen but when I remove the wire and just jump to ground i dont have any issues? Sorry to be a pain but cannot wrap my head around what the difference is?
const int INPUTPINFIRST = 2;
const int INPUTPINLAST = 7;
const int OUTPUTPINFIRST = 8;
const int OUTPUTPINLAST = 13;
int pinWaitingFor = INPUTPINFIRST;
int soundTriggerCurrPin = OUTPUTPINFIRST;
void setup() {
// put your setup code here, to run once:
// Set up the pins for input.
for ( int li_LoopPinIdx = INPUTPINFIRST ; li_LoopPinIdx <= INPUTPINLAST ; li_LoopPinIdx++ )
{
pinMode ( li_LoopPinIdx , INPUT_PULLUP);
}
// Set up the pings for output.
for ( int li_LoopPinIdx = OUTPUTPINFIRST; li_LoopPinIdx <= OUTPUTPINLAST ; li_LoopPinIdx++ )
{
pinMode ( li_LoopPinIdx , OUTPUT);
}
// Set up the output pins as HIGH.
for ( int li_LoopPinIdx = OUTPUTPINFIRST; li_LoopPinIdx <= OUTPUTPINLAST ; li_LoopPinIdx++ )
{
digitalWrite ( li_LoopPinIdx , HIGH);
}
}
void loop() {
// Read the input pin.
int buttonState = digitalRead (pinWaitingFor );
// Did they trigger it>'
if ( buttonState == LOW )
{
// Does this pin need a delay?
if ( pinWaitingFor == INPUTPINFIRST )
{
// Delay to let everyone in.
delay ( 100 );
}
// Fire the sound.
PinTemporarilyLow ( soundTriggerCurrPin );
// Set up for the next sound.
soundTriggerCurrPin++;
// Set up for next pin.
pinWaitingFor++;
// Are we out of pings?
if ( pinWaitingFor > INPUTPINLAST )
{
// Exit the loop.
exit;
} // End of if ( pinWaitingFor > INPUTPINLAST )
} // End of if ( buttonState == HIGH )
} // End of loop ()
void PinTemporarilyLow ( int pinNumber )
{
// Set the pin low.
digitalWrite ( pinNumber , LOW );
// Wait 1/10th of a second.;
}