Hackster is hosting Impact Spotlights highlighting smart energy storage. Start streaming on Thursday!Stream Impact Spotlights on Thursday!
chocochunks
Published © GPL3+

Rocket Altimeter

Make an easy altimeter using a BMP280 Barometric Air Pressure Module with a OLED Display Module and an Arduino NANO.

IntermediateFull instructions provided2,235
Rocket Altimeter

Things used in this project

Hardware components

Grove - Barometer Sensor (BMP280)
Seeed Studio Grove - Barometer Sensor (BMP280)
BMP280 3.3V I2C SPI 1.8-5V digital Sensor Temperature Barometric Air Pressure Module For Arduino
×1
Arduino Nano R3
Arduino Nano R3
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Graphic OLED, 96 x 64
Graphic OLED, 96 x 64
0.96 inch IIC Serial 4pin Yellow Blue OLED Display Module 128X64 12864.
×1
Battery, 3.7 V
Battery, 3.7 V
3.7 volt 100mAh lithium battery.
×1
Breadboard (generic)
Breadboard (generic)
Prototype Board PCB 3x7cm board. Double Sided Prototype DIY Universal Protoboard Circuit Board
×1
5 mm LED: Red
5 mm LED: Red
Standard or Ultra bright.
×1
Buzzer
Buzzer
×1
LED, Blue
LED, Blue
Standard or Ultra bright.
×1
Resistor 100 ohm
Resistor 100 ohm
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Rosin
Solder Flux, Rosin

Story

Read more

Schematics

Rocket Altimeter Schematic

Code

RC_Altimeter_LARGE_DISPLAY.ino

Arduino
//V1   -BMP280 has an accuracy of +-3'.  The initial value is of no concern as the overall Altitude is determine by subtracting the MIN reading from the MAX reading. 
#include "U8glib.h"  //Find and Install this library
#include "BMP280.h"  //Find and Install this library
#include "Wire.h"  //Find and Install this library
#define P0 1013.25 //1021.97  //1013.25  //1028.86 //Height above sea level?  https://whatismyelevation.com/  I really need help with this
BMP280 bmp;

int piezoPin = 9;  //PIN 9 connected to BUZZERs POSITIVE PIN
int waiter = 0;  //Timers Initial State
int result;
int resulta;
int resultb;

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);  // OLED DISPLAY Type

char sT[20];
char sP[9];
char sA[9];
char sA_MIN[9];
char sA_MAX[9];
char sA_result[9];
char sA_resulta[9];
char sA_resultb[9];
double A_MIN = 0;
double A_MAX = 0;

void draw2(double T, double P, double A, double A_MIN, double A_MAX, double resulta) {
  u8g.setFont(u8g_font_unifont);

resulta = A_MAX - A_MIN;  //Determine difference in feet between the BMP's MIN and MAX readings
float resultb = resulta / 3.281;  //Result is in METERS

   dtostrf(A_MIN, 4, 2, sA_MIN);
   dtostrf(A_MAX, 4, 2, sA_MAX);
   dtostrf(resulta, 4, 4, sA_resulta);
   dtostrf(resultb, 4, 4, sA_resultb);
  dtostrf(T, 4, 2, sT);
  dtostrf(P, 4, 2, sP);
  dtostrf(A, 4, 2, sA);

  u8g.drawStr( 5, 10 , "Feet : ");
  u8g.drawStr( 60, 10, sA_resulta);

  u8g.drawStr( 5, 30 , "m : ");
  u8g.drawStr( 60, 30, sA_resultb);

  u8g.drawStr( 5, 45 , "TEMP : ");
  u8g.drawStr( 60, 45, sT);
 
  u8g.drawStr( 5, 62, sA_MAX);
  u8g.drawStr( 60, 62, sA_MIN);
  
}

void setup() {

 pinMode(2, OUTPUT);  //Set PIN 2 as an OUTPUT for the RED LED
 pinMode(3, OUTPUT);  //Set PIN 3 as an OUTPUT for the BLUE LED
 pinMode(4, OUTPUT);  //Set PIN 4 as an OUTPUT for the Green LED
  Serial.begin(9600);
  if (!bmp.begin()) {
    Serial.println("BMP init failed!");
    while (1);
  }
  else Serial.println("BMP init success!");

  bmp.setOversampling(4);

  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_unifont);
}


void loop(void) {

int redl = 2;  //Name Pin 2 redl
int white = 3; //Name PIN 3 white
int redr = 4; //Name Pin 4 redr

int wait = 50;  //delay in ms, 1000ms equals one second
int wait2 = 30;  // delay in ms, 1000ms equals one second
int wait3 = 10;  // delay in ms, 1000ms equals one second

waiter = waiter + 1;  //Increases the VALUE of WAITER by ONE every PROGRAM CYCLE
if (waiter >= 600) tone(piezoPin, 2000, 50);  // Set Buzzer Delay based on # of program cycles.  Sets Buzzers frequency and how long it beeps for

digitalWrite(redl, HIGH); // turn the redl LED ON
delay(wait2); // PAUSE
digitalWrite(redl, LOW); // turn the redl LED OFF
delay(wait); // PAUSE

digitalWrite(white, HIGH); // turn the white LED ON
delay(wait2); // PAUSE
digitalWrite(white, LOW); // turn the white LED OFF
delay(wait); //PAUSE

digitalWrite(redr, HIGH); // turn the redr LED ON
delay(wait2); // PAUSE
digitalWrite(redr, LOW); // turn the redr LED OFF
delay(wait); //PAUSE

  double T, P;
  char result = bmp.startMeasurment();

  if (result != 0) {
    delay(result);
    result = bmp.getTemperatureAndPressure(T, P);

    if (result != 0) {
      double A = bmp.altitude(P, P0);

      if ( A > A_MAX) {
        A_MAX = A;
      }

      if ( A < A_MIN || A_MIN == 0) {
        A_MIN = A;
      }

      do {
        draw2(T, P, A, A_MIN, A_MAX, resulta);    //(A_MIN, A_MAX, resulta);  //Tells the program to go to DRAW2
      } while ( u8g.nextPage() );
      u8g.firstPage();
      delay(wait3);
     
    }
    else {
      Serial.println("Error.");
    }
  }
  else {
    Serial.println("Error.");
  }

  delay(wait3);

}

Credits

chocochunks

chocochunks

3 projects • 2 followers

Comments