Education

Education

Education

OLED Screen

Robo Explorers

To read the temperature and humidity from the DHT11 sensor we use the OLED screen. The OLED screen is made out of very very small leds which we call pixels. We activate these pixel LEDs in such a way that we can see texts or images on the screen.

The OLED works on the principle and technology of I2C.We will discuss more on this in the upcoming Robo Explorers Series!

Let’s dive into the code!



#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//WE IMPORT THE REQUIRED LIBRARIES FOR THE OLED


// WE DEFINE THE REQUIREMENTS FOR THE OLED
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1

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

void setup() {
  Serial.begin(9600);

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }

}

void loop() {

  display.clearDisplay(); // THIS LINE WILL CLEAR THE DISPLAY OF OLED
  display.setTextSize(1); // SET THE TEXT SIZE to 1
  display.setTextColor(SSD1306_WHITE); // WE CAN SET THE COLOR BY THIS COMMAND
  display.setCursor(0, 0); // SETTING THE CURSOR TO 0,0 COORDINATE

  display.println("TEMPERATURE IS"); // BY THESE LINES WE CAN DISPLAY THE TEMPERATURE ON THE OLED
  display.println(DHT.temperature);
  display.println("HUMIDITY IS"); // BY THESE LINES WE CAN DISPLAY THE HUMIDITY ON THE OLED
  display.println(DHT.humidity);
  display.display(); // WHEN WE ARE READY TO DISPLAY EVERYTHING WE USE THIS COMMAND TO DISPLAY ON THE SCREEN


}

Congratulations on completing all the lessons!

Start Over

Learn from a Professional

Book a Class

Socials

info.jumplabs@gmail.com

Call Us

+4550142069

+919560372931

Damgade 82, 6400 Sønderborg

© Jumplabs Inc. 2023

Reach out to Us

Socials

info.jumplabs@gmail.com

Call Us

+4550142069

+919560372931

Damgade 82, 6400 Sønderborg

© Jumplabs Inc. 2023

Reach out to Us