Short story: pin 9 detects the input as high, even when there aren't any wires in it(so no way to detect a input) Other pins have the problem also, but only occasionally. Why would this be happening. I have tried if(digitalRead(pinNum) == HIGH); and if(digitalRead(pinNum) != 0); neither seem to work. I have not tried reversing the logic (subtracting from 255 instead of adding from 0) but I do not see why that would make a difference.
The long story:
I wrote a small bit of code that would detect input on pins 2-9 and return the integer value (the input represents binary. This is for part of a project to help introduce kids to binary, it is a calculator that also outputs in binary on leds. The rest of the project is working) For some reason pin nine always returns as HIGH and some of the other pins do sometimes also. I have noticed that It is only the PWM pins on the last few trials, but this is likely just a confirmation bias, because I think that at one point there were a couple registering incorrectly at a time. I made a separate program just so that I could prove to myself that my other code was not interfering. Now all that the program does is output to serial what pins are detecting a HIGH input.
I have never powered the arduino from anything other than a usb port, so there is no reason that I see that it should have fried. Should I put a resistor inbetween the 5v rail and the input pins? if so how high of a resistance? Do I need a pull down resistor (from the input to ground) to be sure? I would have thought that just having the connection break would be enough, but as we can see what do I know.