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: $840
Top Donor: C.C. $100
Created on: 2 August 2012
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.
File → Examples → 1.Basics → DigitalReadSerial
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.
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.
Can't see the video? View on YouTube →