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 Data**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-11-28 23:37:11
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The project must implement the LM35 sensor for */
- /* continuous temperature monitoring, with readings */
- /* taken from analog pin A0. The setup should include */
- /* necessary error handling for sensor malfunctions. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* read gyroscope and accelerometer and print on */
- /* serial. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <LM35.h> //https://github.com/wilmouths/LM35
- #include <BMI160.h> //https://github.com/EmotiBit/EmotiBit_BMI160
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF ANALOG INPUT PINS *****/
- const uint8_t temp_LM35_Vout_PIN_A0 = A0;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t accelerometer_BMI160_I2C_PIN_SDA_A4 = A4;
- const uint8_t accelerometer_BMI160_I2C_PIN_SCL_A5 = A5;
- const uint8_t accelerometer_BMI160_I2C_SLAVE_ADDRESS = 104;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- LM35 lm35(temp_LM35_Vout_PIN_A0); // Instantiate LM35 object
- BMI160 bmi160; // Instantiate BMI160 object
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(9600);
- // Set the LM35 pin as input
- pinMode(temp_LM35_Vout_PIN_A0, INPUT);
- // Initialize BMI160 sensor
- bmi160.initialize();
- if (!bmi160.testConnection()) {
- Serial.println("BMI160 connection failed!");
- while (1); // Halt the program if the sensor is not connected
- }
- }
- void loop(void)
- {
- // Read temperature from LM35
- double temperature = lm35.getTemp(); // Get temperature in Celsius
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" °C");
- // Read gyroscope and accelerometer data from BMI160
- int16_t ax, ay, az, gx, gy, gz;
- bmi160.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); // Get motion data
- Serial.print("Accelerometer: ");
- Serial.print("X: "); Serial.print(ax);
- Serial.print(", Y: "); Serial.print(ay);
- Serial.print(", Z: "); Serial.println(az);
- Serial.print("Gyroscope: ");
- Serial.print("X: "); Serial.print(gx);
- Serial.print(", Y: "); Serial.print(gy);
- Serial.print(", Z: "); Serial.println(gz);
- // Delay for a second before the next reading
- delay(1000);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement