#include <Adafruit_GFX.h>// Graphics Library
#include <Adafruit_SSD1306.h> // OLED Display Library
#define SCREEN_WIDTH 128 // Width of the OLED display
#define SCREEN_HEIGHT 64 // Height of the OLED display
// Create an instance of the display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // -1 is for the reset pin (not us
const int triggerPin = 2;
const int echoPin = 18;
void setup() {
Serial.begin(9600);
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(22,INPUT);
// Initialize the DHT sensor
// Initialize the display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize with I2C address 0x3C
display.clearDisplay(); // Clear the display buffer
display.setTextSize(1); // Set text size to normal
display.setTextColor(WHITE); // Set text color to white
}
void loop() {
// Read distance from ultrasonic sensor
float duration, dist;
int distance;
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
duration = pulseIn(echoPin, HIGH);
dist = (duration / 2) / 29.1; // Calculate distance in centimeters
distance = round(dist);
// Read temperature and humidity from DHT11 sensor
// Check if any reads failed and exit early (to try again).
// Read IR sensor
// Clear the display and show distance, temperature, and humidity
display.clearDisplay(); // Clear the display
display.setCursor(0, 0); // Set cursor position
display.print("Distance: "); // Print label
display.print(distance); // Print distance value
display.print(" cm"); // Print unit
// Move cursor to the next line
// Print temperature label
// Print temperature value
// Print unit
// Move cursor to the nex
// Print humidity label
// Print humidity value
// Print unit
// Move cursor to the next line
// Print IR sensor
// Print IR sensor value
display.display(); // Update the display with the new content
delay(1000); // Adjust delay as needed for your application
}