Digital Read In Arduino - Tutorialspoint
Maybe your like
- Home
- Whiteboard
- Online Compilers
- Practice
- Articles
- AI Assistant
- Jobs
- Tools
- Corporate Training
- Courses
- Certifications
- Switch theme
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Just like analogRead() helps you to read analog voltages, digitalRead() helps you read digital levels.
Syntax
digitalRead(pin)When pin is the number of the pin whose digital level you wish to read. This function returns either HIGH or LOW.
Please note that if the pin you are wishing to read is not connected to anything, it can return either HIGH or LOW, and this value can change with time and noise. Also, in general, analog pins can be used for digitalRead(). As stated in Arduino’s documentation, the following are the exceptions −
Arduino Nano, Pro Mini, and Mini’s A6 and A7 pins, which can only be used as analog inputs.
Example
int pinToRead = 5; void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); pinMode(pinToRead, INPUT); int a = digitalRead(pinToRead); if (a == HIGH) { Serial.println("The pin is at a HIGH Level"); } else { Serial.println("The pin is at a LOW Level"); } } void loop() { // put your main code here, to run repeatedly: }Output
The Serial Monitor Output is given below −

Yash Sanghvi Updated on: 2021-05-29T13:29:22+05:30 6K+ Views
Kickstart Your Career
Get certified by completing the course
Get StartedTag » Arduino If Statement Digital Read
-
DigitalRead And If Statements - Arduino Forum
-
If Statement For Checking DigitalRead Not Executing - Arduino Forum
-
DigitalRead() - Arduino Reference
-
Is "if(digitalRead(2) == HIGH)" An Unreliable Way Of Going About It?
-
Reading A Button - - Arduino Modular Electronics Project - Circuitar
-
Arduino Digital Input & If Statement
-
If/else On DigitalRead Not Executing On 'else' Portion
-
DigitalRead() | Référence Du Langage Arduino En Français
-
Arduino IF Statement Code Examples
-
Why Is My If Statement In My Program Not Working? - Stack Overflow
-
Arduino Lesson 6. Digital Inputs - Adafruit Learning System
-
Unit 12 – The Button And The If-Statement - Tutorials For Arduino
-
Arduino Lesson 4 - If Statements - YouTube