#include <WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
// WiFi credentials
const char* ssid = "your-ssid";
const char* password = "your-password";
// Pin configuration
#define ONE_WIRE_BUS 14 // Pin for DS18B20
#define OXYGEN_PIN 32 // Pin for custom oxygen sensor
// Create an instance of the MPU6050 class
Adafruit_MPU6050 mpu;
// Function prototypes
void connectToWiFi();
float readTemperature();
float readOxygenLevel();
void readAccelerometerAndGyroscope(float& accelX, float& accelY, float& accelZ, float& gyroX, float& gyroY, float& gyroZ);
void setup() {
Serial.begin(115200);
connectToWiFi();
// Initialize MPU6050 sensor
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
}
void loop() {
float temperature = readTemperature();
float oxygenLevel = readOxygenLevel();
float accelX, accelY, accelZ, gyroX, gyroY, gyroZ;
readAccelerometerAndGyroscope(accelX, accelY, accelZ, gyroX, gyroY, gyroZ);
// Send data to server or process as needed
Serial.print("Temperature: ");
Serial.println(temperature);
Serial.print("Oxygen Level: ");
Serial.println(oxygenLevel);
Serial.print("Accelerometer (X,Y,Z): ");
Serial.print(accelX);
Serial.print(", ");
Serial.print(accelY);
Serial.print(", ");
Serial.println(accelZ);
Serial.print("Gyroscope (X,Y,Z): ");
Serial.print(gyroX);
Serial.print(", ");
Serial.print(gyroY);
Serial.print(", ");
Serial.println(gyroZ);
delay(5000); // Adjust as needed for sampling frequency
}
void connectToWiFi() {
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected!");
}
float readTemperature() {
// Code to read temperature from DS18B20 sensor
}
float readOxygenLevel() {
// Code to read oxygen level from custom sensor
}
void readAccelerometerAndGyroscope(float& accelX, float& accelY, float& accelZ, float& gyroX, float& gyroY, float& gyroZ) {
sensors_event_t accelEvent, gyroEvent;
// Read accelerometer data
mpu.getEvent(&accelEvent, Adafruit_MPU6050::ACCEL_FORECAST);
accelX = accelEvent.acceleration.x;
accelY = accelEvent.acceleration.y;
accelZ = accelEvent.acceleration.z;
// Read gyroscope data
mpu.getEvent(&gyroEvent, Adafruit_MPU6050::GYRO_FORECAST);
gyroX = gyroEvent.gyro.x;
gyroY = gyroEvent.gyro.y;
gyroZ = gyroEvent.gyro.z;
}