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:59:14
- ********* 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 <BMI160Gen.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); // Create LM35 object
- BMI160GenClass BMI160; // Create BMI160 object
- void setup(void)
- {
- // Initialize serial communication
- Serial.begin(9600);
- // Initialize LM35 temperature sensor
- pinMode(temp_LM35_Vout_PIN_A0, INPUT);
- // Initialize BMI160 sensor
- if (!BMI160.begin(BMI160GenClass::I2C_MODE, Wire, accelerometer_BMI160_I2C_SLAVE_ADDRESS)) {
- Serial.println("BMI160 initialization failed!");
- while (1); // Halt if initialization fails
- }
- }
- 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; // Accelerometer data
- int16_t gx, gy, gz; // Gyroscope data
- BMI160.readAccelerometer(ax, ay, az);
- BMI160.readGyroscope(gx, gy, gz);
- // Print accelerometer data
- Serial.print("Accelerometer: ");
- Serial.print(" ax: "); Serial.print(ax);
- Serial.print(", ay: "); Serial.print(ay);
- Serial.print(", az: "); Serial.println(az);
- // Print gyroscope data
- Serial.print("Gyroscope: ");
- Serial.print(" gx: "); Serial.print(gx);
- Serial.print(", gy: "); Serial.print(gy);
- Serial.print(", gz: "); Serial.println(gz);
- // Delay before the next reading
- delay(1000); // Delay for 1 second
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement