How to Connect an OLED Display to an Arduino Uno - Step-by-Step Tutorial

How to Connect an OLED Display to an Arduino Uno - Step-by-Step Tutorial

Welcome to my blog! In this tutorial, I’ll show you how to connect a 0.96 inch OLED display to an Arduino Uno and create a scrolling message. This project is perfect for beginners and will help you get started with using OLED displays in your Arduino projects.




Materials Needed:


•Arduino Uno

•0.96 inch OLED I2C Display 

•(HW-239A)Jumper wires

•Breadboard (optional)

Step 1: Connections


First, let's connect the OLED display to the Arduino Uno. Here’s how you should connect the pins:

VCC to 3.3V (or 5V if required)

GND to GND

SCL to A5

SDA to A4Step 

2: Install Libraries


Make sure you have the following libraries installed in your Arduino IDE/droid(if you use Android app.

Adafruit SSD1306

Adafruit GFX Library

If you are using the Arduinodroid app, search for and install these libraries from the library manager.

Or follow these steps to install Adafruit SSD1306 and Adafruit GFX libraries 

Step 1: Open Arduinodroid app and click on three dots


Step 2: Now click on libraries 


Step 3: Now click on mannage libraries 

Step 4: Now click on Available option and search for Adafruit GFX and Adafruit SSD1306 and install.



You can also follow this circuit diagram:








Step 3: The Code

Here’s the code for displaying a scrolling message on your OLED display:

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

#define SCREEN_WIDTH 128   // OLED display width, in pixels
#define SCREEN_HEIGHT 64   // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET    -1   // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  // Initialize the OLED display with I2C address 0x3C (for the 128x64 display)
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    for(;;); // Don't proceed, loop forever if OLED initialization fails
  }

  display.clearDisplay();   // Clear the display buffer
  display.setTextSize(1);   // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Set text color to white

  // Calculate text dimensions
  String text = "Shiva the CREATOR";
  int16_t x = (SCREEN_WIDTH - (text.length() * 6)) / 2; // Center horizontally
  int16_t y = (SCREEN_HEIGHT - 8) / 2; // Center vertically

  display.setCursor(x, y); // Set the text position
  display.println(text);    // Print the centered text
  display.display();        // Update the display
}

void loop() {
  // No need for any continuous operations in the loop for static display
}



Step 4: Upload the Code

1.Open the Arduino IDE or Arduinodroid           app and create a new sketch.

2.Copy and paste the provided code into the     new sketch.

3.Connect your Arduino Uno to your                   computer or mobile device via an 
   OTG  cable.

4.Select the correct board and port 
   in the IDE settings. Compile and upload 
   the code.

Conclusion

That's it! Your OLED display should now be showing a scrolling message. This simple project is a great way to get started with using OLED displays in your Arduino projects. Feel free to modify the code to display different messages or add more features.If you have any questions or run into any issues, leave a comment below or check out my Full tutorial in .y YouTube channel. Happy coding!

Post a Comment

Previous Post Next Post