Yet another illustration how to use the 0.96” OLED 128×64 Screen Display, and DHTXX Temperature & Humidity Sensor, The OLED 128X64 Screen Display module it is made of 128×64 individual blue OLED pixels, each on is can be turn on or off by the microcontroller chip, and works without backlight, that will light in a dark environment, OLED display is higher compared to LCD display. These module works in i2C communication,
The DHTXX temperature & humidity sensor is a complex with a calibrated digital signal output by using the exclusive digital signal acquisition technique and temperature and humidity sensing technology, it insures a high reliability and excellent long term stability. This sensor includes a resistive type humidity measurement component and an NTC temperature measurement component offering an excellent quality fast response and anti-interference.
As you can see the illustration below the DHT11 was illustrated to a manual wiring concept, but if you have a module that already mounted to the PCV along with the resistor just follow the wiring diagram.
For generating an Image to byte C Code Array please refer to this link.
Required Component
- ESP8266 12E or 13E / NodeMCU Development Board
- 0.96 inch 128×64 OLED Screen Display
- DHT11/DHT22/DHT24 Package or Module
- Jumper Wire / DuPont Wire
- Solder Less Bread Board
Wiring Diagram
C Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
#include <Wire.h> #include <Adafruit_GFX.h> #include <ESP_Adafruit_SSD1306.h> #include "ESP8266WiFi.h" #include "DHT.h" #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); #define DHTPIN 14 // Connected to Pin D5 in NodeMCU // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht(DHTPIN, DHTTYPE,15); byte img [] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,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 0x0, 0x20, 0x0, 0x0, 0xe, 0x0, 0x0, 0x70, 0x0, 0x0, 0x0, 0x1, 0x80, 0x70, 0x0, 0x0, 0x0, 0x1, 0x80, 0xf8, 0x0, 0x0, 0x0, 0x3, 0xc0, 0xf8, 0x0, 0x0, 0x0, 0x3, 0xc0, 0xf8, 0x0, 0x0, 0x0, 0x3, 0xc0, 0x70, 0x0, 0x0, 0x0, 0x3, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, }; void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); // dht begin dht.begin(); // set display display.begin(SSD1306_SWITCHCAPVCC, 0x78>>1); display.display(); delay(2000); display.clearDisplay(); } void showTemp(float temp,float hud) { display.drawBitmap(0, 5, img, 48, 50, 1); display.setTextSize(1); display.setCursor(3,0); display.println("Temperature/Humidity"); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(52,10); display.print(temp); display.println("C"); display.setCursor(52,30); display.print(hud); display.println("%"); display.setTextSize(1); display.setCursor(52,50); display.println("14CORE.COM"); display.display(); display.clearDisplay(); void loop() { delay(1000); // Wait a few seconds between measurements. float h = dht.readHumidity(); float t = dht.readTemperature(); // Read temperature as Celsius if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.print("Humidity: "); // show in serial monitor Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); // show in serial monitor Serial.print(t); Serial.print(" *C \n"); showTemp(t,h); // show temp } |
Required Libraries
Hi!
Tried your code but i get nothing when putting uploading it.
Also, the code would not compile at first, i found a unclosed bracket. But still, after upload nothing happens. Have i missed something? Using a NodeMCU, OLED with i2C and a DHT11.
The missing bracket (as i understand it);
display.clearDisplay();
}; <- Added this
void loop() {
delay(1000); // Wait a few seconds between measurements.
Check the input voltage of your OLED Screen, sometimes the OLED screen works on 5v. you can achieve the 5v by hooking up 1 jumper to get 5v. note: ground should be common ground.
I’ve tried the screen at 3.3v with a arduino and som other codes on the NodeMCU and then it works. But will try the 5 volt anyway. Maybe it aint sufficient with the setup. It’s spec at 3-5 volt.
Other thoughts;
#include
#include
#include
#include “ESP8266WiFi.h”
Shouldn’t it be;
#include “Wire.h”
#include “Adafruit_GFX.h”
#include “ESP_Adafruit_SSD1306.h”
#include “ESP8266WiFi.h”
or does it not matter?
This probably fixed it, got the pins wrong. For me the working combination was;
DHT: D5
SCL: D1
SDA: D2
So sorry for all other mumbling above :)
Thanks for coding and fixing coding. But surprise for me rook. I have found that I have to use an 4,7 KOhm resistor between VCC and signal from DHT11. And it works . But again I am an rook
You are right. Actually the wiring diagram is wrong because the 10kOhm resistor must be connectet between +Vcc and DATA pin of DHTxx sensor. So in your case, addind 4.7kOhm got the same result.
With resistor between GND and DATA I guess nobody will get it works!!!
In file included from C:\Users\Pradeep\Documents\Arduino\NodeMCUESP8266_OLED_DHT22\NodeMCUESP8266_OLED_DHT22.ino:1:0:
C:\Users\Pradeep\Documents\Arduino\libraries\SPI/SPI.h:16:26: fatal error: avr/pgmspace.h: No such file or directory
#include
^
compilation terminated.
Multiple libraries were found for “SPI.h”
Used: C:\Users\Pradeep\Documents\Arduino\libraries\SPI
Not used: C:\Users\Pradeep\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\SPI
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
hi! your using multiple SPI library, you need to remove some unused SPI library in your arduino IDE . make it sure that Adafruit_GFX.h is available in your list.
> C:\Users\Pradeep\Documents\Arduino\libraries\SPI
You can use this library from U8G >
http://www.14core.com/wiring-the-128×64-1-3-inch-oled-display-on-4-wire-3-wire-i2c-interface/
Please, there should be a mistake in Wirin Diagram;
The 10 kOhm resistor should be connected from DHTxx DATA pin to VCC pin, not to GND.