Tutorial 3: Using Digital Input
English Chinese (Simplified) Czech French German Hindi Italian Japanese Korean Russian Spanish

In this tutorial we will show how read a digital signal using the UNO R3 and report the signal state using the serial port monitor.  We will show you how to connect a simple input circuit using a tact switch and a pull up resistor.


I – Stuffs that you will need:

You will need a UNO R3 Plus board, a mini USB to standard USB cable, a PC as well as a breadboard, a tact switch, a 10kohm resistors and jumper cables for assembling your circuit.

UNO R3 Plus  

Mini USB to Standard USB

Windows PC



Tact Switch

1x10kohm Resistors

Jumper cables


II – Background Information:

In the previous tutorial, we mention that the digital pins of the UNO R3 Plus are rated at 5V, so you can apply a signal as high as 5V signal to it without damaging it.

In this tutorial we will experiment with the digital input pin.  To input a logic-1, we will use a 10k ohm pull resistor connecting to the 5V power supply.   To input a logic-0, we will use a tact switch to short the digital input pin to ground.

By default, the tact switch is open circuit, so the electrical current would flow from the 5V power supply to the D12 pin.  The amount of current flowing into the digital pin is very low because the input pin is a CMOS input.  (This current is referred to as a Cgs leakage current and typically in the μA range.)  Because there is very little current flow, the voltage drop across the 10kohm resistor will be close to 0V.  If you measure the voltage at the input pin, you should see a 5V.  When the tact switch is pressed, a short circuit will form and the digital input pin will be grounded.   If you measure the voltage on the input, you should see a 0V.

Useful Note: The resistor on this circuit is to prevent the 5V from shorting to ground when the tact switch is pressed.  With a 10kohm resistor you will only be sinking 0.5mA of current from the power supply.  If you use a resistor with very low resistance, you could over load and damage the power supply.


III – Schematic Diagram:

Below is the schematic diagram, we will use digital pin 12.


IV – Wiring the Breadboard:

Let’s wire up the breadboard.  Be sure to pay attention to the orientation f the tact switch.  If the orientation is incorrect, the input signal will always be grounded.



V – Writing the Sketch:

Like in the above tutorial, start a new project and copy and paste the below sketch into the Arduino environment.  This sketch will setup digital pin 12 as input using the pinMode function and will uses the digitalRead function to read the state of the pin.  The sketch will poll the pin state once every second.  In addition, the sketch enabled the serial port and will output the pin state on the serial port once every second.




To read the output from the serial port, click Tools à Serial Monitor (or hit Ctrl + Shift + M).

You should see the default button state is 1, and when the button is pressed, the button state is 0.


Things we have covered in this tutorial:

  • Digital input pin
  • Using serial monitor



Tutorial 4: An LED Game

Tutorial 5: Building Voltage Meter

Tutorial 6: Using Buzzer to Play a Melody

Tutorial 7: Counting Down with a 7 Segment LED

Tutorial 8: Powering the UNO R3 PLUS Using Batteries


Download  ARD-101_Tutorial_Codes