
Sea Voyage
Robo Explorers 2
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:
Anode (+ terminal): Removes electrons when current flows.
Organic Layers: These layers emit light when charged.
Cathode (- terminal): Injects electrons to activate the organic layers.
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
Temperature (°C) from the DHT11 sensor.
Humidity (%) from the DHT11 sensor.
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
Wire.h
handles I2C communication between the OLED and Arduino.Adafruit_GFX.h
andAdafruit_SSD1306.h
are graphics libraries that help display text and images on the OLED screen.
Step 2: Defining OLED Display Parameters
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
This creates an OLED object named
display
, which will be used for text rendering and updates.
Step 4: Initializing the OLED Display in setup()
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
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()
Breaking It Down
Clears the screen to remove old data (
clearDisplay()
).Sets text size to
1
(setTextSize(1)
) to fit more data on the screen.Sets cursor at the top (
setCursor(0, 0)
).Displays "TEMPERATURE IS".
Prints the actual temperature reading (
DHT.temperature
).Displays "HUMIDITY IS".
Prints the actual humidity reading (
DHT.humidity
).Updates the OLED screen with
display.display()
.
Summary of OLED Functionality in This Code
Function | Purpose |
---|---|
| Initializes the OLED display |
| Clears the screen before updating |
| Sets the size of the text |
| Sets text color to white |
| Positions the text on the screen |
| Prints text or sensor data on OLED |
| 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!
How It Works
The OLED screen will start blank.
The name will appear one letter at a time on the screen.
After the name is complete, the message will appear below it in the same way.
The text will then stay on the screen, repeating the animation every few seconds.
What You’ll See on the OLED Screen
The screen starts blank.
The name ("JumpLabs") appears letter by letter at the top.
A short pause before the next animation.
The subtext ("Bringing Families Closer") appears letter by letter.
The text stays for 3 seconds, then repeats the animation.