Digital Input

Anand Ramaswami

Welcome back, Maker!

In the previous blog, we learned how to control things using digital output like turning LEDs ON and OFF.

Now we will learn the opposite idea:

Digital Input

Instead of sending signals out, the Arduino will now read signals coming in.

This is how Arduino understands what is happening in the real world.

For example:

  • Is a button pressed?
  • Is a switch ON or OFF?
  • Did a sensor detect something?

This is called Digital Input.

What Is Digital Input?

A digital input pin reads only two possible values:

  • LOW
  • HIGH

Just like digital output, there are only two states.

Think of it like a question:

Is the button pressed or not?

The Arduino reads the answer as:

  • LOW = 0
  • HIGH = 1

So the board can make decisions based on this.

Digital Inputs on the Board:

The KIDUINO Trainer Board has several input devices already built in.

These include:

  • D2 → Button 1
  • D3 → Button 2
  • D8 → Button 3
  • D7 → Button 4

In this blog, we will focus on the push buttons.

Push buttons are one of the simplest and most useful digital inputs.

What Is a Push Button?

A push button is a simple switch.

It has two states:

  • Pressed
  • Not pressed

When pressed, the circuit is connected.

When released, the circuit is open.

Arduino reads this change using a digital input pin.

So if we want Arduino to check whether a button is pressed or not, we need a command to read that pin. That command is digitalRead().

The Command: digitalRead()

digitalRead() is used to read the value of a digital input pin.

Syntax:

digitalRead(pin);

Parameters:

pin → the pin number you want to read

Returns

The function returns:

  • HIGH
  • LOW

Example:

int buttonState = digitalRead(2);

This means:

Read the signal on pin 2 and store it in a variable called buttonState.

Now that we know how to read a digital pin, let’s use it in a real example.

 

Project-1: Read Push Button on Serial Monitor

Now let’s make the Arduino detect when a button is pressed.

Instead of turning on an LED, we will print the result in the Serial Monitor.

void setup() {

  pinMode(3, INPUT);   // Button connected to pin 3

  Serial.begin(9600);         // Start serial communication

}


void loop() {

  int buttonState = digitalRead(3); // Read button


  if(buttonState == HIGH){

    Serial.println("Button Pressed");

  }

  else{

    Serial.println("Button Not Pressed");

  }

  delay(200);

}

Explanation:

pinMode(3, INPUT); tells Arduino that pin 3 will read a button, and it turns on the internal pull-up resistor.

Serial.begin(9600); starts communication between the Arduino and the Serial Monitor.

digitalRead(3); reads the state of the button on pin 3.

if(buttonState == HIGH) checks if the button is pressed.

Serial.println("Button Pressed"); shows the message when the button is pressed.

else Serial.println("Button Not Pressed"); shows the message when the button is not pressed.

delay(200); waits for a short time before reading again.

This repeats forever, so the Arduino keeps checking whether the button is pressed or not.
Wait why does it work without any extra components?

You might be wondering: the button just connects two wires together. How does the Arduino know the pin is HIGH when the button isn't pressed? Shouldn't the pin just be... nothing?

This is a real problem in electronics called floating. When a pin isn't connected to anything definite, it drifts randomly between HIGH and LOW — giving you garbage readings. To fix this, you need a pull-up resistor.

A pull-up resistor connects the pin to 5V through a resistor, so the pin sits firmly at HIGH when the button isn't pressed. The moment you press the button, it connects the pin directly to GND — pulling it LOW. That's why pressed = LOW.

Here's the good part: your KIDUINO Trainer Board already has pull-up resistors built in as hardware, wired directly on the board for every button pin. You don't need to add any components, and you don't need to do anything special in code. Just using INPUT is enough — the board takes care of the rest automatically.

In summary:

  • button not pressed → pull-up holds the pin at HIGH
  • button pressed → GND pulls the pin to LOW

This is why we check for the button state carefully and why the reading stays reliable.

Now that we know how a button is read, let us use that button to control something.


Project-2: Control Single LED using Button

