SE322 /

Lab: Arduino Hardware

Prof. Anis Koubaa
Professor

Prof. Anis Koubaa

SE322: Internet of Things Applications
Spring 2025
College of Engineering, Alfaisal University

Arduino Hardware Lab

1. Introduction to Arduino Hardware

This lab introduces fundamental Arduino hardware components and sensors commonly used in IoT applications. Students will learn to interface with various sensors and actuators while understanding basic electronic principles.

1.1 Basic Components Overview

  • Arduino UNO Board: The main microcontroller board featuring an ATmega328P processor, digital/analog I/O pins, and USB connectivity for programming.
  • Breadboard: A solderless prototyping board for creating temporary circuits and testing connections.
  • Jumper Wires: Male-to-male, female-to-female, and male-to-female wires for making electrical connections.
  • Resistors: Various resistors (220Ω, 10kΩ) for current limiting and pull-up/pull-down configurations.

1.2 Sensors and Actuators

Input Devices (Sensors)
  • DHT11 Temperature & Humidity Sensor: Digital sensor for environmental monitoring
  • Photoresistor (LDR): Light-dependent resistor for measuring ambient light levels
  • Push Buttons: Digital input for user interaction
Output Devices (Actuators)
  • LEDs: Light-emitting diodes for visual indicators
  • Buzzer: Piezo buzzer for audio feedback
  • LCD Screen: 16x2 character LCD for displaying sensor data

1.3 Lab Experiments

Experiment 1: LED Control

Basic digital output control using LEDs with different patterns:

  • Single LED blinking
  • Multiple LED sequences
  • LED brightness control using PWM
Experiment 2: Temperature Monitoring

Using the DHT11 sensor to measure environmental conditions:

  • Temperature and humidity readings
  • Data display on LCD screen
  • Temperature-triggered alerts using buzzer
Experiment 3: Interactive Light System

Combining multiple components:

  • Light level detection using photoresistor
  • Automatic LED control based on ambient light
  • User override using push buttons

1.4 Hardware Setup & Connections

Circuit Diagrams and Connections
LED Control Setup
LED Circuit Connection

LED Circuit Connection Diagram

LED Blink Code

// LED Blink Example
const int ledPin = 13;

void setup() {
    pinMode(ledPin, OUTPUT);
}

void loop() {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
}
                                                    
Temperature Sensor Setup
DHT11 Circuit Connection

DHT11 Circuit Connection Diagram

DHT11 Code

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
    
    delay(2000);
}
                                                    
Interactive Light System Setup
LDR Circuit Connection

LDR Circuit Connection Diagram

Light System Code

const int ldrPin = A0;
const int ledPin = 13;
const int buttonPin = 2;

int threshold = 500;
bool manualMode = false;

void setup() {
    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT_PULLUP);
    Serial.begin(9600);
}

void loop() {
    if (digitalRead(buttonPin) == LOW) {
        manualMode = !manualMode;
        delay(200);
    }

    if (!manualMode) {
        int lightLevel = analogRead(ldrPin);
        digitalWrite(ledPin, lightLevel < threshold);
    }
}
                                                    
LCD Display Setup
LCD Circuit Connection

LCD Display Connection Diagram

LCD Display Code

#include 

// Initialize LCD (pins: RS=12, E=11, D4=5, D5=4, D6=3, D7=2)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
    // Set up the LCD's number of columns and rows
    lcd.begin(16, 2);
    
    // Print a message to the LCD
    lcd.print("Hello, World!");
}

void loop() {
    // Set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0)
    lcd.setCursor(0, 1);
    
    // Print the number of seconds since reset
    lcd.print(millis() / 1000);
    
    delay(1000);
}
                                                    

Note: Make sure to install the LiquidCrystal library in your Arduino IDE before running this code. The LCD display requires proper voltage (5V) and contrast adjustment through the potentiometer for optimal visibility.

Learning Outcomes

After completing this lab, students will be able to:

  • Interface basic sensors and actuators with Arduino
  • Write and understand Arduino sketches for hardware control
  • Design simple interactive IoT prototypes
  • Troubleshoot common hardware connectivity issues

Review Questions

Question 1

Explain the three key characteristics of IoT systems and provide an example for each characteristic from a real-world application.

Question 2

How has IoT evolved from the 1980s to present day? Discuss the major technological advancements that have shaped this evolution.

Question 3

What are the projected market trends for IoT from 2023 to 2030? Discuss the key drivers behind this growth.

Question 4

Compare and contrast AIoT, Edge Computing, and 5G in terms of their contributions to IoT advancement.

Question 5

Discuss the main challenges facing IoT implementation, particularly in terms of security and environmental impact.