Basic Touch Sensor / Switch program


I'm totally new to Arduino -- I just bought my first kit last week. Please bear with me.

I'm trying to create an extremely simple circuit that will run current through a wire, and detect if and when the circuit is broken. This is probably the easiest project you guys have ever heard of, but right now, I'm having a hard time figuring out how to accomplish it. Right now, I'm thinking out treating the wire like its a switch, and simply checking to make sure that its digital value remains constant at 1, and when it changes to 0, continue with the program.

My main issue is figuring out where I should attach the wires and how I should connect them to the board -- I have an Arduino Uno and a fully assembled Sparkfun "Protoboard", but I cant figure out what else I would need to make the circuit work and where I should attach it.

I would greatly appreciate any insight into what other electronics I need to attach to make this work, and also where I should place then, and I how I would acknowledge this in the code. I'm used to systems like the Handyboard and CBC where we dont have to do a lot of this stuff -- so hopefully you guys can introduce me into the platform and kickstart my Arduino career.

Thanks! :)

You could read it as an analog value, use a common ground. Don't try measuring voltages coming out of the wallsocket though, stay within limits of the input range of your board.

I'm going to be powering this off a 9v battery, so no problem with voltages.

So I should just connect the wire to a 3v and a gnd and read the value as an analog?

Errr, NO!.. what's your setup? Details would help, if you're totally new to electronics you might wanna read up on that too.

Take a simple approach.

Define a pin as an input, with pullup resister enabled. pinMode (pinx, INPUT); digitalWrite(pinX, HIGH);

connect the pin to ground with your wire.

Then read it, when it goes high, the ground connection has been broken:

voild loop(){ pinX_state = digitalRead(pinX); if (pinX_state == 0) { // do something, like turn on an LED }

} // end loop

Questions for CrossRoads:

  1. What kind of pullup resistor should I purchase?

  2. Exactly which pins on the Ardunio Uno / SparkFun Protoboard should I attach the wire too? Where should I place the LED? How should I wire it? I don't really understand.

I'm a total noob when it comes to this sort of stuff (I've mainly been working with HandyBoard / CBC, where all of the sensors and motors fit nicely into predefined slots and you don't have to worry about anything on the electronics side).


  1. None. Use the internal pullup:
    pinMode (pinx, INPUT);
    digitalWrite(pinX, HIGH); << this connects the internal pullup for pinX

  2. Hmm. Okay, go back and do some of the Learning tutorials. Specifically Blink & Button.

LadyAda has great step by step tutorials