Education

Education

OLED Screen

Introduction to OLED Displays

An OLED (Organic Light-Emitting Diode) display is a small screen that can display text, graphics, and animations without needing a backlight. Unlike LCDs, OLEDs produce their own light, making them more energy-efficient and capable of displaying deep blacks and vibrant colors.

In this chapter, we will explore how OLED screens work, how they differ from traditional displays, and how to use them to display real-time temperature and humidity data from the DHT11 sensor using an Arduino Nano.

How Does an OLED Display Work?

OLED displays are made of organic compounds that emit light when an electric current is applied. The screen consists of thousands of tiny pixels that can turn on and off individually, allowing for sharp and efficient image rendering.

Key Features of OLED Displays

  • Self-emitting light: No need for a backlight like LCDs.

  • High contrast: OLED screens can display true blacks because pixels can turn off completely.

  • Thin and lightweight: Requires fewer layers than LCDs, making it thinner.

  • Power-efficient: Uses less power compared to LED/LCD screens.

The Science Behind OLED Technology

An OLED display is made up of multiple layers:

  1. Anode (+ terminal): Removes electrons when current flows.

  2. Organic Layers: These layers emit light when charged.

  3. Cathode (- terminal): Injects electrons to activate the organic layers.

  4. Substrate: The glass or plastic base that holds everything together.

When voltage is applied:

  • Electrons move from the cathode (- terminal) to the organic layer.

  • A hole (missing electron) moves from the anode (+ terminal) to the organic layer.

  • When they meet, energy is released in the form of light—this is how OLED pixels light up.

Different organic compounds emit different colors, allowing full-color OLED screens to exist.

How We Will Use OLED in This Project

We will use an OLED display to show temperature and humidity values from the DHT11 sensor in real time. The OLED will update every few seconds to reflect the latest data.

What the Display Will Show

  1. Temperature (°C) from the DHT11 sensor.

  2. Humidity (%) from the DHT11 sensor.

  3. A simple "Weather Station" title on top.

How to connect OLED Screen on the Blue Elixer Board

Code Breakdown: Displaying Temperature & Humidity on OLED

Now, let's write a program to read temperature & humidity from the DHT11 sensor and display the values on the OLED screen.

Step 1: Including Required Libraries

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h

  • Wire.h handles I2C communication between the OLED and Arduino.

  • Adafruit_GFX.h and Adafruit_SSD1306.h are graphics libraries that help display text and images on the OLED screen.

Step 2: Defining OLED Display Parameters

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1  // Reset pin (not needed for I2C)
  • The OLED screen size is defined as 128x64 pixels.

  • OLED_RESET -1 means we are not using a reset pin (since it's not required in I2C mode).

Step 3: Creating the OLED Display Object

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  • This creates an OLED object named display, which will be used for text rendering and updates.

Step 4: Initializing the OLED Display in setup()

if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
}
  • The display.begin() function initializes the OLED with address 0x3C (default I2C address for SSD1306).

  • If the OLED is not detected, the program prints "SSD1306 allocation failed" in the serial monitor and stops execution.

Step 5: Displaying a Welcome Message

display.clearDisplay();
display.setTextSize(5);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("LEAP");
display.display();
delay(1000);
  • Clears the screen (clearDisplay() ensures no previous data is shown).

  • Sets text size to 5 (setTextSize(5)) to make the text large.

  • Sets text color to white (setTextColor(SSD1306_WHITE)).

  • Moves cursor to (0,0) (setCursor(0,0)) to position the text.

  • Prints "LEAP" on the OLED screen.

  • Updates the display with display.display().

  • Pauses for 1 second (delay(1000)) so the message stays visible for a while.

Step 6: Displaying Temperature and Humidity Data in loop()

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("TEMPERATURE IS");
display.println(DHT.temperature);
display.println("HUMIDITY IS");
display.println(DHT.humidity);
display.display();

Breaking It Down

  1. Clears the screen to remove old data (clearDisplay()).

  2. Sets text size to 1 (setTextSize(1)) to fit more data on the screen.

  3. Sets cursor at the top (setCursor(0, 0)).

  4. Displays "TEMPERATURE IS".

  5. Prints the actual temperature reading (DHT.temperature).

  6. Displays "HUMIDITY IS".

  7. Prints the actual humidity reading (DHT.humidity).

  8. Updates the OLED screen with display.display().

Summary of OLED Functionality in This Code

Function

Purpose

display.begin(SSD1306_SWITCHCAPVCC, 0x3C)

Initializes the OLED display

display.clearDisplay()

Clears the screen before updating

display.setTextSize(size)

Sets the size of the text

display.setTextColor(SSD1306_WHITE)

Sets text color to white

display.setCursor(x, y)

Positions the text on the screen

display.println("Text")

Prints text or sensor data on OLED

display.display()

Updates the display with new content

Fun Activity!

In this activity, you will program your Arduino Nano and OLED display to show a fun animated introduction screen with your name and a short message. The text will appear letter by letter, creating a cool animation effect!

Imagine using this to display your name tag, a greeting, or a fun fact about yourself!

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128  // OLED display width
#define SCREEN_HEIGHT 64  // OLED display height
#define OLED_RESET -1  // Reset pin not needed for I2C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

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

  // Initialize the OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }

  display.clearDisplay();  // Clear the screen
}

void loop() {
  // Define the name and subtext
  String name = "JumpLabs";
  String subtext = "Bringing Families Closer";

  // Display name with animation
  displayTextWithAnimation(name, 10, 20, 2);  // Text appears at position (10,20) with size 2
  
  delay(1000); // Short pause before displaying the subtext

  // Display subtext with animation
  displayTextWithAnimation(subtext, 10, 40, 1);  // Subtext appears at position (10,40) with size 1

  delay(3000); // Pause before repeating the animation
}

void displayTextWithAnimation(String text, int x, int y, int textSize) {
  display.clearDisplay();  // Clear screen before each animation
  display.setTextSize(textSize);
  display.setTextColor(SSD1306_WHITE);

  for (int i = 0; i <= text.length(); i++) {
    display.setCursor(x, y);
    display.println(text.substring(0, i)); // Print text letter by letter
    display.display();
    delay(200); // Delay for animation effect
  }
}

How It Works

  1. The OLED screen will start blank.

  2. The name will appear one letter at a time on the screen.

  3. After the name is complete, the message will appear below it in the same way.

  4. The text will then stay on the screen, repeating the animation every few seconds.

What You’ll See on the OLED Screen

  1. The screen starts blank.

  2. The name ("JumpLabs") appears letter by letter at the top.

  3. A short pause before the next animation.

  4. The subtext ("Bringing Families Closer") appears letter by letter.

  5. The text stays for 3 seconds, then repeats the animation.

Socials

info.jumplabs@gmail.com

Call Us

+4550142069

+91 9910566229

Damgade 82, 6400 Sønderborg

© Jumplabs Inc. 2023

Reach out to Us

Socials

info.jumplabs@gmail.com

Call Us

+4550142069

+91 9910566229

Damgade 82, 6400 Sønderborg

© Jumplabs Inc. 2023

Reach out to Us

Socials

info.jumplabs@gmail.com

Call Us

+4550142069

+91 9910566229

Damgade 82, 6400 Sønderborg

© Jumplabs Inc. 2023

Reach out to Us