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 10:23:08
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* read periodically temp and humidity. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <GY21.h> //https://github.com/JonasGMorsch/GY-21
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t sensor_GY21_I2C_PIN_SDA_A4 = A4;
- const uint8_t sensor_GY21_I2C_PIN_SCL_A5 = A5;
- const uint8_t sensor_GY21_I2C_SLAVE_ADDRESS = 64;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- GY21 sensor; // Create an instance of the GY21 class
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(9600);
- // Initialize I2C communication
- Wire.begin(sensor_GY21_I2C_PIN_SDA_A4, sensor_GY21_I2C_PIN_SCL_A5);
- }
- void loop(void)
- {
- // Read temperature and humidity
- float temperature = sensor.GY21_Temperature();
- float humidity = sensor.GY21_Humidity();
- // Print the results to the serial monitor
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" °C");
- 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