- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Digital Read in Arduino
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 −
- Related Articles
- How to read data from EEPROM in Arduino?
- Read values sent by Serial Monitor to Arduino
- Read a file from SD Card connected to Arduino
- Read a specific bit of a number with Arduino
- How to interface Arduino with a GSM Module and read SMS?
- How to interface Arduino with a GSM module and delete all the read SMSes?
- Arduino Uno vs Arduino Leonardo
- Arduino Uno vs Arduino Micro
- Arduino Uno vs Arduino Mega
- Arduino Uno vs Arduino Nano
- Arduino Uno vs Arduino Due
- Interrupts in Arduino
- Arrays in Arduino
- PWM in Arduino
- Timers in Arduino

Advertisements