CCCPaste

**Sensor Display** rev_01

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: **Sensor Display**
	- Source Code NOT compiled for: ESP32 DevKit V1
	- Source Code created on: 2024-11-08 23:11:23

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* The project aims to automate sensor data */
	/* collection and processing using Arduino, */
	/* integrating libraries for efficient communication */
	/* and control of connected components. Focus on */
	/* modular design for easy updates and maintenance. */
/****** END SYSTEM REQUIREMENTS *****/

/* START CODE */

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 
#include 
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/****** GLOBAL VARIABLES *****/
// Create an instance of the BME280 sensor
Adafruit_BME280 bme; // I2C
// Create an instance of the OLED display
Adafruit_SSD1306 display(128, 32, &Wire, -1); // Initialize with I2C

void setup(void)
{
    // Initialize serial communication for debugging
    Serial.begin(9600);
    
    // Initialize the BME280 sensor
    if (!bme.begin(0x76)) { // Check the I2C address
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
    }

    // Initialize the OLED display
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize with I2C address
    display.clearDisplay();
    display.display();
}

void loop(void)
{
    // Read temperature, humidity, and pressure from the BME280 sensor
    float temperature = bme.readTemperature();
    float humidity = bme.readHumidity();
    float pressure = bme.readPressure() / 100.0F; // Convert to hPa

    // Display the sensor data on the OLED display
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    display.print("Temp: ");
    display.print(temperature);
    display.println(" C");
    display.print("Humidity: ");
    display.print(humidity);
    display.println(" %");
    display.print("Pressure: ");
    display.print(pressure);
    display.println(" hPa");
    display.display();

    // Wait for 2 seconds before the next loop
    delay(2000);
}

/* END CODE */