Starting Electronics needs your help! Please make a donation to help cover our hosting and other costs. Click the donate button to send a donation of any amount.

Project 2: Read a Digital Value (DigitalReadSerial)

Created on: 2 August 2012

Tutorial 10 – Pages

The Arduino continuously reads the state of pin 2 to see if the attached switch is open or closed. The state of the switch is continuously sent out of the serial (USB) port for display on the Arduino IDE serial monitor window.

Parts Needed

  • 1 × 10k resistor (1/4W, 5%)
  • 1 × push button or toggle switch (or just a wire link will do)

Arduino Website Page


In the Arduino IDE

File → Examples → 1.Basics → DigitalReadSerial

Building the Circuit

The DigitalReadSerial page on the Arduino website shows the circuit diagram and breadboard connections.

If using just a wire link instead of a switch, start by connecting a wire link from Arduino pin 2 to one end of a 10k resistor on the breadboard. Connect the other end of the resistor to one of the Arduino GND pins using a wire link. To simulate a switch, connect a wire to the Arduino 5V pin. To close the "switch" touch the other end of the wire to Arduino pin 2. This can be done on the breadboard where Arduino pin2 connects to the 10k resistor. Don't connect the wire to the wrong end of the resistor or you will be shorting out the 5V power.

Programming and Operating the Circuit

In the Arduino IDE select File → Examples → 1.Basics → DigitalReadSerial to open the sketch for this project. Verify and then upload the sketch.

Open the serial monitor window. With the switch open, zero (0) will be continuously sent to the serial monitor window. Closing the switch will continuously send one (1) to the serial monitor window.

Project 2 Video

Can't see the video? View on YouTube →

As an Amazon Associate I earn from qualifying purchases:

As an Amazon Associate I earn from qualifying purchases:

Amazon Website

Computer Best Sellers