Arduino - DigitalRead Serial Monitor With Button
by MertArduino in Circuits > Arduino
18818 Views, 41 Favorites, 0 Comments
Arduino - DigitalRead Serial Monitor With Button
![Arduino Basic Tutorial 05 - digitalRead Serial Monitor with Button](/proxy/?url=https://content.instructables.com/F8S/0OF4/IVHQJSHE/F8S0OF4IVHQJSHE.jpg&filename=Arduino Basic Tutorial 05 - digitalRead Serial Monitor with Button)
This example shows you how to monitor the state of a switch by establishing serial communication between your Arduino or Genuino and your computer over USB.
​digitalRead()
![vlcsnap-2016-11-16-02h58m23s557.png](/proxy/?url=https://content.instructables.com/FC2/P8B1/IVHQJRNR/FC2P8B1IVHQJRNR.png&filename=vlcsnap-2016-11-16-02h58m23s557.png)
![vlcsnap-2016-11-16-03h03m09s530.png](/proxy/?url=https://content.instructables.com/FWB/4LU2/IVHQJS80/FWB4LU2IVHQJS80.png&filename=vlcsnap-2016-11-16-03h03m09s530.png)
![vlcsnap-2016-11-16-03h03m33s370.png](/proxy/?url=https://content.instructables.com/FG2/WN6Q/IVHQJS82/FG2WN6QIVHQJS82.png&filename=vlcsnap-2016-11-16-03h03m33s370.png)
Description
Reads the value from a specified digital pin, either HIGH or LOW.
Syntax
digitalRead(pin)
Parameters
pin: the number of the digital pin you want to read (int)
Returns
HIGH or LOW
Reference : https://www.arduino.cc/en/Reference/DigitalRead
Hardware Required
![vlcsnap-2016-11-16-02h58m51s034.png](/proxy/?url=https://content.instructables.com/FZ5/O9GB/IVHQJRPW/FZ5O9GBIVHQJRPW.png&filename=vlcsnap-2016-11-16-02h58m51s034.png)
- Arduino Uno
- Button
- 10k ohm resistor
- Wires
- Breadboard
Connections
![vlcsnap-2016-11-16-02h59m29s736.png](/proxy/?url=https://content.instructables.com/FRC/JOZL/IVHQJRRQ/FRCJOZLIVHQJRRQ.png&filename=vlcsnap-2016-11-16-02h59m29s736.png)
![vlcsnap-2016-11-16-02h59m40s917.png](/proxy/?url=https://content.instructables.com/F4F/L44N/IVHQJRTI/F4FL44NIVHQJRTI.png&filename=vlcsnap-2016-11-16-02h59m40s917.png)
![vlcsnap-2016-11-16-03h00m03s060.png](/proxy/?url=https://content.instructables.com/FRV/DH3C/IVHQJRVA/FRVDH3CIVHQJRVA.png&filename=vlcsnap-2016-11-16-03h00m03s060.png)
![vlcsnap-2016-11-16-03h00m22s912.png](/proxy/?url=https://content.instructables.com/FE3/GBKB/IVHQJRX2/FE3GBKBIVHQJRX2.png&filename=vlcsnap-2016-11-16-03h00m22s912.png)
![vlcsnap-2016-11-16-03h00m40s779.png](/proxy/?url=https://content.instructables.com/FAR/15GL/IVHQJRYU/FAR15GLIVHQJRYU.png&filename=vlcsnap-2016-11-16-03h00m40s779.png)
![vlcsnap-2016-11-16-03h00m59s995.png](/proxy/?url=https://content.instructables.com/FTK/HZJC/IVHQJS0M/FTKHZJCIVHQJS0M.png&filename=vlcsnap-2016-11-16-03h00m59s995.png)
![vlcsnap-2016-11-16-03h01m14s501.png](/proxy/?url=https://content.instructables.com/FFA/4MWW/IVHQJS2E/FFA4MWWIVHQJS2E.png&filename=vlcsnap-2016-11-16-03h01m14s501.png)
![vlcsnap-2016-11-16-03h01m45s101.png](/proxy/?url=https://content.instructables.com/FS3/L5UB/IVHQJS48/FS3L5UBIVHQJS48.png&filename=vlcsnap-2016-11-16-03h01m45s101.png)
![vlcsnap-2016-11-16-03h01m59s574.png](/proxy/?url=https://content.instructables.com/FHS/P12B/IVHQJS4C/FHSP12BIVHQJS4C.png&filename=vlcsnap-2016-11-16-03h01m59s574.png)
- Button attach to breadboard
- One leg of the button connect a resistor
- The wire connect to digital pin to one leg of the pushbutton
- Empty leg of the resistor to ground (GND)
- Other leg of the button connect to +5V
Code
![vlcsnap-2016-11-16-03h02m44s491.png](/proxy/?url=https://content.instructables.com/FQQ/K1HK/IVHQJS67/FQQK1HKIVHQJS67.png&filename=vlcsnap-2016-11-16-03h02m44s491.png)
// This example code is in the public domain
int pushButton = 2;
void setup() {
Serial.begin(9600);
pinMode(pushButton, INPUT);
}
void loop() {
int buttonState = digitalRead(pushButton);
Serial.println(buttonState);
delay(1);
}
//reference https://www.arduino.cc/en/Tutorial/DigitalReadSerial
If It Helps, Please Subscribe
![vlcsnap-2016-11-16-03h03m52s241.png](/proxy/?url=https://content.instructables.com/FF7/NMTP/IVHQJS9V/FF7NMTPIVHQJS9V.png&filename=vlcsnap-2016-11-16-03h03m52s241.png)
First of all, I would like to thank you for reading this guide ! I hope it helps you.
If you want to support me, you can subscribe my channel and watch my videos.