What is the OLED SSD1306?

The 0.96" OLED SSD1306 is a crisp, low-power screen that supports 128x64 pixels in monochrome. Unlike LCDs, OLEDs emit their own light, meaning:

  • No need for a backlight
  • Better contrast
  • Smaller and more energy-efficient

It communicates with the Arduino using I2C, saving pins and simplifying wiring.

 

Components Used

  • Arduino UNO (or compatible board)
  • OLED 128x64 I2C display (SSD1306 driver)
  • Analog joystick
  • Jumper wires + breadboard

 

Wiring Diagram

 

OLED PinArduino UNO
GNDGND
VCC5V
SCLA5
SDAA4
Joystick VRxA0

 

Required Arduino Libraries

Before uploading the code, install these via the Library Manager:

  • Adafruit GFX
  • Adafruit SSD1306

Go to: Sketch > Include Library > Manage Libraries
Search for “Adafruit GFX” and “Adafruit SSD1306” → Install both

 

Arduino Code

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int lastValue = -1;

void setup() {
  pinMode(A0, INPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    while (true); // Freeze if screen fails
  }

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("SOSLab.net");
  display.display();
  delay(1000); // Welcome screen
}

void loop() {
  int readJoy = analogRead(A0);

  if (abs(readJoy - lastValue) > 2) {
    display.clearDisplay();

    display.setTextSize(1);
    display.setCursor(0, 0);
    display.println("Joystick Reading:");

    display.setTextSize(2);
    display.setCursor(0, 20);
    display.print(readJoy);

    display.setTextSize(1);
    display.setCursor(0, 50);
    display.print("soslab.net");

    display.display();
    lastValue = readJoy;
  }

  delay(10); // Smooth update
}

Why Use abs(readJoy - lastValue) > 2?

Analog sensors like joysticks often produce minor noise, even when still.
Using this line reduces unnecessary screen updates, preventing flickering and saving resources.

 

Project in Action

 

Summary

  • Displayed analog joystick values on a 128x64 OLED
  • Used I2C for simple wiring
  • Prevented flickering with change detection
  • Fully working and scalable for other sensor readings

 

Check out our previous article using LCD 1602 I2C:
"Displaying Joystick Value on an LCD 1602 with Arduino"