 # Question about Simple Circuit from 5V to input pin

Hi,

I just started playing around with my Arduino so this is an incredibly stupid 'simple' question. Basically I am trying to understand how the digitalread function works. I'm aware that this is a software question but I think the real reason for my confusion is that I don't understand the basic electronics so I posted it here (apologies if this is incorrect!).

The code I am using is this, which I found in a tutorial:

``````/*
* Switch test program
*/

int switchPin = 2;              // Switch connected to digital pin 2

void setup()                    // run once, when the sketch starts
{
Serial.begin(9600);           // set up Serial library at 9600 bps
pinMode(switchPin, INPUT);    // sets the digital pin as input to read switch
}

void loop()
{
delay(100);
}
``````

If i connect the 5V pin to pin2 via a 200 Ohm resistor I get it displaying input 1 and if I connect it to ground I get it displaying 0. Which makes sense to me. However, if I wire up the circuit below I always get a 0 display output and I'm not sure why. Could anyone help me understand whats going on?

http://i60.tinypic.com/2ywz3nk.jpg

Thanks so much for your help!

You always get zero because pin 2 is always connected to zero or ground.

What you have there is a voltage divider with Z1 = 200 and Z2 = 0.

So the equation there in the Wiki tells you that Vout = (0 / (0+200) ) Vin = 0x Vin = 0 for all Vins.

Thanks for the quick replies. Both together are perfect, problem solved!

:)