Advertisement
pleasedontcode

**Sensor Data** rev_08

Nov 28th, 2024
34
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 Data**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-28 23:59:14
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The project must implement the LM35 sensor for */
  21.     /* continuous temperature monitoring, with readings */
  22.     /* taken from analog pin A0. The setup should include */
  23.     /* necessary error handling for sensor malfunctions. */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* read gyroscope and accelerometer and print on */
  26.     /* serial. */
  27. /****** END SYSTEM REQUIREMENTS *****/
  28.  
  29. /* START CODE */
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <Wire.h>
  33. #include <LM35.h>   //https://github.com/wilmouths/LM35
  34. #include <BMI160Gen.h>  //https://github.com/EmotiBit/EmotiBit_BMI160
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39.  
  40. /***** DEFINITION OF ANALOG INPUT PINS *****/
  41. const uint8_t temp_LM35_Vout_PIN_A0 = A0;
  42.  
  43. /***** DEFINITION OF I2C PINS *****/
  44. const uint8_t accelerometer_BMI160_I2C_PIN_SDA_A4 = A4;
  45. const uint8_t accelerometer_BMI160_I2C_PIN_SCL_A5 = A5;
  46. const uint8_t accelerometer_BMI160_I2C_SLAVE_ADDRESS = 104;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. LM35 lm35(temp_LM35_Vout_PIN_A0); // Create LM35 object
  50. BMI160GenClass BMI160; // Create BMI160 object
  51.  
  52. void setup(void)
  53. {
  54.     // Initialize serial communication
  55.     Serial.begin(9600);
  56.    
  57.     // Initialize LM35 temperature sensor
  58.     pinMode(temp_LM35_Vout_PIN_A0, INPUT);
  59.    
  60.     // Initialize BMI160 sensor
  61.     if (!BMI160.begin(BMI160GenClass::I2C_MODE, Wire, accelerometer_BMI160_I2C_SLAVE_ADDRESS)) {
  62.         Serial.println("BMI160 initialization failed!");
  63.         while (1); // Halt if initialization fails
  64.     }
  65. }
  66.  
  67. void loop(void)
  68. {
  69.     // Read temperature from LM35
  70.     double temperature = lm35.getTemp(); // Get temperature in Celsius
  71.     Serial.print("Temperature: ");
  72.     Serial.print(temperature);
  73.     Serial.println(" °C");
  74.    
  75.     // Read gyroscope and accelerometer data from BMI160
  76.     int16_t ax, ay, az; // Accelerometer data
  77.     int16_t gx, gy, gz; // Gyroscope data
  78.    
  79.     BMI160.readAccelerometer(ax, ay, az);
  80.     BMI160.readGyroscope(gx, gy, gz);
  81.    
  82.     // Print accelerometer data
  83.     Serial.print("Accelerometer: ");
  84.     Serial.print(" ax: "); Serial.print(ax);
  85.     Serial.print(", ay: "); Serial.print(ay);
  86.     Serial.print(", az: "); Serial.println(az);
  87.    
  88.     // Print gyroscope data
  89.     Serial.print("Gyroscope: ");
  90.     Serial.print(" gx: "); Serial.print(gx);
  91.     Serial.print(", gy: "); Serial.print(gy);
  92.     Serial.print(", gz: "); Serial.println(gz);
  93.    
  94.     // Delay before the next reading
  95.     delay(1000); // Delay for 1 second
  96. }
  97.  
  98. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement