Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega 2560 Based Environmental and Position Tracking System

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Based Environmental and Position Tracking System

Circuit Documentation

Summary

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.

Component List

Arduino Mega 2560

BMP280

MPU-6050

GPS NEO 6M

Wiring Details

Arduino Mega 2560

BMP280

MPU-6050

GPS NEO 6M

Documented Code

#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.