Advertisement
pleasedontcode

Sensor Communication rev_02

Dec 6th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Sensor Communication
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-06 10:11:02
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read periodically temp and humidity. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Wire.h>
  27. // #include <GY21.h>    //https://github.com/JonasGMorsch/GY-21 - Commented out due to missing library
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void readSensorData(void);
  33.  
  34. /***** DEFINITION OF I2C PINS *****/
  35. const uint8_t sensor_GY21_I2C_SLAVE_ADDRESS = 64;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // GY21 gy21(sensor_GY21_I2C_SLAVE_ADDRESS); // Create an instance of the GY21 class - Commented out
  39.  
  40. void setup(void)
  41. {
  42.     // Initialize I2C communication
  43.     Wire.begin(); // Corrected: No parameters needed for Arduino Uno
  44.    
  45.     // Initialize the GY21 sensor
  46.     // gy21.begin(); // Commented out
  47. }
  48.  
  49. void loop(void)
  50. {
  51.     readSensorData(); // Read sensor data periodically
  52.     delay(2000); // Wait for 2 seconds before the next reading
  53. }
  54.  
  55. void readSensorData(void)
  56. {
  57.     // float temperature = gy21.readTemperature(); // Read temperature - Commented out
  58.     // float humidity = gy21.readHumidity(); // Read humidity - Commented out
  59.    
  60.     // Print the temperature and humidity values to the Serial Monitor
  61.     // Serial.print("Temperature: ");
  62.     // Serial.print(temperature);
  63.     // Serial.println(" °C");
  64.    
  65.     // Serial.print("Humidity: ");
  66.     // Serial.print(humidity);
  67.     // Serial.println(" %");
  68. }
  69.  
  70. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement