// Arduino Lab — Marcus Jaijal · RNU University

Five Tasks.
One Board.

Five embedded systems exercises covering output control, variable signals, user input, alerts, and information display — each with full Arduino code and wiring guide.

Task 01

Basic Output Control

Control an LED using a digital output pin. The LED cycles through ON and OFF states with a delay — the foundation of all embedded output logic.

🔴 LED · Digital Output
Real-world use
Traffic lights, indicator lamps, status LEDs on industrial machines, power indicators on consumer electronics.
Components needed
Arduino Uno LED (any colour) 220Ω Resistor Breadboard Jumper wires
Wiring
ComponentPin / TerminalArduino
LED (+) AnodePin 13 (via 220Ω)
LED (−) CathodeGND
ResistorBetween Pin 13 & LEDIn series
task1_led_control.ino
/*
 * Task 1 — Basic Output Control
 * Blinks an LED connected to Pin 13.
 * Components: LED, 220Ω resistor
 */

const int LED_PIN = 13;

void setup() {
  pinMode(LED_PIN, OUTPUT);   // Set pin as output
  Serial.begin(9600);
  Serial.println("Task 1 — LED Control started");
}

void loop() {
  digitalWrite(LED_PIN, HIGH);  // LED ON
  Serial.println("LED: ON");
  delay(1000);                   // Wait 1 second

  digitalWrite(LED_PIN, LOW);   // LED OFF
  Serial.println("LED: OFF");
  delay(1000);                   // Wait 1 second
}
Task 02

Variable Control System

Use PWM (analogWrite) to gradually change LED brightness from 0 to full and back — simulating a fade effect through variable voltage output.

💡 PWM · Brightness Fade
Real-world use
Smart lighting systems, phone screen auto-brightness, motor speed control, fan speed regulators.
Components needed
Arduino Uno LED 220Ω Resistor Breadboard Jumper wires
Wiring — use a PWM-capable pin (~)
ComponentTerminalArduino
LED (+) AnodePin 9 ~ (via 220Ω)
LED (−) CathodeGND
task2_pwm_brightness.ino
/*
 * Task 2 — Variable Control System
 * Fades an LED in and out using PWM on Pin 9.
 * PWM range: 0 (off) → 255 (full brightness)
 */

const int LED_PIN = 9;  // Must be a PWM pin (~)

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Task 2 — PWM Brightness started");
}

void loop() {
  // Fade IN: 0 → 255
  for (int brightness = 0; brightness <= 255; brightness++) {
    analogWrite(LED_PIN, brightness);
    Serial.print("Brightness: ");
    Serial.println(brightness);
    delay(8);
  }

  // Fade OUT: 255 → 0
  for (int brightness = 255; brightness >= 0; brightness--) {
    analogWrite(LED_PIN, brightness);
    Serial.print("Brightness: ");
    Serial.println(brightness);
    delay(8);
  }

  delay(300);  // Pause before repeating
}
Task 03

User Interaction System

A push button controls an LED. Pressing the button toggles the LED on/off — demonstrating digital input reading and state management.

🔘 Button · Digital Input
Real-world use
Elevator call buttons, vending machines, keyboard switches, doorbell systems, manual override controls.
Components needed
Arduino Uno Push Button LED 220Ω Resistor 10kΩ Resistor (pull-down) Breadboard
Wiring
ComponentTerminalArduino
Button (one leg)Pin 2
Button (same leg)10kΩ → GND (pull-down)
Button (other leg)5V
LED (+) AnodePin 13 (via 220Ω)
LED (−) CathodeGND
task3_button_led.ino
/*
 * Task 3 — User Interaction System
 * Push button toggles LED on/off.
 * Uses debounce logic for clean input reading.
 */

const int BTN_PIN = 2;
const int LED_PIN = 13;

bool ledState      = false;
bool lastBtnState  = false;
unsigned long lastDebounce = 0;
const int DEBOUNCE_MS = 50;

void setup() {
  pinMode(BTN_PIN, INPUT);   // External pull-down resistor
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Task 3 — Button Toggle ready");
}

void loop() {
  bool btnReading = digitalRead(BTN_PIN);

  // Detect rising edge with debounce
  if (btnReading == true && lastBtnState == false) {
    if (millis() - lastDebounce > DEBOUNCE_MS) {
      ledState = !ledState;                 // Toggle state
      digitalWrite(LED_PIN, ledState);
      Serial.print("Button pressed — LED: ");
      Serial.println(ledState ? "ON" : "OFF");
      lastDebounce = millis();
    }
  }
  lastBtnState = btnReading;
}
Task 04

