Tutorial: How to use 0.96 OLED - a small and cute display
Specifications
Description: 0.96 inch monochrome OLED display
Resolution: 128×64 pixels
Dimension: WxHxT 27.3 mm x 27.8 mm x 4.3 mm
Protocol: I2C
Operating Voltage: 3V to 5V
Common variations of this OLED module:
- Different monochrome color: white, blue, yellow
- Different resolution: 128×64 and 128×32 pixels
- Different communication protocol: I2C and SPI
- Different driver IC: SSD1306 and SSH1106
- Some has additional reset pin.
Circuit Diagram
links of libraries: https://github.com/adafruit/Adafruit_SSD1306 https://github.com/adafruit/Adafruit-GFX-Librar
Video Demonstration
Call To Action
If you have any question regarding this tutorial, please do not hesitate to write it in the comment box below and I will be happy to answer it.
If you like this video, please kindly consider supporting me by Subscribing to TechToTinker Youtube channel. Click this to SUBSCRIBE.
Thank you and have a good day.
Source Code
1// Load the libraries for the DHT sensor
2#include "Wire.h"
3#include "DHT.h"
4#include "Adafruit_Sensor.h"
5
6// Load the libraries for the OLED display
7#include "Adafruit_GFX.h"
8#include "Adafruit_SSD1306.h"
9
10// OLED display size in pixels
11#define SCREEN_WIDTH 128
12#define SCREEN_HEIGHT 64
13
14// DHT11 data pin assignment
15#define DHTPIN A0
16
17// Define the type of sensor to be use
18#define DHTTYPE DHT11 // DHT 11
19//#define DHTTYPE DHT22 // DHT 22 (AM2302)
20//#define DHTTYPE DHT21 // DHT 21 (AM2301)
21
22// Create the "oled" object
23#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
24Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
25
26// Create the "dht" object
27DHT dht(DHTPIN, DHTTYPE);
28
29// Declare global variables here
30float temperature;
31float humidity;
32
33void setup() {
34 // Initialized the Serial
35 Serial.begin(115200);
36
37 // Initialized the DHT11
38 dht.begin();
39
40 // Initialized the OLED
41 if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
42 Serial.println(F("SSD1306 failed"));
43 for(;;);
44 }
45
46 oled.clearDisplay();
47 oled.setTextColor(WHITE);
48}
49
50void loop() {
51 // Get the sensor readings
52 getSensorValue();
53
54 // and display it to the oled
55 updateDisplay();
56
57 // Delay for some time
58 delay(3000);
59}
60
61void getSensorValue() {
62 // Get the temperature and humidity sensor readings
63 temperature = dht.readTemperature();
64 humidity = dht.readHumidity();
65 if (isnan(humidity) || isnan(temperature)) {
66 Serial.println("DHT sensor failed");
67 }
68}
69
70void updateDisplay() {
71 // Clear the display
72 oled.clearDisplay();
73
74 // Display the current temperature
75 oled.setTextSize(1);
76 oled.setCursor(0,0);
77 oled.print("Temperature: ");
78 oled.setTextSize(2);
79 oled.setCursor(0,10);
80 oled.print(temperature);
81 oled.print(" ");
82 oled.setTextSize(1);
83
84 // Enable the Code Page 437
85 // https://en.wikipedia.org/wiki/Code_page_437
86 oled.cp437(true);
87
88 // Then print the chosen characters
89 // which in this case is the degrees symbol
90 // https://www.ascii-codes.com/
91 oled.write(248);
92 oled.setTextSize(2);
93 oled.print("C");
94
95 // Display the current humidity
96 oled.setTextSize(1);
97 oled.setCursor(0, 35);
98 oled.print("Humidity: ");
99 oled.setTextSize(2);
100 oled.setCursor(0, 45);
101 oled.print(humidity);
102 oled.print(" %");
103
104 // Update and show the display
105 oled.display();
106}
Posts in this series
- How to Get Started with ATTiny85 in Arduino IDE
- Tutorial: How to use MFRC522 RFID module using Arduino
- SOS Flasher Using Millis Function with Enable Switch
- Tutorial: How to use DS3231 RTC in Arduino
- Tutorial: Getting Started with the NRF24L01 | How to use | Arduino
- Tutorial: How to use SIM800L GSM Module for Controlling Anything | Arduino
- Tutorial: How to use Keypad | Text Entry Mode | Arduino
- Tutorial: How to use 4x4 Keypad | Arduino
- Project Idea: Arduino Voltmeter
- Project Idea: Door Lock Security | Arduino
- Multitasking with Arduino | Relay Timer Controller | using millis
- Tutorial Understanding Blink Without Delay | How to millis
- Arduino Simple LCD Menu
- How to use SIM800L GSM Module using Arduino | Make or Answer Voice Calls
- Tutorial: How to Use Arduino Uno as HID | Part 2: Arduino Mouse Emulation
- Tutorial: How to Use Arduino Uno as HID | Part 1: Arduino Keyboard Emulation
- Tutorial: How to use SIM800L DTMF to Control Anything | Arduino
- Tutorial: Arduino EEPROM
- How to use SIM800L GSM Module | Arduino | Send and Receive SMS
- 16x2 LCD Menu for Arduino
- Tutorial: Arduino GPIO | How to use Arduino Pins
- MIT App Inventor for Arduino
- RC Car using L298N, HC-06, and Arduino Uno
- How to Use LCD Keypad Shield for Arduino
- How to Use Arduino Interrupts
- Project: Automatic Alcohol Dispenser
- TUTORIAL: How to use HC-SR04 Ultrasonic Sensor with Arduino
- Source Code: Astronomia Meme and Funeral Dance | melodies the Arduino way
- How to Get Started with L293D Motor Driver Shield with Arduino
- How to Get Started with L298N Motor Driver module using Arduino
- Part 2: Wav Music Player with Lyrics Using Arduino and SD Card
- Interfacing Infrared to Arduino Uno
- Part 1: Wav Music Player Using Arduino Uno and SD Card
- How to Interface Stepper Motor to Arduino Uno
- How To Play MP3 Files on Arduino from SD Card
- What is Arduino Software Serial
- How to Interface SD card to Arduino (without SD card shield)?
- Playing Melodies Using Arduino
- 8 Degrees Of Freedom (DOF) Robot Using Arduino Uno
- How to Interface PS2 Controller to Arduino Uno
- Part 3: DF Player Mini Tinkering with Arduino Nano and LCD
- How to Interface HC-06 to Arduino
- How to make a Remote Control RC car using Arduino and HC-06 bluetooth module
- Part 2: DF Player Mini Tinkering with Arduino Nano
- Part 1: DF Player Mini - a mini cheap mp3 player
No comments yet!