Jump to content

Experiment 1: Introduction to Arduino and Digital I/O Control

From cognifront

Experiment 1: Introduction to Arduino and Digital I/O Control

Objective

To understand digital input/output operations by interfacing LEDs and push buttons with an Arduino board.

Theory

Arduino digital pins can act as INPUT or OUTPUT.

  • INPUT mode detects HIGH (5V) or LOW (0V) signals.
  • OUTPUT mode drives devices like LEDs using HIGH or LOW logic.

Push buttons provide user input, while LEDs indicate output response.

Components Required

  • Arduino Uno Microcontroller
  • USB Data Cable
  • Patch Cords
  • LED Bar

Task

  1. Connect LEDs and push buttons to Arduino.
  2. Write a program to turn LEDs ON/OFF based on button press.
  3. Observe the LED response and monitor button status using Serial Monitor.

Arduino Code

<syntaxhighlight lang="cpp"> int led1 = 8, led2 = 9; int button1 = 2, button2 = 3;

void setup() {

 pinMode(led1, OUTPUT); pinMode(led2, OUTPUT);
 pinMode(button1, INPUT); pinMode(button2, INPUT);
 Serial.begin(9600);

}

void loop() {

 int b1 = digitalRead(button1), b2 = digitalRead(button2);
 Serial.print("B1: "); Serial.print(b1);
 Serial.print(" | B2: "); Serial.println(b2);
 digitalWrite(led1, b1); digitalWrite(led2, b2);
 delay(100);

} </syntaxhighlight>

Observation

  • Button press → corresponding LED ON
  • Serial Monitor → displays button state

Conclusion

Demonstrates basic digital I/O control using Arduino.