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

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
vlcsnap-2016-11-16-03h03m09s530.png
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

  • Arduino Uno
  • Button
  • 10k ohm resistor
  • Wires
  • Breadboard

Connections

vlcsnap-2016-11-16-02h59m29s736.png
vlcsnap-2016-11-16-02h59m40s917.png
vlcsnap-2016-11-16-03h00m03s060.png
vlcsnap-2016-11-16-03h00m22s912.png
vlcsnap-2016-11-16-03h00m40s779.png
vlcsnap-2016-11-16-03h00m59s995.png
vlcsnap-2016-11-16-03h01m14s501.png
vlcsnap-2016-11-16-03h01m45s101.png
vlcsnap-2016-11-16-03h01m59s574.png

  1. Button attach to breadboard
  2. One leg of the button connect a resistor
  3. The wire connect to digital pin to one leg of the pushbutton
  4. Empty leg of the resistor to ground (GND)
  5. Other leg of the button connect to +5V

Code

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

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.

Mert Arduino Tutorial & Projects