SIGN IN
SIGN IN HOME BUY SOFTWARE PRODUCTS LEARNING COMMUNITY SUPPORT
Reference > Language > Functions > Digital io > Digitalread
LANGUAGE
FUNCTIONS
digitalRead()
VARIABLES
[Digital I/O]
STRUCTURE
LIBRARIES Description
GLOSSARY Reads the value from a specified digital pin, either HIGH or LOW .
The Arduino Reference text is
licensed under a Creative Syntax
Commons AttributionShare Alike
3.0 License.
digitalRead(pin)
Find anything that can be
improved? Suggest corrections
and new documentation via Parameters
GitHub.
Doubts on how to use Github? pin : the number of the digital pin you want to read
Learn everything you need to
know in this tutorial.
Last Update: 11/15/2017 Returns
HIGH or LOW
EDIT THIS PAGE
Example Code
Sets pin 13 to the same value as pin 7, declared as an input.
int ledPin = 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(inPin, INPUT); // sets the digital pin 7 as input
}
void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value
}
Notes and Warnings
If the pin isnt connected to anything, digitalRead() can return either HIGH or LOW (and this
can change randomly).
The analog input pins can be used as digital pins, referred to as A0, A1, etc.
See also
LANGUAGE digitalWrite()
LANGUAGE pinMode()
EXAMPLE Tutorial: (Digital Pins)
SIGN IN HOME BUY SOFTWARE
NEWSLETTER
ENTER YOUR EMAIL TO SIGN UP SUBSCRIBE
Copyright Notice
Contact Us
About Us
Careers
2017 Arduino