Arduino Nano-Based Environmental Data Logger with Altitude Triggered MOSFET Control
View and Edit Project In Cirkit Designer
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
VINand5Vpins are connected to the positive output of the LM2596 buck converter.GNDis connected to the common ground net.A4(SDA) andA5(SCL) are connected to the I2C bus for communication with the BME680 and MPU6050 sensors.D9controls the gate of the IRF520 MOSFET through a 1k Ohm resistor.D10(CS),D11/MOSI,D12/MISO, andD13/SCKare connected to the corresponding pins on the SD card module for SPI communication.
Adafruit BME680
VCCis connected to the 5V net.GNDis connected to the common ground net.SCK/SCLandSDI/SDAare connected to the I2C bus (Arduino NanoA5andA4respectively).
9V Battery
+is connected to the positive input of the LM2596 buck converter and thePin Aof the Terminal PCB 2 Pin.-is connected to the common ground net.
InvenSense MPU6050
VCCis connected to the 5V net.GNDis connected to the common ground net.SCLandSDAare connected to the I2C bus (Arduino NanoA5andA4respectively).
SD Card Module
VCCis connected to the 5V net.GNDis connected to the common ground net.CS,MOSI,MISO, andSCKare connected to the corresponding SPI pins on the Arduino Nano (D10,D11/MOSI,D12/MISO, andD13/SCKrespectively).
Terminal PCB 2 Pin
Pin Ais connected to the positive terminal of the 9V battery.Pin Bis connected to theDrainof the IRF520.
LM2596 Buck Converter
Positive Inputis connected to the+of the 9V battery.Negative Inputis connected to the common ground net.Positive Outputis connected to theVINand5Vof the Arduino Nano.
IRF520
Gateis connected to theD9of the Arduino Nano through a 1k Ohm resistor.Drainis connected to thePin Bof the Terminal PCB 2 Pin.Sourceis connected to the common ground net.
Resistor (1k Ohm)
pin1is connected to the common ground net.pin2is connected to theGateof the IRF520 andD9on 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.