Arduino nano OLED Display

The Arduino Nano OLED Display drives a small SSD1306‑based OLED screen (typically 128×64 or 128×32 I2C) using the Arduino Nano board. It is used in status panels, meters, menus, and other projects requiring compact text and graphics output.

Arduino Nano OLED Display

The OLED Display project demonstrates how to connect and program an I2C OLED module (usually 0.96" monochrome, 128×64 or 128×32) with an Arduino Nano. The Nano sends data over I2C to the SSD1306 driver chip, enabling you to display text, numbers, simple graphics, and even small icons or bitmaps on the OLED screen.

What Is an OLED Display?

An OLED (Organic Light‑Emitting Diode) display consists of tiny self‑emitting pixels that glow when a voltage is applied, making it very bright, high‑contrast, and power‑efficient compared to LCDs. Most hobby modules use the SSD1306 driver and expose I2C pins (SCL, SDA, VCC, GND), making them easy to interface with the Arduino Nano’s A4 (SDA) and A5 (SCL) pins.

Common sizes include 128×64 (for more detailed text and graphics) and 128×32 (for compact status lines); both use the same basic wiring and code approach.

Components Needed

  • Arduino Nano
  • OLED display module (I2C, SSD1306‑based, 128×64 or 128×32)
  • Jumper Wires
  • Breadboard

Circuit Setup

1. Connect OLED to Arduino Nano:

Typical I2C OLED module pins:

  • VCC → 5V on the Arduino Nano (most modules have an internal 5V→3.3V regulator).
  • GND → GND on the Arduino Nano.
  • SDA → A4 (or SDA) on the Arduino Nano.
  • SCL → A5 (or SCL) on the Arduino Nano.

If your module has additional pins (like RESET or D/C), connect RESET to the Arduino’s RESET or leave it unconnected if the library lets you share the MCU reset; D/C is usually not needed on I2C‑only modules.

How the OLED Works

The Arduino uses the I2C bus to send commands and data to the SSD1306 driver, which manages the internal display memory (frame buffer). The library functions such as `display.println()` or `display.drawPixel()` update this buffer, and a final `display.display()` command refreshes the screen so the pixels appear on the OLED.

By setting the correct screen size (e.g., 128×64) and I2C address (often 0x3C or 0x3D), the same code structure works across different modules; only the width and height constants may need adjustment.

Program: Arduino Nano OLED Display (Hello OLED + Scrolling Text)
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// Screen dimensions (change for 128x32)
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// I2C address (check your module; 0x3C or 0x3D)
#define OLED_ADDR 0x3C

// Reset pin; use -1 if sharing with Arduino reset
#define OLED_RESET -1

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  Wire.begin();
  Serial.begin(9600);
  
  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
    Serial.println(F("OLED allocation failed"));
    for (;;);
  }
  
  display.display();
  delay(1000);
  
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println(F("HELLO"));
  display.println(F("ARDUINO"));
  display.println(F("NANO"));
  display.display();
  delay(1000);
}

void loop() {
  // Clear and redraw a simple scrolling line
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 20);
  display.print(F("OLED Status: "));
  display.println(millis() / 1000);
  display.display();
  
  delay(250);
}

// To install required libraries in Arduino IDE:
// 1) Sketch → Include Library → Manage Libraries
// 2) Search for "Adafruit SSD1306"
// 3) Install both "Adafruit SSD1306" and "Adafruit GFX Library"

Instructions

1. Circuit Setup:

Wire the OLED module to the Arduino Nano as described in the circuit section, ensuring VCC, GND, SDA, and SCL are connected correctly and that the display’s power and the Arduino share a common ground.

2. Install Libraries:

In the Arduino IDE go to Sketch → Include Library → Manage Libraries, and install:

  • Adafruit SSD1306
  • Adafruit GFX Library

3. Adjust Screen Size and Address:

If your module is 128×32 instead of 128×64, change `SCREEN_HEIGHT` to 32 and adjust the cursor positions accordingly. Check the module’s datasheet or markings to confirm the I2C address (often 0x3C or 0x3D) and set `OLED_ADDR` to match.

4. Code Upload and Testing:

Upload the OLED code to the Arduino Nano via USB. The screen should first show the Adafruit splash screen, then clear and display the text "HELLO ARDUINO NANO". In the loop, it will update a line like "OLED Status: 3" that counts seconds roughly from the Arduino’s `millis()`.

Drawing Text and Graphics

Beyond basic text, you can draw lines, rectangles, filled shapes, and small bitmaps. For example:

Drawing basic shapes on OLED
void drawTest() {
  display.clearDisplay();
  
  // Draw a white pixel
  display.drawPixel(10, 10, SSD1306_WHITE);
  
  // Draw a line
  display.drawLine(0, 20, 127, 20, SSD1306_WHITE);
  
  // Draw a rectangle
  display.drawRect(10, 30, 40, 20, SSD1306_WHITE);
  
  // Fill a small box
  display.fillRect(60, 30, 40, 20, SSD1306_WHITE);
  
  // Add text
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 50);
  display.println(F("TEST SHAPES"));
  
  display.display();
}

// Then call drawTest() from setup() or loop().

Applications

Status & Info Panels: Use the OLED as a compact display for sensor values (temperature, humidity, voltage) or system status messages in robots, weather stations, or IoT devices.

Menus and User Interfaces: Create simple menus, settings screens, or project selection interfaces, using buttons or encoders to navigate.

Data Loggers and Meters: Display numeric readings, bar graphs, or simple charts for loggers, energy meters, or experimental setups.

Troubleshooting

  • No display or black screen? Check the SDA/SCL wiring, I2C address, and that the proper libraries (Adafruit SSD1306 + GFX) are installed; also verify the display height/width constants match your module.
  • Garbled graphics or garbage on screen? Ensure the I2C pull‑ups are present (many modules include them); avoid long or noisy I2C lines.
  • Library compilation errors? Install both Adafruit SSD1306 and Adafruit GFX; older library versions may need updating for Arduino Nano ESP32 or newer cores.

Best Practices and Notes

  • Always clear the display buffer and call `display.display()` after drawing operations so changes appear on the screen.
  • Use small text sizes and limited graphics where possible to keep updates fast and avoid flicker on larger scenes.
  • Avoid leaving bright, static images on the screen for long periods to reduce OLED burn‑in risk.

Extensions and Ideas

You can extend this project by displaying real‑time sensor data (e.g. temperature or LDR level) on the OLED, or by drawing a small bar graph, or by using a menu system with an encoder or buttons, or even by loading custom bitmaps (converted from images) to show logos or simple animations.