Uniostar
Published © LGPL

Adafruit BMP280 + Micro SD Card Reader for Altimeter

Hey! Here you can find how to make a compact and simple altimeter data logger for model rockets and hiking adventures!

BeginnerFull instructions provided1 hour41
Adafruit BMP280 + Micro SD Card Reader for Altimeter

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Adafruit BMP 280
×1
Adafruit Micro SD Card Reader
×1
Perf+ 2
Crowd Supply Perf+ 2
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic

Code

Main Code

Arduino
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_BMP280.h>

Adafruit_BMP280 bmp;

float newAlt;
float alt;
float origAlt;
float temp;

const int chipSelect = 10; // Change if your CS pin is different
unsigned long lastLogTime = 0;

void setup() {
  Serial.begin(9600);
  while (!Serial);  // wait for serial on some boards

  Serial.println("Initializing BMP280...");
  if (!bmp.begin(0x76, 0x60)) {
    Serial.println("Error: BMP280 not found at 0x76");
    while (1);  // halt
  }

  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
                  Adafruit_BMP280::SAMPLING_X2,
                  Adafruit_BMP280::SAMPLING_X16,
                  Adafruit_BMP280::FILTER_X16,
                  Adafruit_BMP280::STANDBY_MS_500);

  origAlt = bmp.readAltitude(1013.25); // baseline altitude

  Serial.println("Initializing SD card...");
  if (!SD.begin(chipSelect)) {
    Serial.println("Error: SD init failed");
    while (1);
  }

  // Create or clear the log file at start
  File logFile = SD.open("altlog.txt", FILE_WRITE);
  if (logFile) {
    logFile.println("Altitude(ft)");
    logFile.close();
    Serial.println("SD card ready, logging started.");
  } else {
    Serial.println("Error: Can't create log file");
  }
}

void loop() {
  temp = bmp.readTemperature();
  newAlt = bmp.readAltitude(1013.25);

  if (newAlt > alt) {
    alt = newAlt;
  }

  float feet = (alt - origAlt) * 3.281;

  // Log altitude to SD every second
  if (millis() - lastLogTime >= 1000) {
    lastLogTime = millis();

    File logFile = SD.open("altlog.txt", FILE_WRITE);
    if (logFile) {
      logFile.println(feet, 2);
      logFile.close();
    } else {
      Serial.println("Error: Can't open altlog.txt for writing");
    }
  }
}

Credits

Uniostar
10 projects β€’ 8 followers
Electrical Engineering Undergrad Student specialized in low-level programming, IoT projects, and microcontroller electronics.

Comments