Hello and welcome to another arduino tutorial
In this project we will learn how to build a simple weather station using DHT11 Sensor and OLED display.
This project micro controller is Arduino Uno R3.
This foundational project merges two different data-collection architectures and requires formatting the results for display.
Analog vs. Digital Sensor Protocols
You cannot analogRead() a DHT11 sensor! The components in this system use fundamentally different communication methods.
The DHT11 Temperature & Humidity Sensor: This is a digital sensor with its own internal processor. It transmits a 40-bit data stream representing its readings.
- You MUST use the
<DHT.h>library to communicate with it. - Data is read using specific library commands:
float temperature = dht.readTemperature();andfloat humidity = dht.readHumidity();.
- You MUST use the
The Light Dependent Resistor (LDR): This is a purely analog, physical component. Its resistance changes based on light intensity.
- It MUST be used in a Voltage Divider circuit with a fixed resistor (e.g., 10K Ohm).
- The Arduino reads it as a simple analog voltage:
int lightValue = analogRead(A0);(Outputs a value from0 to 1023).
Formatting Data for the Display
The microcontroller reads values like temperature = 25.0 and humidity = 60.0. A character display has limited space, so data must be organized carefully.
- A 16x2 Character LCD (especially with an I2C backpack to simplify wiring) has exactly 32 character positions.
- Execution: You must control the cursor position precisely to format the output:
lcd.setCursor(0, 0); // Start at the beginning of the first line lcd.print("T: "); lcd.print(temperature); lcd.print("C"); lcd.setCursor(0, 1); // Move to the beginning of the second line lcd.print("H: "); lcd.print(humidity); lcd.print("%"); - To display additional data (like from the LDR) on the same small screen, you can create a simple pagination system. Use
delay(3000); lcd.clear();to wipe the screen every few seconds and cycle through different data screens.
Standard Climate Station Components
- Arduino Uno R3 / Nano (Provides standard execution speed and I/O).
- DHT11 Temperature & Humidity Sensor (The DHT22 is a more precise alternative, providing decimal readings).
- Light Dependent Resistor (LDR) Photocell.
- 16x2 LCD Character Display + I2C Backpack (The I2C interface drastically reduces the number of required connecting wires from 16 to just 4).
You can make your own adaptations since the system is versatile [Challenge for the reader: minimize the system ;) ].
Take care, Roy.