Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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 Readings**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-12-12 23:50:25
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall initialize all connected */
- /* components during the setup phase and continuously */
- /* monitor their status in the loop phase to ensure */
- /* optimal performance and responsiveness. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* During the setup phase, the system shall configure */
- /* all connected components, including sensors and */
- /* actuators, and in the loop phase, it shall check */
- /* their operational status to ensure reliability and */
- /* timely responses. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Instantiate the BME280 sensor object
- Adafruit_BME280 bme; // I2C
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(9600);
- // Initialize the BME280 sensor
- if (!bme.begin(0x77)) { // Check if the sensor is connected
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- while (1); // Stop if the sensor is not found
- }
- Serial.println("BME280 sensor initialized successfully.");
- }
- void loop(void)
- {
- // Read temperature, pressure, and humidity from the BME280 sensor
- float temperature = bme.readTemperature();
- float pressure = bme.readPressure() / 100.0F; // Convert to hPa
- float humidity = bme.readHumidity();
- // Print the sensor readings to the Serial Monitor
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" °C");
- Serial.print("Pressure: ");
- Serial.print(pressure);
- Serial.println(" hPa");
- Serial.print("Humidity: ");
- Serial.print(humidity);
- Serial.println(" %");
- // Wait for a second before the next reading
- delay(1000);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement