Arduino SSD1306 OLED Display: Wiring, Code and Simulator

To build this Arduino SSD1306 OLED Display project you need an Arduino Uno and an SSD1306 OLED display. A 128×64 SSD1306 OLED over I²C, drawn with Adafruit GFX: text, a frame and a moving ball. Make the 4 connections in the wiring table, upload the Arduino C++ code, and watch the ball roll. Each frame, display() sends all 1024 bytes of pixels over two wires.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1SSD1306 OLED displaySSD1306 over I²C: DATA (SDA) to A4, CLK (SCL) to A5, VIN to 5V, GND to GND. Address 0x3C.

Wiring

#FromTo
1Arduino Uno A4SSD1306 OLED display DATA
2Arduino Uno A5SSD1306 OLED display CLK
3Arduino Uno 5VSSD1306 OLED display VIN
4Arduino Uno GNDSSD1306 OLED display GND

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an SSD1306 OLED display from the parts palette.
  3. Wire 1. Connect Arduino Uno A4 to SSD1306 OLED display DATA.
  4. Wire 2. Connect Arduino Uno A5 to SSD1306 OLED display CLK.
  5. Wire 3. Connect Arduino Uno 5V to SSD1306 OLED display VIN.
  6. Wire 4. Connect Arduino Uno GND to SSD1306 OLED display GND.
  7. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  8. Run it. Press Run. Watch the ball roll. Each frame, display() sends all 1024 bytes of pixels over two wires.

Arduino C++ code

// OLED: draw text and shapes on a 128x64 SSD1306 over I2C (address 0x3C).
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);

void setup() {
  Serial.begin(9600);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("SSD1306 not found. Check SDA (A4) and SCL (A5).");
    for (;;) {}
  }
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(4, 4);
  display.println("Hello!");
  display.drawRect(0, 0, 128, 64, SSD1306_WHITE);
  display.display();
  Serial.println("Drawn.");
}

void loop() {
  static int x = 8;
  display.fillRect(1, 40, 126, 20, SSD1306_BLACK);
  display.fillCircle(x, 50, 6, SSD1306_WHITE);
  display.display();
  x = x >= 120 ? 8 : x + 4;
}

What to try

Watch the ball roll. Each frame, display() sends all 1024 bytes of pixels over two wires.

Frequently asked questions

How do I wire the SSD1306 OLED Display project on an Arduino Uno?

Make 4 connections: Arduino Uno A4 to SSD1306 OLED display DATA; Arduino Uno A5 to SSD1306 OLED display CLK; Arduino Uno 5V to SSD1306 OLED display VIN; Arduino Uno GND to SSD1306 OLED display GND.

What parts do I need for this Arduino project?

An Arduino Uno and an SSD1306 OLED display.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

A 128×64 SSD1306 OLED over I²C, drawn with Adafruit GFX: text, a frame and a moving ball.

More Arduino Uno projects