New to Raspberry Pi. Need help with simple program to detect closing of a circuit.

I had this same exact problem. I love my RPi's and all, but after researching my options I went with Arduino Uno R3 board, which is a $15 open source board really built for this sort of stuff (i.e., sensing). In Arduino Tutorial #2 here ( http://www.sunfounder.com/learn/Super-Kit-V2-0-for-Arduino/lesson-2-controlling-an-led-by-button-super-kit.html ), they show how to control an LED with a button, and with just very few lines of code. I realized that I could swap the button out for leads to be continuity tested. Then, I embellished the Tutorial into my Continuity Tester On steroids. Main code event loop:

void loop() { giTock++;

// Read the state of the contin pin and check if broken (the state is LOW) if(digitalRead(continPin) == LOW ) { digitalWrite(ledPin, LOW); // turn off the LED (Pin 13)

// Set T0, if not already set
if(ulFaultT0 == 0)
{
  ulFaultT0 = millis();
 }

} else { digitalWrite(ledPin,HIGH); // turn on the LED (Pin 13)

if(ulFaultT0 > 0)
{
  ulFaultT1 = millis(); // Close Duration interval
  giFaults++;
  displayFault();
  // Reset
  ulFaultT0 = 0;
}

if(giTock % ciTockInterval == 0)
{
  giTock = 0;
  displayElapsedTime();
}

} }

And logging fault is done by:

void displayFault() { Serial.print("*** Fault "); Serial.print(giFaults); Serial.print(": Occurred at "); printTime( millis() ); Serial.print(" [Duration: "); Serial.print(ulFaultT1 - ulFaultT0); Serial.println("ms] ***");
}

I use RPi for various HTPC and VPN stuff, but for knocking out micro-controlled electronic circuits, Arduino is my go to board.

/r/raspberry_pi Thread