Wemos D1 Mini-Based Indoor Climate Monitor with OLED Display and Rotary Encoder
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to interface a Wemos D1 Mini microcontroller with a DHT11 Humidity and Temperature Sensor, a 0.96" OLED display, and an HW-040 Rotary Encoder. The purpose of the circuit is to read temperature and humidity data from the DHT11 sensor, display this information along with a menu on the OLED screen, and use the rotary encoder for navigating through the menu options.
Component List
Wemos D1 Mini
- Description: A compact microcontroller based on the ESP8266 WiFi-enabled microcontroller.
- Pins: RST, A0, D0, D5, D6, D7, D8, 3V3, 5V, G, D4, D3, D2, D1, RX, TX
DHT11 Humidity and Temperature Sensor
- Description: A basic, low-cost digital temperature and humidity sensor.
- Pins: VDD, DATA, NULL, GND
0.96" OLED
- Description: A small OLED display for visual output.
- Pins: GND, VDD, SCK, SDA
HW-040 Rotary Encoder
- Description: An input device that provides rotary input and has an integrated push-button.
- Pins: GND, +, SW, DT, CLK
Wiring Details
Wemos D1 Mini
- D5: Connected to CLK pin of HW-040 Rotary Encoder
- D6: Connected to DT pin of HW-040 Rotary Encoder
- D7: Connected to SW pin of HW-040 Rotary Encoder
- 3V3: Connected to VDD pins of DHT11 Sensor, 0.96" OLED, and + pin of HW-040 Rotary Encoder
- G: Connected to GND pins of DHT11 Sensor, 0.96" OLED, and GND pin of HW-040 Rotary Encoder
- D4: Connected to DATA pin of DHT11 Sensor
- D2: Connected to SDA pin of 0.96" OLED
- D1: Connected to SCK pin of 0.96" OLED
DHT11 Humidity and Temperature Sensor
- VDD: Connected to 3V3 pin of Wemos D1 Mini
- DATA: Connected to D4 pin of Wemos D1 Mini
- GND: Connected to G pin of Wemos D1 Mini
0.96" OLED
- GND: Connected to G pin of Wemos D1 Mini
- VDD: Connected to 3V3 pin of Wemos D1 Mini
- SCK: Connected to D1 pin of Wemos D1 Mini
- SDA: Connected to D2 pin of Wemos D1 Mini
HW-040 Rotary Encoder
- GND: Connected to G pin of Wemos D1 Mini
- +: Connected to 3V3 pin of Wemos D1 Mini
- SW: Connected to D7 pin of Wemos D1 Mini
- DT: Connected to D6 pin of Wemos D1 Mini
- CLK: Connected to D5 pin of Wemos D1 Mini
Documented Code
/*
* This Arduino Sketch is designed for a Wemos D1 Mini microcontroller.
* It interfaces with a DHT11 sensor to read temperature and humidity,
* a 0.96" OLED display to show a menu with these readings and other
* options, and an HW-040 Rotary Encoder for menu navigation.
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DHTPIN D4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define CLK D5
#define DT D6
#define SW D7
int menuIndex = 0;
const int menuItems = 3;
void setup() {
pinMode(CLK, INPUT);
pinMode(DT, INPUT);
pinMode(SW, INPUT_PULLUP);
dht.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.print("Initializing...");
display.display();
delay(1000);
}
void loop() {
static int lastClkState = HIGH;
int clkState = digitalRead(CLK);
if (clkState != lastClkState) {
if (digitalRead(DT) != clkState) {
menuIndex = (menuIndex + 1) % menuItems;
} else {
menuIndex = (menuIndex - 1 + menuItems) % menuItems;
}
lastClkState = clkState;
displayMenu();
}
if (digitalRead(SW) == LOW) {
executeMenuAction();
delay(200);
}
}
void displayMenu() {
display.clearDisplay();
display.setCursor(0,0);
switch(menuIndex) {
case 0:
display.print("1. Show Temp & Humidity");
break;
case 1:
display.print("2. Option 2");
break;
case 2:
display.print("3. Option 3");
break;
}
display.display();
}
void executeMenuAction() {
switch(menuIndex) {
case 0:
displayTempHumidity();
break;
case 1:
// Add action for Option 2
break;
case 2:
// Add action for Option 3
break;
}
}
void displayTempHumidity() {
float h = dht.readHumidity();
float t = dht.readTemperature();
display.clearDisplay();
display.setCursor(0,0);
display.print("Temp: ");
display.print(t);
display.print(" C");
display.setCursor(0,10);
display.print("Humidity: ");
display.print(h);
display.print(" %");
display.display();
delay(2000);
displayMenu();
}
This code is responsible for initializing the components, reading sensor data, handling the rotary encoder input, updating the OLED display, and executing actions based on the menu selection.