Digital input: what is it again?

Let’s say that you’re standing outside a friend’s house looking through the window at a light switch. Your friend calls to ask “Is the light switch on?” Your job is to tell the friend “yes the light switch is on” or “no, the light switch is off.” That’s exactly what a digital input does: reports whether it is on or off.

In digital inputs, there are only two possible states: high and low, which you can think of as ON (high) or OFF (low). Digital inputs measure whether something is ON (in a HIGH state) or OFF (in a LOW state). HIGH /ON is also equal to 1 and LOW/OFF is equal to 0. We can use the digital pins on the Arduino to check on buttons and switches to see whether or not they have been triggered or pressed.

Why are there three different ways to say the same thing?

If HIGH, 1, and On are all equivalent (as are LOW, 0, and Off), why are there multiple ways to say the same thing? This can be confusing.

Each value talks about a different aspect of our Arduino project:

On and Off refer to what we see happening in the world. For example, is the LED lit or not? We don’t use the terms on and off in our code for the Arduino, only in our general discussions.

1 and 0 are integer variable values that represent On and Off (respectively). We use 1 or 0 when we are initializing variables in our code. You saw an example of this in out sketch’s initialization code, which includes the line int buttonState = 0; This tells the Arduino that the button is initially off.

HIGH and LOW refer to the electrical state of the pin: is the pin providing 5 volts or is it acting as 0v (ground)? In the Arduino programming language, HIGH and LOW are used to set or to read the state of a pin (via digitalWrite and digitalRead functions).

1s and 0s are part of the binary language that allow computers to speak. High and low, means 1 and 0 to computers, including our Arduino. HIGH and LOW make the code slightly easier for humans to read, and they are used when we are using the digitalWrite and digitalRead functions. We’ll use 0 and 1 when we are creating new variables.

Conditional statementsVariables

Leave a Reply

Your email address will not be published. Required fields are marked *