Starting Electronics Needs Your Help!
It is that time of the year when we need to pay for web hosting and buy new components and equipment for new tutorials. You can help by making a donation. Contribute to this website by clicking the Donate button. The total will be updated once daily. (You may need to clear your browser cache to see the updates.)

Target Amount: $2000
Amount Raised: $1960

Donations Received

Top Donor: C.C. $100


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 →

← Go back to P1: AnalogReadSerialGo to P3: Fade →