Week 10 Output devices

Exploring output devices this week showed me how important feedback is in user experience. Whether it's lights, sounds, or displays, output devices bring the system to life by communicating information clearly and effectively.

Learning Objectives

1 Introduction

πŸ’‘1.1 LED Display Introduction

An LED display is a module designed to display letters, numbers, and symbols. It is widely used in industrial applications such as digital clocks and temperature displays.I am using an I2C 1602A LCD.

1

Note: If the LCD backlight is too dim, adjust the blue potentiometer on the back of the LCD module.

πŸ“œ1.2 Working Principle of I2C 1602A LCD

The I2c 1602 LCD is a common 16Γ—2 character liquid crystal display often used in embedded systems such as Arduino or microcontroller projects. It can display 2 rows with up to 16 characters per row. The common interface methods include parallel interface (4-bit or 8-bit mode) and I2C interface (via the PCF8574 expansion module).

1 1

πŸ› 1.3 How to Use an LED Display to Show "Hello World!"

Components Required: Arduino board, LED display module, and jumper wires.

Start β†’ Initialize β†’ Display "Hello World!" on the LED screen β†’ End

πŸ”Ή1.3.1 Install Library

1

πŸ”Ή1.3.2 Connecting I2C LCD to Arduino

LCD PinArduino Uno Pin
VCC5V
GNDGND
SDAA4
SCLA5
1

πŸ” 1.4 I2C Address Scanning

The first time testing the code, the display did not show any content, so I used the following code to check the I2C Address.

1

#include <Wire.h>

void setup() {
    Serial.begin(9600);
    while (!Serial);
    Serial.println("I2C Scanner is running...");
    Wire.begin();
}

void loop() {
    Serial.println("Scanning...");
    byte count = 0;
    for (byte address = 1; address < 127; address++) {
        Wire.beginTransmission(address);
        if (Wire.endTransmission() == 0) {
            Serial.print("I2C device found at address 0x");
            Serial.println(address, HEX);
            count++;
        }
        delay(5);
    }
    if (count == 0) Serial.println("No I2C devices found!");
    Serial.println("Scan complete.\n");
    delay(5000);
}
    

πŸ›  My Troubleshooting Steps

πŸ“Œ 1.5 LCD Display Test Code

The correct I2C address is found(0x27οΌ‰, use the following test code:

1

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
    lcd.init();
    lcd.backlight();
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Hello, World!");
}

void loop() {}
    

Unfortunately,there was still no display content. I continued troubleshooting and found that the contrast needed to be adjusted. Finally, the test was completed.

Adjusting the Contrast

1

The test was finally successful!

1

2 Electronic Thermometer

This device uses the DS18B20 sensor as the temperature input and an I2C 1602 LCD as the output display.

2.1 DS18B20 Temperature Sensor

2.1.1 Introduction

DS18B20 is a common digital temperature sensor that uses a unique single-wire interface. Compared to analog temperature sensors, it is more functional, simple in hardware, easy to expand, and highly resistant to interference.

1 1

2.1.2 Specifications

Feature Specification
Power Supply DC 5V
Temperature Range -55 to +125℃
Communication Interface 1-Wire
Accuracy Β±0.5℃
Resolution 9-12 bits adjustable

2.2 Working Principle

2.2.1 Circuit Diagram

The pin configuration is as follows:

Pin Description
VCC Power Supply (5V)
GND Ground
I/O Data Line
1

2.2.2 Circuit Connections

1

2.3 Coding and Operation

The following Arduino code reads temperature from the DS18B20 sensor and displays it on an I2C 1602 LCD:

2.3.1 Install OneWire and DallasTemperature Libraries

1 #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <OneWire.h> #include <DallasTemperature.h> // LCD setup LiquidCrystal_I2C lcd(0x27, 16, 2); // DS18B20 setup #define ONE_WIRE_BUS 2 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void setup() { lcd.init(); lcd.backlight(); sensors.begin(); lcd.setCursor(0, 0); lcd.print("Temp Monitor"); } void loop() { sensors.requestTemperatures(); float temperatureC = sensors.getTempCByIndex(0); lcd.setCursor(0, 1); lcd.print("Temp: "); lcd.print(temperatureC); lcd.print(" C "); delay(1000); } 1
Code01 for this week Code02 for this week

Upload and Run Arduino Program

Step-by-Step Guide:

  1. πŸ”Œ Connect the Arduino Board: Use a USB cable to connect the Arduino to computer.
  2. πŸ–₯ Open Arduino IDEArduino official website.
  3. βš™οΈ Select Board & Port:
    • Go to Tools β†’ Board and select your Arduino Uno.
    • Go to Tools β†’ Port and select the correct port COM5.
  4. πŸ“‹ Code: Open the code.
  5. βœ… Compile & Upload Code:
    • Click the βœ”οΈ (checkmark icon) to verify the code.
    • Click the ⬆️ (upload icon) to upload the code.
  6. πŸ“Ÿ Open Serial Monitor:
    • Go to Tools β†’ Serial Monitor .(shift+alt+M)
    • Set baud rate to 9600.
    • Check code