Alert / Notification System

A passive buzzer plays different tones to signal alerts. A button triggers the alarm — useful for safety-critical feedback systems.

🔔 Buzzer · Tone Output
Real-world use
Fire alarms, microwave beeps, reversing sensors in vehicles, hospital call systems, security intrusion alerts.
Components needed
Arduino Uno Passive Buzzer Push Button 10kΩ Resistor Breadboard
Wiring
ComponentTerminalArduino
Buzzer (+)PositivePin 8
Buzzer (−)NegativeGND
Button (one leg)Pin 2 + 10kΩ → GND
Button (other leg)5V
task4_buzzer_alert.ino
/*
 * Task 4 — Alert / Notification System
 * Button triggers a buzzer alarm with escalating tones.
 * Uses tone() for passive buzzer frequency control.
 */

const int BUZZER_PIN = 8;
const int BTN_PIN    = 2;

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(BTN_PIN, INPUT);
  Serial.begin(9600);
  Serial.println("Task 4 — Alert System ready");
}

void playAlert(int level) {
  switch (level) {
    case 1:  // Single short beep
      tone(BUZZER_PIN, 1000, 200);
      delay(300);
      break;
    case 2:  // Double beep
      tone(BUZZER_PIN, 1500, 150); delay(200);
      tone(BUZZER_PIN, 1500, 150); delay(200);
      break;
    case 3:  // Alarm siren
      for (int freq = 800; freq <= 2400; freq += 100) {
        tone(BUZZER_PIN, freq);
        delay(30);
      }
      noTone(BUZZER_PIN);
      break;
  }
}

int alertLevel = 1;

void loop() {
  if (digitalRead(BTN_PIN) == HIGH) {
    Serial.print("Alert level: ");
    Serial.println(alertLevel);
    playAlert(alertLevel);

    alertLevel++;
    if (alertLevel > 3) alertLevel = 1;  // Cycle 1 → 2 → 3 → 1
    delay(400);
  }
}
Task 05

Display / Information System

Read temperature and humidity from a DHT11 sensor and display live readings on a 16×2 LCD via I2C — a complete sensor-to-display pipeline.

📟 DHT11 · LCD I2C
Real-world use
Weather stations, HVAC dashboards, server room monitors, smart home displays, greenhouse climate control.
Components needed
Arduino Uno DHT11 Sensor 16×2 LCD (I2C) 10kΩ Resistor Jumper wires
Wiring
ComponentTerminalArduino
DHT11VCC5V
DHT11GNDGND
DHT11DATAPin 7 (+ 10kΩ to 5V)
LCD I2CVCC5V
LCD I2CGNDGND
LCD I2CSDAA4
LCD I2CSCLA5
Libraries required
DHT sensor library — Adafruit LiquidCrystal_I2C Wire.h (built-in)
task5_dht11_lcd.ino
/*
 * Task 5 — Display / Information System
 * Reads DHT11 sensor and shows temp + humidity on LCD.
 * Libraries: Adafruit DHT, LiquidCrystal_I2C
 */

#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define DHT_PIN    7
#define DHT_TYPE   DHT11

DHT dht(DHT_PIN, DHT_TYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Address 0x27, 16 cols, 2 rows

void setup() {
  Serial.begin(9600);
  dht.begin();

  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("  Sensor Ready  ");
  lcd.setCursor(0, 1);
  lcd.print(" Initializing.. ");
  delay(2000);
  lcd.clear();

  Serial.println("Task 5 — DHT11 + LCD ready");
}

void loop() {
  float humidity    = dht.readHumidity();
  float temperature = dht.readTemperature();  // Celsius

  if (isnan(humidity) || isnan(temperature)) {
    lcd.clear();
    lcd.print("Sensor error!");
    Serial.println("ERROR: DHT11 read failed");
    delay(2000);
    return;
  }

  // LCD Row 1: Temperature
  lcd.setCursor(0, 0);
  lcd.print("Temp:  ");
  lcd.print(temperature, 1);
  lcd.print(" C  ");

  // LCD Row 2: Humidity
  lcd.setCursor(0, 1);
  lcd.print("Hum:   ");
  lcd.print(humidity, 1);
  lcd.print(" %  ");

  Serial.print("Temp: "); Serial.print(temperature); Serial.print("°C  ");
  Serial.print("Humidity: "); Serial.print(humidity); Serial.println("%");

  delay(2000);  // Update every 2 seconds
}