Making a parachute deployment system for rocket

Hey Guys,
So I'm writing out some code for an Arduino nano that's hooked up to two Servos and the BMP180, the idea is that when the Altimeter realizes its hit apogee its will wait until it reaches a certain altitude to release the parachutes by turning the servo arm 90 degrees. I think the code should work, but its my first time programming with Arduino and I'd love some guidance.

So a bit of background knowledge of the code.

  • The code sets the starting altitude as zero
  • It reads out its code to the computer (for testing)
  • It sees if theirs a drop in altitude and if does it'll wait until it reaches its set altitude to deploy the servos
//---This sketch will make your altitude zero when you press the reset button---//
//---Allowing you to know increases and decreases in altitude based on your initial location---//
//---Altitude is in Meters---//

// Include the Wire library for I2C access.
#include <Wire.h>
// Include the BMP180 library.
#include <BMP180.h>
//inlcudes the Servo library
#include <Servo.h>

//------------ Store an instance of the BMP180 sensor. ----------------//
BMP180 barometer;
//------------ Use the on board LED for an indicator. -----------------//
int indicatorLed = 13; 


//--- Set current pressure & altitude, in this example it will be zero when we press reset button. ---//
int initialPressure = 0;
int initialAltitude = 0;
int lastAltitude;
Servo myservo; //create the Servo object.

void setup()
{
 initialPressure =  barometer.GetPressure();
 initialAltitude = barometer.GetAltitude(initialPressure);
 
 long currentPressure = barometer.GetPressure();
 float altitude = barometer.GetAltitude(initialPressure);
 // Start the serial library to output our messages.
 Serial.begin(9600);
 // Start the I2C on the Arduino for communication with the BMP180 sensor.
 Wire.begin();
 // Set up the Indicator LED.
 pinMode(indicatorLed, OUTPUT);
 // Check to see if connected to the sensor.
 if(barometer.EnsureConnected())
 {
   Serial.println("Connected to BMP180."); // Output - connected to the computer.
   digitalWrite(indicatorLed, HIGH); // Set our LED.
   
    // When connected, reset the device to ensure a clean start.
   barometer.SoftReset();
   // Initialize the sensor and pull the calibration data.
   barometer.Initialize();
 }
 else
 { 
   Serial.println("Not connected to BMP180.");
   digitalWrite(indicatorLed, LOW); // Set our LED.
 }
 myservo.attach( , ); //pins yet to be assigned
 myservo.write(0); //starting position is zero
}

void loop()
{
 if(barometer.IsConnected)
 {
   // Retrive the current pressure in Pascals.
   long currentPressure = barometer.GetPressure();
   
   // Retrive the current altitude (in meters).
   float altitude = barometer.GetAltitude(currentPressure);
   
   // Print out the Altitude.
   Serial.print("Altitude: ");
   Serial.print(altitude);
   Serial.print(" m");
   
   // Retrive the current temperature in degrees celcius.
   float currentTemperature = barometer.GetTemperature();
   
   Serial.println(); // Start a new line.
   delay(100); // Show new results every half second.
 }
 get altitude(); //gets the current altitude.
 if(altitude - lastaltitude <= -1) //checks for a 2 meter drop in altitude
{
  delay(100); //enough time to allow for the rocket to drop another amount to verify apogee was passed.
  get altitude(); //Gets altitude reading again
  if(altitude -lastAltitude <= -2) // checks to see if it decreased by 2 meters.
  {
    delay(150);
    get altitude;
    if(altitude - lastAltitude <= -3) //checks to see if it decreased y 3 meters.
    {
      if(altitude == 150) //altitude is not set but for now it works.
      myservo.write(90); //moves servo to open nose cone.
    }
    else
    {
      lastAltitude = altitude; //didnt fall 3 meters
    }
  }
  else
  {
    lastAltitude = altitude; //didnt fall 2 meters
  }
}
else
{
  lastAltitude = altitude; //didnt fall 1 meters
}
}

Thank You :smiley:

1 Like

Isn't the barometer an I2C device?

You're reading it before you initialise the I2C interface

 get altitude();
   get altitude;

Didn't the compiler bitch about that?

  if(altitude == 150) I imagine falling from 149 metres or 151 metres without a parachute could be a bit destructive.

AWOL:
Isn't the barometer an I2C device?

You're reading it before you initialise the I2C interface

What do you mean? Aren't you supposed to read the I2C first and then BMP180?
nvm I see what you mean.

get altitude(); //gets the current altitude.

Fixed.

Consoles also telling me that "Rocket_Code:59:5: error: 'barometer' was not declared in this scope

if(barometer.IsConnected)

^

Rocket_Code:78:2: error: 'get' was not declared in this scope

get altitude(); //gets the current altitude."

The deployment altitude is only temporary. max height is 261meter that's the intended height.

So, why didn't you post the error messages first time?
All of them.

AWOL:
So, why didn't you post the error messages first time?
All of them.

sorry didn't think of it.

Arduino: 1.8.8 (Windows 10), Board: "Arduino Nano, ATmega328P"

Rocket_Code:13:1: error: 'BMP180' does not name a type

 BMP180 barometer;

 ^

C:\Users\Daniel Borras\Documents\CLUB\Rocket Design\Rocket_Code\Rocket_Code.ino: In function 'void setup()':

Rocket_Code:26:21: error: 'barometer' was not declared in this scope

  initialPressure =  barometer.GetPressure();

                     ^

Rocket_Code:53:18: error: expected primary-expression before ',' token

  myservo.attach( , ); //pins yet to be assigned

                  ^

Rocket_Code:53:20: error: expected primary-expression before ')' token

  myservo.attach( , ); //pins yet to be assigned

                    ^

C:\Users\Daniel Borras\Documents\CLUB\Rocket Design\Rocket_Code\Rocket_Code.ino: In function 'void loop()':

Rocket_Code:59:5: error: 'barometer' was not declared in this scope

  if(barometer.IsConnected)

     ^

Rocket_Code:78:2: error: 'get' was not declared in this scope

  get altitude(); //gets the current altitude.

  ^

Rocket_Code:79:5: error: 'altitude' was not declared in this scope

  if(altitude - lastaltitude <= -1) //checks for a 2 meter drop in altitude

     ^

Rocket_Code:79:16: error: 'lastaltitude' was not declared in this scope

  if(altitude - lastaltitude <= -1) //checks for a 2 meter drop in altitude

                ^

Rocket_Code:82:7: error: expected ';' before 'altitude'

   get altitude(); //Gets altitude reading again

       ^

Rocket_Code:86:9: error: expected ';' before 'altitude'

     get altitude();

         ^

exit status 1
'BMP180' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Here's everything that the compiler is bitching about.