CCCPaste

**Sensor Data** rev_10

/********* 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-29 00:03:49

********* 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 
#include 	// https://github.com/wilmouths/LM35
#include 	// 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
BMI160GenClass BMI160; // Instantiate BMI160 object

void setup(void)
{
	// put your setup code here, to run once:
	pinMode(temp_LM35_Vout_PIN_A0, INPUT);
	Serial.begin(9600); // Initialize serial communication

	// Initialize BMI160 sensor
	if (!BMI160.begin(BMI160GenClass::I2C_MODE, Wire, accelerometer_BMI160_I2C_SLAVE_ADDRESS)) {
		Serial.println("BMI160 initialization failed!");
		while (1); // Stop execution if sensor fails
	}
}

void loop(void)
{
	// Read temperature from LM35 sensor
	double temperature = lm35.getTemp(); // Get temperature in Celsius
	Serial.print("Temperature: ");
	Serial.print(temperature);
	Serial.println(" °C");

	// Read gyroscope and accelerometer data
	// Assuming that the BMI160 library has methods to read gyro and accel data
	int16_t ax, ay, az, gx, gy, gz;
	BMI160.readAccelerometer(ax, ay, az); // Read accelerometer values
	BMI160.readGyroscope(gx, gy, gz); // Read gyroscope values

	// Print accelerometer data
	Serial.print("Accelerometer: ");
	Serial.print("X: "); Serial.print(ax);
	Serial.print(", Y: "); Serial.print(ay);
	Serial.print(", Z: "); Serial.println(az);

	// Print gyroscope data
	Serial.print("Gyroscope: ");
	Serial.print("X: "); Serial.print(gx);
	Serial.print(", Y: "); Serial.print(gy);
	Serial.print(", Z: "); Serial.println(gz);

	delay(1000); // Delay for readability
}

/* END CODE */