This circuit is designed to interface an Arduino Mega 2560 with a BMP280 barometric pressure sensor, an MPU-6050 accelerometer/gyroscope, and a GPS NEO 6M module. The Arduino Mega 2560 serves as the central processing unit, collecting data from the sensors and providing output through its serial interface. The BMP280 and MPU-6050 are connected via the I2C bus, while the GPS NEO 6M module communicates with the Arduino through a serial connection.
D20/SDA
connected to SDA pins of BMP280 and MPU-6050.D21/SCL
connected to SCL pins of BMP280 and MPU-6050.3V3
connected to VCC of BMP280.5V
connected to VCC of MPU-6050 and GPS NEO 6M.GND
connected to GND pins of BMP280, MPU-6050, and GPS NEO 6M.D19/RX1
connected to TX of GPS NEO 6M.D18/TX1
connected to RX of GPS NEO 6M.SDA
connected to D20/SDA
on Arduino Mega 2560.SCL
connected to D21/SCL
on Arduino Mega 2560.VCC
connected to 3V3
on Arduino Mega 2560.GND
connected to GND
on Arduino Mega 2560.SDA
connected to D20/SDA
on Arduino Mega 2560.SCL
connected to D21/SCL
on Arduino Mega 2560.VCC
connected to 5V
on Arduino Mega 2560.GND
connected to GND
on Arduino Mega 2560.RX
connected to D18/TX1
on Arduino Mega 2560.TX
connected to D19/RX1
on Arduino Mega 2560.VCC
connected to 5V
on Arduino Mega 2560.GND
connected to GND
on Arduino Mega 2560.#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <MPU6050.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
// Create instances of the sensor libraries
Adafruit_BMP280 bmp; // I2C
MPU6050 mpu;
TinyGPSPlus gps;
SoftwareSerial gpsSerial(4, 3); // RX, TX
void setup() {
// Initialize serial communication
Serial.begin(115200);
gpsSerial.begin(9600);
// Initialize BMP280
if (!bmp.begin(0x76)) { // BMP280 I2C address is 0x76 or 0x77
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
Serial.println(F("BMP280 initialized"));
// Initialize MPU6050
Wire.begin();
mpu.initialize();
if (!mpu.testConnection()) {
Serial.println(F("MPU6050 connection failed"));
while (1);
}
Serial.println(F("MPU6050 initialized"));
// Initialize GPS
Serial.println(F("GPS module initialized"));
}
void loop() {
// Read data from BMP280
float temperature = bmp.readTemperature();
float pressure = bmp.readPressure();
Serial.print(F("Temperature = "));
Serial.print(temperature);
Serial.println(F(" *C"));
Serial.print(F("Pressure = "));
Serial.print(pressure / 100.0F);
Serial.println(F(" hPa"));
// Read data from MPU6050
int16_t ax, ay, az;
int16_t gx, gy, gz;
mpu.getAcceleration(&ax, &ay, &az);
mpu.getRotation(&gx, &gy, &gz);
// Convert to g and degrees/s
float ax_g = ax / 16384.0; // Scale factor for accelerometer
float ay_g = ay / 16384.0; // Scale factor for accelerometer
float az_g = az / 16384.0; // Scale factor for accelerometer
float gx_dps = gx / 131.0; // Scale factor for gyroscope
float gy_dps = gy / 131.0; // Scale factor for gyroscope
float gz_dps = gz / 131.0; // Scale factor for gyroscope
Serial.print(F("Accel X = "));
Serial.print(ax_g);
Serial.print(F(", Y = "));
Serial.print(ay_g);
Serial.print(F(", Z = "));
Serial.println(az_g);
Serial.print(F("Gyro X = "));
Serial.print(gx_dps);
Serial.print(F(", Y = "));
Serial.print(gy_dps);
Serial.print(F(", Z = "));
Serial.println(gz_dps);
// Read data from GPS
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
if (gps.location.isUpdated()) {
Serial.print(F("Latitude= "));
Serial.print(gps.location.lat(), 6);
Serial.print(F(", Longitude= "));
Serial.print(gps.location.lng(), 6);
Serial.print(F(", Altitude= "));
Serial.print(gps.altitude.meters());
Serial.println(F(" meters"));
}
}
delay(1000); // Delay 1 second between readings
}
This code initializes the sensors connected to the Arduino Mega 2560 and reads data from them in a continuous loop. The BMP280 sensor provides temperature and pressure readings, the MPU-6050 provides acceleration and gyroscope data, and the GPS NEO 6M provides location data. The data is printed to the serial monitor for observation.