Rabu, 5 Jun 2024

DIY Temperature & Humidity Meter with Custom Text Display for my car

Well ..... was thinking to add this as a new instrument for my car. But now I'm working on to improve further. I will be adding a gas sensor to detect CO2 level in ppm. For display, I will use a bigger Colour TFT. But I will share this simple one for now ........

            

This is a simple project to explore some methods to generate display on OLED. 

    OLED, which stands for Organic Light-Emitting Diode, is a display technology that utilizes organic compounds to emit light when an electric current is applied. This technology consists of thin layers of organic materials positioned between two electrodes, typically a cathode and an anode. The key component is the emissive electroluminescent layer, which is responsible for emitting light in response to the electric current. When electricity passes through this layer, it excites the organic molecules, causing them to emit light. 

            For this project, two type of displays will be projected on to the OLED ;

1. Temperature and Humidity reading from DHT11 sensor and

2. Customs scrolling text display ( contents of the text can be edited )


Video of the display on OLED

List of components ;

1. Arduno UNO 

2. DHT11 sensor

3. OLED 128 x 64

4. Jumper wires


Circuit Diagram ;

And below is the coding. Copy and paste to Aduino IDE, ensure to get the needed libraries, modify text display as you wish and  compile & upload.

//Temp & Humid Meter With Custom Text Display on OLED

//By Rosedi 20May2024

 

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include <DHT.h>

 

// Define the OLED reset pin

#define OLED_RESET    -1

Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);

 

// DHT11 sensor settings

#define DHTPIN 2     // Digital pin connected to the DHT sensor

#define DHTTYPE DHT11   // DHT 11

 

DHT dht(DHTPIN, DHTTYPE);

 

// Define the scrolling text

const char *scrollText = "ALLAHUMMA SOLLI ALA MUHAMMAD ";

int textX = 128; // Start the text off-screen to the right

int textY = 56; // Vertically position the text at the bottom

 

void setup() {

  // Initialize Serial for debugging

  Serial.begin(9600);

 

  // Initialize the DHT sensor

  dht.begin();

 

  // Initialize the OLED display

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // 0x3C is the I2C address for the SSD1306

    Serial.println(F("SSD1306 allocation failed"));

    for (;;); // Loop forever if OLED initialization fails

  }

 

  // Clear the buffer

  display.clearDisplay();

 

  // Display initial text

  display.setTextSize(1);      // Set text size

  display.setTextColor(SSD1306_WHITE); // Set text color

  display.setCursor(16, 0);     // Set cursor position

  display.print(F("ASSALAMMUALAIKUM                               ROSEDI"));

  display.display();           // Display the text

  delay(5000);                 // Pause for 5 seconds

 

  // Display initial text

  display.setTextSize(1);      // Set text size

  display.setTextColor(SSD1306_WHITE); // Set text color

  display.setCursor(0, 35);     // Set cursor position

  display.print(F(" FASTEN YOUR SEATBELT"));

  display.display();           // Display the text

  delay(5000);                 // Pause for 5 seconds

 

  // Display initial text

  display.setTextSize(1);      // Set text size

  display.setTextColor(SSD1306_WHITE); // Set text color

  display.setCursor(0, 52);     // Set cursor position

  display.print(F("     SAFE JOURNEY"));

  display.display();           // Display the text

  delay(5000);                 // Pause for 5 seconds

}

 

// Function to display scrolling text

void displayScrollingText() {

  display.clearDisplay();

  display.setTextSize(1);

  display.setTextColor(SSD1306_WHITE);

  display.setCursor(textX, textY);

  display.print(scrollText);

  display.display();

 

  // Move the text to the left

  textX--;

  if (textX < -((int)strlen(scrollText) * 6)) {

    textX = 88; // Reset text position to start again

  }

}

 

void loop() {

  // Read temperature and humidity from DHT11 sensor

  float humidity = dht.readHumidity();

  float temperature = dht.readTemperature();

 

  // Check if any reads failed and exit early (to try again).

  if (isnan(humidity) || isnan(temperature)) {

    Serial.println(F("Failed to read from DHT sensor!"));

    return;

  }

 

  // Print the values to the Serial Monitor (for debugging)

  Serial.print(F("Humidity: "));

  Serial.print(humidity);

  Serial.print(F("%  Temperature: "));

  Serial.print(temperature);

  Serial.println(F("°C "));

 

  // Clear the display buffer

  display.clearDisplay();

 

  // Display temperature

  display.setTextSize(2);

  display.setTextColor(SSD1306_WHITE);

  display.setCursor(6,10);

  display.print(F("T: "));

  display.print(temperature);

  display.print(F(" C"));

 

  // Display humidity

  display.setCursor(6,34);

  display.print(F("H: "));

  display.print(humidity);

  display.print(F(" %"));

 

  // Update the display with the new data

  display.display();

 

  // Display scrolling text

  displayScrollingText();

 

  // Wait a few seconds between measurements

  delay(0);

}



Actually if you look into the program, there are a litte extra functions compare to the one shown in the video. The display will come in three parts, greetings, sensor values and scrolling text. Just try it out.


Happy exploring !

To purchase the parts for this project, click on below links ;

Arduino UNO R3 (Original Italy)

DHT11 Sensor

OLED 128 X 64 I2C






GEN - Z & Alpha : A Guide For Navigating Modern Culture

WARNING : The opening passage below uses Gen Z and Gen Alpha Slangs When Australian Senator Fatima Payman’s speech went viral, it totally ca...