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: Arduino Uno
- - Source Code created on: 2024-12-06 11:23:47
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* read periodically all data from sensor. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <DFRobot_BME280.h> //https://github.com/DFRobot/DFRobot_BME280
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t sensor_BME280_I2C_PIN_SDA_A4 = A4;
- const uint8_t sensor_BME280_I2C_PIN_SCL_A5 = A5;
- const uint8_t sensor_BME280_I2C_SLAVE_ADDRESS = 119;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- DFRobot_BME280 bme; // Create an instance of the DFRobot_BME280 class
- void setup(void)
- {
- // Initialize I2C communication
- Wire.begin(sensor_BME280_I2C_PIN_SDA_A4, sensor_BME280_I2C_PIN_SCL_A5);
- // Initialize the BME280 sensor
- if (bme.begin(sensor_BME280_I2C_SLAVE_ADDRESS) != bme.eStatusOK) {
- Serial.println("BME280 sensor not found!");
- while (1); // Stop execution if sensor not found
- }
- // Start Serial communication for debugging
- Serial.begin(9600);
- }
- void loop(void)
- {
- // Read sensor data periodically
- float temperature = bme.getTemperature();
- uint32_t pressure = bme.getPressure();
- float humidity = bme.getHumidity();
- // Print the sensor data to the Serial Monitor
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" °C");
- Serial.print("Pressure: ");
- Serial.print(pressure);
- Serial.println(" Pa");
- Serial.print("Humidity: ");
- Serial.print(humidity);
- Serial.println(" %");
- // Wait for 2 seconds before the next reading
- delay(2000);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement