0% found this document useful (0 votes)
5 views4 pages

Exp 2 (Ii)

The document outlines an experiment to interface an OLED display with an Arduino to show temperature and humidity readings using a DHT11 sensor. It includes a list of required components, circuit connections, and detailed instructions for installing necessary libraries. The Arduino program provided reads the sensor data and displays it on the OLED screen, with a successful result of displaying temperature and humidity values.

Uploaded by

kazirabiya785
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Exp 2 (Ii)

The document outlines an experiment to interface an OLED display with an Arduino to show temperature and humidity readings using a DHT11 sensor. It includes a list of required components, circuit connections, and detailed instructions for installing necessary libraries. The Arduino program provided reads the sensor data and displays it on the OLED screen, with a successful result of displaying temperature and humidity values.

Uploaded by

kazirabiya785
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No.

: 2 (ii)
Aim: To interface OLED with Arduino and write a program to print temperature and humidity
readings on it.

Component Required:

Sl No Components Quantity
1 Arduino UNO 1
2 DHT11 Temperature sensor 1
3 USB cable for Arduino UNO 1
4 Connecting wires --
5 OLED Display 128×64, SSD1306 I2C 1
Circuit Connection:
Theory :
The SSD1306 OLED I2C 128X64 OLED
Specification of OLED
Display module is a small
monochrome organic light- Size 0.96 inch
emitting diode (OLED) display
that is controlled through an Terminals 4
I2C interface. It has a display
resolution of 128×64 pixels, Pixels 128×64
and the SSD1306 is the
controller chip that manages the display. It’s Communication I2C only
commonly used for display purposes in various
electronics projects and is compact low power, VCC 3.3V-5V
and easily readable in low light conditions.
Operating Temperature -40℃ to +80℃

To control the OLED display you need the adafruit_SSD1306.h and the adafruit_GFX.h libraries.
Follow the next instructions to install those libraries.

1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries.
The Library Manager should open.
2. Type “SSD1306” in the search box and install the SSD1306 library from Adafruit.
3. Click install button to install library
4. If ask click on install all button to install library dependencies
5. After installing the SSD1306 library from Adafruit, type “GFX” in the search box and
install the library.
6. If ask click on install all button to install library dependencies
7. After installing the libraries, restart your Arduino IDE
8. Find the Adafruit_SSD1306.h file in the Arduino Library folder. Generally, it is
located at Documents\Arduino\libraries on windows systems. There you will find the
Adafruit_SSD1306.h file inside the Adafruit_SSD1306 folder.

MMEC, ECE, Belagavi 2


Arduino Program to display temperature and humidity on OLED

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

#define SCREEN_WIDTH 128 // OLED display width, in pixels


#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define DHTPIN 2 // pin connected to DHT11 sensor


#define DHTTYPE DHT11

Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);


// create SSD1306 display object connected to I2C
DHT dht(DHTPIN, DHTTYPE);

String displayString;

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

// initialize OLED display with address 0x3C for 128x64


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

delay(2000); // wait for initializing


oled.clearDisplay(); // clear display

oled.setTextSize(2); // text size


oled.setTextColor(WHITE); // text color
oled.setCursor(0, 10); // position to display

dht.begin(); // initialize DHT11 the temperature


and humidity sensor
displayString.reserve(10); // to avoid fragmenting memory when
using String

MMEC, ECE, Belagavi 3


}

void loop() {
float humi = dht.readHumidity(); // read humidity
float tempC = dht.readTemperature(); // read temperature

// check if any reads failed


if (isnan(humi) || isnan(tempC)) {
displayString = "Failed";
} else {
displayString = String(tempC, 1); // one decimal places
displayString += "°C";
displayString += String(humi, 1); // one decimal places
displayString += "%";
}

Serial.println(displayString); // print the temperature in


Celsius to Serial Monitor
oledDisplayCenter(displayString); // display temperature and
humidity on OLED
}

void oledDisplayCenter(String text) {


int16_t x1;
int16_t y1;
uint16_t width;
uint16_t height;

oled.getTextBounds(text, 0, 0, &x1, &y1, &width, &height);

// display on horizontal and vertical center


oled.clearDisplay(); // clear display
oled.setCursor((SCREEN_WIDTH - width) / 2, (SCREEN_HEIGHT -
height) / 2);
oled.println(text); // text to display
oled.display();
}

Result: Temperature and humidity values are seen on OLED.

MMEC, ECE, Belagavi 4

You might also like