Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

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

Image 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

  • VIN and 5V pins are connected to the positive output of the LM2596 buck converter.
  • GND is connected to the common ground net.
  • A4 (SDA) and A5 (SCL) are connected to the I2C bus for communication with the BME680 and MPU6050 sensors.
  • D9 controls the gate of the IRF520 MOSFET through a 1k Ohm resistor.
  • D10 (CS), D11/MOSI, D12/MISO, and D13/SCK are connected to the corresponding pins on the SD card module for SPI communication.

Adafruit BME680

  • VCC is connected to the 5V net.
  • GND is connected to the common ground net.
  • SCK/SCL and SDI/SDA are connected to the I2C bus (Arduino Nano A5 and A4 respectively).

9V Battery

  • + is connected to the positive input of the LM2596 buck converter and the Pin A of the Terminal PCB 2 Pin.
  • - is connected to the common ground net.

InvenSense MPU6050

  • VCC is connected to the 5V net.
  • GND is connected to the common ground net.
  • SCL and SDA are connected to the I2C bus (Arduino Nano A5 and A4 respectively).

SD Card Module

  • VCC is connected to the 5V net.
  • GND is connected to the common ground net.
  • CS, MOSI, MISO, and SCK are connected to the corresponding SPI pins on the Arduino Nano (D10, D11/MOSI, D12/MISO, and D13/SCK respectively).

Terminal PCB 2 Pin

  • Pin A is connected to the positive terminal of the 9V battery.
  • Pin B is connected to the Drain of the IRF520.

LM2596 Buck Converter

  • Positive Input is connected to the + of the 9V battery.
  • Negative Input is connected to the common ground net.
  • Positive Output is connected to the VIN and 5V of the Arduino Nano.

IRF520

  • Gate is connected to the D9 of the Arduino Nano through a 1k Ohm resistor.
  • Drain is connected to the Pin B of the Terminal PCB 2 Pin.
  • Source is connected to the common ground net.

Resistor (1k Ohm)

  • pin1 is connected to the common ground net.
  • pin2 is connected to the Gate of the IRF520 and D9 on the Arduino Nano.

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.