[Solved] Input Digital Pins / Cuting a wire.

Hi everyone.

Today I need your help. I'm working on a simple project :

When I cut a wire (or unplug it), I want to return a value ("1" or "0", or another fixed value, I don't care).

I followed the schematics included in the doc page on the official Arduino website ( http://arduino.cc/en/Tutorial/DigitalReadSerial )

My code is very long, so I cut it :

int inPin0 = 0;

int val0 = 0;     // variable to store the read value

void setup() {
  
  pinMode(inPin0, INPUT);
  Serial.begin(9600); 

}

void loop() {
int val0 = digitalRead(inPin0);
Serial.println(val0);
}

My Serial.println always return "1" value, even if I disconnect the Digital Pin (0 pin)

Thanks a lot for helping me.

Read:- http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Enable the internal pull-ups or use external ones, then connect the wire to the ground, when intact the pin where the wire is connected will read 0, when cutted the pull-ups will pull the pin up and it will read 1.

I already have an external pull-up resistor connected. But I think I forgot to configure it. I'll try and tell you if it works.

Thanks

Do not use pins 0 or 1, these are used by the serial connection that the print statement uses. Use another pin.

Oh. That’s why it won’t work. I’ll try.

Okay, it's better but I have another problem.

Now, the output seems to be a random number. I don't know wich wire I need to cut to change the output value. I tried the GND wire, wich give me a "1 0 0 0 1" again and again.

Sometimes it works well with the GND pin, and just after I get random numbers.

Tell me, I need to disconnect the GND or the Digital Pin to change the output value ?

and just after I get random numbers.

Read the first link I posted that tells you why you get random numbers.

Oh, I see.

Okay I tested with your hints and it works very well now.

I added a wire between the Digital Input and the Vcc and now it works when i disconnect (or cut) the wire.

Thanks a lot.

I already have an external pull-up resistor connected. But I think I forgot to configure it.

You can't "configure" external resitors.

I added a wire between the Digital Input and the Vcc and now it works when i disconnect (or cut) the wire.

You'd save yourself the cost and hassle of soldering external resistors if you used the internal pull-ups.