Mid-Senior Engineers: Reinvent your career with Robotics, earning $100k-$200k+ in the next 90 days. Learn More

OLED Display with Arduino Tutorial

Liz Miller Learn Robotics

About the Author, Liz Miller, Founder/CEO @ Learn Robotics

Liz graduated with a degree in Robotics Engineering from Worcester Polytechnic Institute and researched drones at UPenn's GRASP Lab. Liz is a former Raytheon Engineer, where she managed major $MM automation projects worldwide. Today, she's the driving force behind Learn Robotics, offering the Robotics Career Blueprint for Engineering Professionals and beginner courses through the Online Robotics Class. Liz is a third-generation entrepreneur who is all about the application of innovation in robotics, automation, and AI. Follow Liz on LinkedIn and Facebook.

Disclosure: Some of the links below are affiliate links. This means that, at zero cost to you, Learn Robotics will earn an affiliate commission if you click through the link and finalize a purchase. Learn Robotics is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a way for websites to earn advertising revenues by advertising and linking to Amazon.com.

Join our Private Discord Server, MakeRobots! Sign Up

In this tutorial I will show you how to use an OLED Display with Arduino. There are several types of displays available in the market, namely: LCD (Liquid Crystal Display), LED, OLED (Organic LED) and eInk display. LCD and OLED are the most common ones. In this post we will learn how to use OLED display with Arduino. Let’s begin.

Materials for this Project

To create this project, you’ll need the following materials:

  1. Arduino: We’ll use this controller as the brain of the project. I used the Arduino UNO but feel free to use whichever Arduino board you like (Mega, Nano or Micro). Just make sure you know the Pin mapping of your board.
  2. OLED Display: There are different types of OLED displays. The one I have used is 1.3″ I2C module. It has a resolution of 128 x 64 and works with the SH1106 Driver.
  3. Proper driver for the display: I used the SH1106 driver, so I installed the Adafruit_SH1106 library for that. Make sure you check what driver your display needs. It should be mentioned in the description of product on the website.

Understanding I2C Protocol:

As our display module uses I2C interface for communication, We must first understand the I2C Protocol.

I2C is a communication method which only uses 4 pins. In this Protocol, multiple Masters (Microcontrollers) can be connected to multiple slaves (Sensors) using 4 pins: VCC, GND, SDA and SCL.

I2C Protocol Diagram

In I2C data is transferred in form of packets. These packets contain frames of data.
I2C Message DiagramFirst frame contains a “Start Condition”, when a device reads the start frame it gets ready for incoming data. Next frame contains the address of the device. Then there are two data frames which contain the instructions. Finally the Stop condition indicates the end of the packet.

The Ack/Nack Bits are the acknowledge bits , when set of data is received successfully acknowledge bit is sent. This was a short explanation of I2C, for in depth information refer I2C Wiki.

OLED Arduino Wiring Diagram

OLED Arduino Fritzing diagram

Connections are very simple, just follow the diagram and you’re done. OLED displays are very power efficient and works perfect on 3v. After the connections are made, it’s time to upload the test code.

Program OLED Display with Arduino

Before we can upload the code, there are a couple of libraries that needs to be installed. Below I have listed the libraries needed:

The Wire.h library must be already installed in IDE, Download the SH1106 library from here.
Click “Clone or Download” on the right. Then choose “Download ZIP.” Extract the Zip file and copy it into Arduino >> Libraries.

Then , create a new sketch, and write the code given below:

#include <Wire.h>
#include <Adafruit_SH1106.h>

#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);

void setup()
{
  Serial.begin(9600);
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);

  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop()
{
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello");
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println("World!");
  display.display();
  delay(2000);
}

Upload the code to the Arduino, and you should see a “Hello World!” message on the screen. You can also try the example code present in Arduino IDE.

Goto File >> Examples >> Adafruit_SH1106-Master >> sh1106_128x64_i2c

Upload the example code to see some cool animations.

OLED SH1106

Final Note

With that complete, now you can use the OLED display for your projects. These displays can be very useful for projects such as a weather station, robot display, or electronic dice. The possibilities are endless once you learn the basic configuration.

Arduino OLED Hello World

If you enjoyed this tutorial, consider buying a copy of my Mini WIFI robot eBook. I show you how to design, build, and program your very own custom robot that can be controlled over WIFI. Pick up your copy, today!

Experienced Engineer (Mechanical, Electrical, Computer, Software): If I offered to help you upgrade your engineering career to robotics, earning $100k-$200k+ in the next 90 days, would you take me up on that offer? Click here for details.
Liz Miller Learn Robotics

🚀 Pre-Launch: Become a "MakeR" with MakeRobots!

Hey Reader, 👋

Liz Miller, Founder/CEO, here with some Exciting News!

Learn Robotics just acquired MakeRobots™, an Online Robotics Community, and are prepping its Official Learn Robotics Debut in Late 2023.

MakeRobots™ is your one-stop-shop for learning, gaining coding, electronics, and robotics skills, connecting, and building robots for one low monthly membership!

Join MakeRobots™ at our Special Pre-launch Rate!
🤖 Access our Private Community & Robotics Courses
💬 Network, Collaborate, Connect with Other Makers
🔓 Only $5.99/month – locked in for life
⏱️ Pre-launch deal is Limited to the first 1,000 subscribers

This is a perfect opportunity for you to get into the fastest growing robotics community on the internet, at our ground-level, pre-launch membership rates.

👇 Click the button below to Claim your Pre-launch Membership and become a MakeR in the MakeRobots Community, today!

Learn Robotics Botly Favicon

MORE LEARN ROBOTICS ARTICLES