8. Input & Output device¶
The device I created is an environmental monitoring system that measures temperature and humidity using a DHT11 sensor, displays the readings on an SSD1306 OLED screen, and triggers a relay when the temperature exceeds 30°C. This system is designed to provide real-time data visualization and automated response to specific environmental conditions. The DHT11 sensor is responsible for accurately capturing temperature and humidity levels, which are then processed by the Arduino. The OLED display visually presents this data in a clear and readable format, making it easy to monitor the current conditions. The relay module acts as a switch, controlled by the Arduino, to activate external devices when a predetermined temperature threshold is reached. This setup can be utilized in various applications, such as automated cooling systems, greenhouse monitoring, or any scenario where maintaining specific environmental conditions is crucial. The combination of these components creates a functional and responsive device that enhances the ability to monitor and manage environmental factors effectively.
Device¶
This device is perfectly suited for use in a tiny acrylic greenhouse to nurture small plants. By continuously monitoring temperature and humidity levels with the DHT11 sensor, the system ensures that the microclimate within the greenhouse remains optimal for plant growth. The real-time data displayed on the SSD1306 OLED screen allows for easy observation and adjustment of the environment. When the temperature exceeds 30°C, the relay is triggered to activate cooling mechanisms, such as a small fan or ventilation system, helping to maintain ideal conditions for the plants. This automation not only enhances plant health and growth but also reduces the need for constant manual monitoring and intervention. The transparency of the acrylic greenhouse, combined with the precision of this environmental monitoring device, creates a controlled and efficient environment, fostering the successful cultivation of small plants.
Reasoning¶
Living in the hot climate of Bahrain has always posed a challenge for keeping plants alive. Despite my best efforts, the harsh temperatures have often led to the premature demise of my plants. This innovative device offers a promising solution to this persistent issue. By closely monitoring and regulating the temperature and humidity levels within a small acrylic greenhouse, I can create an optimal environment for my plants to thrive. The automated system, which triggers cooling mechanisms when temperatures rise above 30°C, ensures that my plants are protected from the extreme heat. This device not only helps in maintaining a stable microclimate but also allows me to enjoy the visual beauty of my plants through the clear acrylic walls, without the constant worry of them wilting and dying. With this technology, I am confident that I can finally keep my plants alive and healthy, despite the challenging Bahraini climate.
Useful link¶
Code Example¶
Use the three backticks to separate code.
/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x32 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Bonezegei_DHT11.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// DHT11 sensor initialization
Bonezegei_DHT11 dht(14);
void setup() {
Serial.begin(115200);
// Initialize DHT11 sensor
dht.begin();
// Initialize OLED display
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
}
void loop() {
// Read data from DHT11 sensor
if (dht.getData()) { // get All data from DHT11
float tempDeg = dht.getTemperature(); // return temperature in celsius
float tempFar = dht.getTemperature(true); // return temperature in fahrenheit if true celsius of false
int hum = dht.getHumidity(); // return humidity
// Prepare the string to display
String str = "Temp: ";
str += tempDeg;
str += "°C ";
str += tempFar;
str += "°F\nHumidity:";
str += hum;
str += "%";
// Clear the display
display.clearDisplay();
// Set text size and color
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
// Set cursor position
display.setCursor(0, 0);
// Display the string on the OLED
display.println(str);
display.display();
}
delay(2000); //delay at least 2 seconds for DHT11 to read the data
}
How I did it¶
Objective:¶
The objective of this project was to create a system that reads temperature and humidity data using a DHT11 sensor, displays this data on an OLED screen, and controls a relay when the temperature exceeds 30°C.
Components Used:¶
- Arduino
- DHT11 temperature and humidity sensor
- SSD1306 OLED display (128x32 pixels)
- Relay module
- Connecting wires
- Breadboard
Steps Followed:¶
Component Setup and Initialization:¶
Connected the DHT11 sensor to the Arduino. Connected the SSD1306 OLED display to the Arduino using I2C communication. Connected the relay module to pin 2 of the Arduino. Libraries and Dependencies:
Included necessary libraries for OLED display and DHT11 sensor:¶
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Bonezegei_DHT11.h>
Define Constants and Variables:¶
Defined screen dimensions and I2C address for the OLED display. Defined the pin for the relay module.
Initialize Display and Sensor:¶
Initialized the DHT11 sensor and OLED display in the setup() function. Ensured the OLED display was properly set up and displayed an initial splash screen.
Relay Control Setup:¶
Set the relay pin as an output in the setup() function. Initialized the relay to be off initially to ensure it was off at the start.
Reading Sensor Data:¶
In the loop() function, read temperature and humidity data from the DHT11 sensor. Stored the data in variables for further processing.
Display Data on OLED:¶
Cleared the OLED display and set the text size and color. Displayed the temperature (in both Celsius and Fahrenheit) and humidity on the OLED screen.
Serial Monitor Output:¶
Printed the temperature and humidity data to the Serial Monitor for debugging and monitoring purposes. Relay Control Based on Temperature:
Added a conditional check to control the relay:¶
If the temperature exceeds 30°C, the relay is turned on. If the temperature is 30°C or below, the relay is turned off.
Code Implementation:¶
Combined all functionalities into a single cohesive code to ensure smooth operation and integration of all components.
Summary of Connections:¶
DHT11 Sensor:¶
VCC → Arduino 5V GND → Arduino GND DATA → Arduino Digital Pin 14 (A0)
SSD1306 OLED Display:¶
VCC → Arduino 3.3V GND → Arduino GND SCL → Arduino A5 (SCL) SDA → Arduino A4 (SDA)
Relay Module:¶
VCC → Arduino 5V GND → Arduino GND IN → Arduino Digital Pin 2