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

Arduino Nano-Based Environmental Data Logger with Altitude Triggered MOSFET Control

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Environmental Data Logger with Altitude Triggered MOSFET Control

Circuit Documentation

Summary

This circuit integrates an Arduino Nano microcontroller with a variety of sensors and modules, including the Adafruit BME680 environmental sensor, the InvenSense MPU6050 accelerometer and gyroscope, an SD card module for data logging, and an IRF520 MOSFET for controlling power to an external device. The circuit is powered by a 9V battery, regulated down to 5V by an LM2596 buck converter. The Arduino Nano facilitates data collection and logging, as well as dynamic control based on sensor inputs.

Component List

Arduino Nano

A compact microcontroller board based on the ATmega328P, featuring digital and analog I/O pins, serial communication capabilities, and a USB interface for programming and power.

Adafruit BME680

An integrated environmental sensor developed by Adafruit, capable of measuring temperature, humidity, barometric pressure, and indoor air quality.

9V Battery

A standard 9V battery providing the primary power source for the circuit.

InvenSense MPU6050

A motion-tracking device that contains a 3-axis accelerometer and a 3-axis gyroscope, allowing for the detection of acceleration and rotational movement.

SD Card Module

A module that allows an SD card to be interfaced with a microcontroller for data storage purposes.

Terminal PCB 2 Pin

A simple two-pin terminal block PCB for making secure electrical connections to external devices.

LM2596 Buck Converter

A voltage regulator module that steps down input voltage to a lower, regulated output voltage.

IRF520

A power MOSFET used for switching heavy loads with a small control signal.

Resistor (1k Ohm)

A passive electrical component providing resistance to the flow of electric current, in this case, 1k Ohm.

Wiring Details

Arduino Nano

Adafruit BME680

9V Battery

InvenSense MPU6050

SD Card Module

Terminal PCB 2 Pin

LM2596 Buck Converter

IRF520

Resistor (1k Ohm)

Documented Code

#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>
#include <SD.h>

const int MOSFET_PIN = 9;
const int SD_CS_PIN = 10;

Adafruit_MPU6050 mpu;
Adafruit_BME680 bme;

#define SEALEVELPRESSURE_HPA (1013.25)

float maxAltitude = 0;
File dataFile;

void setup() {
  pinMode(MOSFET_PIN, OUTPUT);
  digitalWrite(MOSFET_PIN, LOW);

  SD.begin(SD_CS_PIN);
  dataFile = SD.open("data.csv", FILE_WRITE);

  mpu.begin();
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);

  bme.begin();
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150);
}

void loop() {
  sensors_event_t a, g, temp_mpu;
  mpu.getEvent(&a, &g, &temp_mpu);

  if (!bme.performReading()) return;

  dataFile.print(a.acceleration.x); dataFile.print(",");
  dataFile.print(a.acceleration.y); dataFile.print(",");
  dataFile.print(a.acceleration.z); dataFile.print(",");
  dataFile.print(g.gyro.x); dataFile.print(",");
  dataFile.print(g.gyro.y); dataFile.print(",");
  dataFile.print(g.gyro.z); dataFile.print(",");
  dataFile.print(temp_mpu.temperature); dataFile.print(",");
  dataFile.print(bme.temperature); dataFile.print(",");
  dataFile.print(bme.pressure / 100.0); dataFile.print(",");
  dataFile.print(bme.humidity); dataFile.print(",");
  dataFile.print(bme.gas_resistance / 1000.0); dataFile.print(",");
  dataFile.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
  dataFile.flush();

  float altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);

  if (altitude > maxAltitude) {
    maxAltitude = altitude;
  } else if (altitude < maxAltitude - 7) {
    digitalWrite(MOSFET_PIN, HIGH);
  } else {
    digitalWrite(MOSFET_PIN, LOW);
  }

  delay(1000);
}

This code initializes and reads data from the MPU6050 and BME680 sensors, logs the data to an SD card, and controls a MOSFET based on altitude changes. The setup() function configures the sensors and opens the SD card file for writing. The loop() function reads sensor data, writes it to the SD card, and toggles the MOSFET based on the altitude reading.