Ok, so I took the code from the DigitalRead reference entry and tried to use it to turn on an LED using a switch (just wanted to try DigitalRead, I know I don't need to do it to use the switch). I got an LED connected to pin 12 and a switch connected to pin 7. The only time the LED turns on is when the switch is on AND my hand is nearby (not even touching, just nearby, regardless if i'm grounded with the wriststrap or not). The circuit with the switch doesn't even have to be completed; I can have one wire in pin 7 and the other in the air not touching anything; I put my hand nearby and the LED turns on.
Its probably some basic knowledge known to electronics savvy people, but I am clueless as to what is up. Btw, I have tried setting the circuit/s up a ton of different ways (common ground, seperate ciruits, in series with no ground, in series with common ground, pull up resistor, pull down resistor, etc.); they probably weren't all correct but most gave me the same result and the rest gave me none. Below is the code.
int ledPin = 12; // LED connected to digital pin 12
int inPin = 7; // switch connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 12 as output
pinMode(inPin, INPUT); // sets the digital pin 7 as input
}
void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the switch's value
}