Devices & Components
Arduino Nano
LED, Blue
Grove - Barometer Sensor (BMP280)
Buzzer
Breadboard (generic)
Graphic OLED, 96 x 64
Battery, 3.7 V
Resistor 100 ohm
Jumper wires (generic)
5 mm LED: Red
Hardware & Tools
Solder Wire, Lead Free
Solder Flux, Rosin
Soldering iron (generic)
Software & Tools
Arduino IDE
Project description
Code
RC_Altimeter_LARGE_DISPLAY.ino
arduino
1//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. 2#include "U8glib.h" //Find and Install this library 3#include "BMP280.h" //Find and Install this library 4#include "Wire.h" //Find and Install this library 5#define P0 1013.25 //1021.97 //1013.25 //1028.86 //Height above sea level? https://whatismyelevation.com/ I really need help with this 6BMP280 bmp; 7 8int piezoPin = 9; //PIN 9 connected to BUZZERs POSITIVE PIN 9int waiter = 0; //Timers Initial State 10int result; 11int resulta; 12int resultb; 13 14U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // OLED DISPLAY Type 15 16char sT[20]; 17char sP[9]; 18char sA[9]; 19char sA_MIN[9]; 20char sA_MAX[9]; 21char sA_result[9]; 22char sA_resulta[9]; 23char sA_resultb[9]; 24double A_MIN = 0; 25double A_MAX = 0; 26 27void draw2(double T, double P, double A, double A_MIN, double A_MAX, double resulta) { 28 u8g.setFont(u8g_font_unifont); 29 30resulta = A_MAX - A_MIN; //Determine difference in feet between the BMP's MIN and MAX readings 31float resultb = resulta / 3.281; //Result is in METERS 32 33 dtostrf(A_MIN, 4, 2, sA_MIN); 34 dtostrf(A_MAX, 4, 2, sA_MAX); 35 dtostrf(resulta, 4, 4, sA_resulta); 36 dtostrf(resultb, 4, 4, sA_resultb); 37 dtostrf(T, 4, 2, sT); 38 dtostrf(P, 4, 2, sP); 39 dtostrf(A, 4, 2, sA); 40 41 u8g.drawStr( 5, 10 , "Feet : "); 42 u8g.drawStr( 60, 10, sA_resulta); 43 44 u8g.drawStr( 5, 30 , "m : "); 45 u8g.drawStr( 60, 30, sA_resultb); 46 47 u8g.drawStr( 5, 45 , "TEMP : "); 48 u8g.drawStr( 60, 45, sT); 49 50 u8g.drawStr( 5, 62, sA_MAX); 51 u8g.drawStr( 60, 62, sA_MIN); 52 53} 54 55void setup() { 56 57 pinMode(2, OUTPUT); //Set PIN 2 as an OUTPUT for the RED LED 58 pinMode(3, OUTPUT); //Set PIN 3 as an OUTPUT for the BLUE LED 59 pinMode(4, OUTPUT); //Set PIN 4 as an OUTPUT for the Green LED 60 Serial.begin(9600); 61 if (!bmp.begin()) { 62 Serial.println("BMP init failed!"); 63 while (1); 64 } 65 else Serial.println("BMP init success!"); 66 67 bmp.setOversampling(4); 68 69 u8g.setColorIndex(1); 70 u8g.setFont(u8g_font_unifont); 71} 72 73 74void loop(void) { 75 76int redl = 2; //Name Pin 2 redl 77int white = 3; //Name PIN 3 white 78int redr = 4; //Name Pin 4 redr 79 80int wait = 50; //delay in ms, 1000ms equals one second 81int wait2 = 30; // delay in ms, 1000ms equals one second 82int wait3 = 10; // delay in ms, 1000ms equals one second 83 84waiter = waiter + 1; //Increases the VALUE of WAITER by ONE every PROGRAM CYCLE 85if (waiter >= 600) tone(piezoPin, 2000, 50); // Set Buzzer Delay based on # of program cycles. Sets Buzzers frequency and how long it beeps for 86 87digitalWrite(redl, HIGH); // turn the redl LED ON 88delay(wait2); // PAUSE 89digitalWrite(redl, LOW); // turn the redl LED OFF 90delay(wait); // PAUSE 91 92digitalWrite(white, HIGH); // turn the white LED ON 93delay(wait2); // PAUSE 94digitalWrite(white, LOW); // turn the white LED OFF 95delay(wait); //PAUSE 96 97digitalWrite(redr, HIGH); // turn the redr LED ON 98delay(wait2); // PAUSE 99digitalWrite(redr, LOW); // turn the redr LED OFF 100delay(wait); //PAUSE 101 102 double T, P; 103 char result = bmp.startMeasurment(); 104 105 if (result != 0) { 106 delay(result); 107 result = bmp.getTemperatureAndPressure(T, P); 108 109 if (result != 0) { 110 double A = bmp.altitude(P, P0); 111 112 if ( A > A_MAX) { 113 A_MAX = A; 114 } 115 116 if ( A < A_MIN || A_MIN == 0) { 117 A_MIN = A; 118 } 119 120 do { 121 draw2(T, P, A, A_MIN, A_MAX, resulta); //(A_MIN, A_MAX, resulta); //Tells the program to go to DRAW2 122 } while ( u8g.nextPage() ); 123 u8g.firstPage(); 124 delay(wait3); 125 126 } 127 else { 128 Serial.println("Error."); 129 } 130 } 131 else { 132 Serial.println("Error."); 133 } 134 135 delay(wait3); 136 137} 138
Downloadable files
Rocket Altimeter Schematic
Rocket Altimeter Schematic
Comments
Only logged in users can leave comments