Wednesday 22 August 2012

Arduino: Detect when two wires are connected

Arduino can detect if you cut the connection of a wire or you want implement a piezo sensor, basically the theory is the same.
One application, that I have tried at home, is to detect when the door is open and when is close.
You have to put 2 wires on the door that when it is closed, the two wires must make a bridge and break it when it is open.

The piezo works with the same concept , when you touch it, your finger does a bridge and then you can catch it with your Arduino.

This is a piezo sensor

CODE

void setup() {
pinMode(A0,INPUT);
}
void loop() {
   if (analogRead(A0) < 50) {
      //The two wires are doing a bridge
  } else {
     //The two wires are disconnected
  }
  delay(100);
}


You should try it and find out a good value but normally when the two wires are connected the value is zero.

This is an example of to connect the piezo on your Arduino


WIRING
Connect one wire on the ground pin and the other one in the A0 pin.