Digital Input

Pins 1-13 can be used as inputs or outputs. So far we've only used them as outputs. You set the pin to be an output in a similar fashion to setting the pin mode to an output as we've done in previous lessons.

You will need to build the circuit show in the schematic. Pin 2 will be looking for an input of either HIGH or LOW. Basically it looks for voltage at pin 2. Technically you don't need the 100 ohm resistor. It's there to protect the Arduino chip from a short circuit.

The size of the two resistors are not critical. They are a rough guide. The 10k resistor can be as small as 4.7k and there is really no maximum, but if it is too big the results can be unpredictable.

The other new part included in this program is an "if...else" statement. An "if...else" statement tests a statement, similar to a "for" loop. In this case, though it tests it only once. If the statement is true it runs the following statement once. If false it does what is under the "else".

if (test) {do what is in the brackets if true} else {if the test is false do what is in these brackets}