In this project, we will use a push button to control an LED.
When the button is pressed, the LED will turn ON.
When the button is released, the LED will turn OFF.

This helps us understand how Arduino reads digital input from a button and uses it to control an output device.

void setup() {

  pinMode(3, INPUT); // Button connected to pin 3

  pinMode(5, OUTPUT);       // LED connected to pin 5

}


void loop() {

  int buttonState = digitalRead(3); // Read the button state


  if(buttonState == HIGH){           // Button pressed

    digitalWrite(5, HIGH);          // Turn LED ON

  }


  else {                             // Button not pressed

    digitalWrite(5, LOW);           // Turn LED OFF

  }

}

Output:

Explanation:

pinMode(3, INPUT); tells Arduino that pin 3 will read the button.

pinMode(5, OUTPUT); tells Arduino that pin 5 will control an LED.

digitalRead(3); reads whether the button is pressed or not.

if(buttonState == HIGH) checks if the button is pressed.

digitalWrite(5, HIGH); turns the LED ON when the button is pressed.

digitalWrite(5, LOW); turns the LED OFF when the button is not pressed.

So the LED follows the button, presses the button and the LED lights up.

Once you can control one LED with one button, the next step is to control more than one output using more than one input.

 

Project-3: Control Multiple LEDs using Multiple Buttons

In this project, we will control two LEDs using two buttons.

Each button controls its own LED.

Button 1 → LED 1
Button 2 → LED 2

This helps us learn how Arduino can handle multiple digital inputs at the same time.

void setup() {

  pinMode(2, INPUT); //Button 1

  pinMode(3, INPUT); // Button 2


  pinMode(5, OUTPUT); // LED 1

  pinMode(6, OUTPUT); // LED 2

}


void loop() {

  int button1 = digitalRead(2); // Read button 1

  int button2 = digitalRead(3); // Read button 2

  if(button1 == HIGH){           // If button 1 pressed

    digitalWrite(5, HIGH);      // LED 1 ON

  }

  else{

    digitalWrite(5, LOW);       // LED 1 OFF

  }

  if(button2 == HIGH){           // If button 2 pressed

    digitalWrite(6, HIGH);      // LED 2 ON

  }

  else{

    digitalWrite(6, LOW);       // LED 2 OFF

  }

}

Output:

Click Here

Explanation:

pinMode(2, INPUT); sets pin 2 as button input.

pinMode(3, INPUT); sets pin 3 as another button input.

pinMode(5, OUTPUT); and pinMode(6, OUTPUT); set pins 5 and 6 as LED outputs.

digitalRead() reads the state of each button.

If Button 1 is pressed, LED 1 turns ON.
If Button 2 is pressed, LED 2 turns ON.

Each button works independently, so you can control multiple devices using different buttons.

After seeing these examples, it becomes easier to understand why digital input is such an important part of Arduino.

Why Digital Input Is Important ?

Digital input allows Arduino to understand what is happening around it.

By reading signals from buttons, switches, and sensors, the board can make decisions and control other devices.

It helps you:

  • Detect button presses
  • Read switch states
  • Trigger actions in your program
  • Build interactive electronics projects

Almost every Arduino project uses digital input to interact with the real world.

Real-Life Examples of Digital Input

Digital input is used in many electronics and robotics systems, such as:

  • Elevator buttons
  • Doorbell switches
  • Robot control buttons
  • Menu navigation systems
  • Game controllers

Whenever a device needs to detect a press, trigger, or signal, digital input is used.

Why This Is Powerful

With digital input, your Arduino can now react to users and sensors.

Instead of just turning things ON and OFF automatically, the board can now respond to actions.

Press a button → turn on an LED
Press another button → start a motor
Press multiple buttons → control different devices

This is how real interactive systems and robots are built.

Final Thoughts

Digital input is one of the most important foundations of Arduino programming.

Once you understand how to read HIGH and LOW signals, you can start building systems that respond to the world around them.

You are no longer just running code — you are creating interactive electronics.

Keep experimenting, keep building, and keep making. 

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.