Experiment 1: Introduction to Arduino and Digital I/O Control
Appearance
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 (or compatible board)
- USB cable, Breadboard, Jumper wires
- 2 × LEDs (with 220Ω resistors)
- 2 × Push buttons (with 10kΩ pull-down resistors)
Task
- Connect LEDs and push buttons to Arduino.
- Write a program to turn LEDs ON/OFF based on button press.
- 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.