Detecting line disconnection

Hi,

I'm making a bomb prop with an external trigger connection
The connection will get a constant 5V power supply so if it's disconnected, the external circuit knows that, and detonates the smoke bomb or what ever
But I also want that the bomb will "explode"

So the Arduino will have the external trigger connected on a digital pin configured to output
An I want it to connect SOMEHOW to an input pin so I'll know when it's disconnected

How can this be done?

Thanks!

Just connect the input pin to ground with a wire. When you cut the wire it will go HIGH.

// Wire is connected to this pin
#define WIRE_PIN 4

void setup()
{
  pinMode(WIRE_PIN,INPUT);
  digitalWrite(WIRE_PIN,HIGH);
}

void loop()
{
  if (digitalRead(WIRE_PIN)==HIGH) {
    Serial.println("Bang!");
  }
}

This seems to work nicely but the wire pin gives just a little bit of current
I'm using a 2N4401 transistor for the external device and its needs more current

omni96:
This seems to work nicely but the wire pin gives just a little bit of current

Correct. You never specified it had to provide a lot of current.

omni96:
I'm using a 2N4401 transistor for the external device and its needs more current

Use a different pin for powering whatever it is you want to power.

This seems to work fine
Am I doing this right?

#define epin 4

void setup(){
  pinMode(epin, OUTPUT);

  digitalWrite(epin, HIGH);
}

void loop(){
  // If the LED on pin 13 is on, it meens that the connection was broken
  digitalWrite(13, digitalRead(epin));
  
  delay(15);
}

omni96:
This seems to work fine
Am I doing this right?

#define epin 4

void setup(){
  pinMode(epin, OUTPUT);

digitalWrite(epin, HIGH);
}

void loop(){
  // If the LED on pin 13 is on, it meens that the connection was broken
  digitalWrite(13, digitalRead(epin));
 
  delay(15);
}

I don't think you should be using digitalRead() on a pin that's an OUTPUT.

fungus:
I don't think you should be using digitalRead() on a pin that's an OUTPUT.

It's perfectly acceptable. --Provided you understand what is being "read".

Reading a pin configured as an OUTPUT will return the last state value of the PORT register set by digitalWrite()

Edit: Revised statement to be a bit more clear

Umm, but this isn't what I want, and it doesn't do that actually
It will return low if connected to the external circuit
And high when disconnected

omni96:
Umm, but this isn't what I want

What did you want? To treat the pin as an OUTPUT and INPUT? That you can't do simultaneously.

omni96:
It will return low if connected to the external circuit
And high when disconnected

It can't do that. digitalRead() only reads the PORT register. The PORT register, when configured as an output, has no idea what voltages are being applied to the pin.

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  Serial.println(digitalRead(13));
  digitalWrite(13, LOW);
  Serial.println(digtialRead(13));
}

That will result in

1
0

Also, in your code, you never set pin 13 to an OUTPUT. So your digitalWrites() are only turning on and off the pull-up resistor for that pin.

So I have set 13 to output and even added some serial output
It still works for some reason

omni96:
It will return low if connected to the external circuit
And high when disconnected

That's not possible for an output pin.

Either your code isn't what you posted or there's something very badly wrong with the wiring.

I have no idea what the problem was so I started over and used 2 optocouplers and it all works now

Thanks alot for the help! :stuck_out_tongue_closed_eyes: