Introduction: Arduino - 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.

Step 1: ​digitalRead()

Picture of ​digitalRead()

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

Step 2: Hardware Required

Picture of Hardware Required

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

Step 3: Connections

Picture of Connections

  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

Step 4: Code

Picture of Code

// 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

Step 5: If It Helps, Please Subscribe

Picture of If It Helps, Please Subscribe

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

Comments

About This Instructable

3,451views

37favorites

License:

Bio: For more project and tutorial visit my YouTube channel Mert Arduino and Raspberry Pi
More by MertArduino:XY Plotter Drawing Robot | Arduino | PolargraphArduino - Balance - Balancing Robot | How to Make?Arduino - MPU6050 GY521 - 6 Axis Accelerometer + Gyro (3D Simulation With Processing)
Add instructable to: