Water rocket automate parachute mechanism

Hi everyone!
I am a HUGE newbie
I've been working on a water rocket with automating parachute mechanism, for a school project.
and the parachute will be connected with the servo
so when the rocket tilts down the servo will spin something like 90°.
I've used a:
-gy-521 accelerometer
-Arduino Nano every (with headers)
-servo motor (from the officially Arduino starter kit)

and then I've looking for some examples with the gy-521 and then I found:

and I've found an example for a servo https://www.arduino.cc/en/Tutorial/Sweep

and then I've tried to combine them.
But can somebody make so the gy-521 is more critic so if the gy-521 rotate something like 90° and then activate the motor?
I've tried but it didn't work. :confused:

here is my code:

// (c) Michael Schoeffler 2017, http://www.mschoeffler.de

#include "Wire.h" // This library allows you to communicate with I2C devices.
#include <Servo.h>
const int MPU_ADDR=0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the I2C address will be 0x69.
Servo myservo;
int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data
int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
int16_t temperature; // variables for temperature data
int pos = 0;  
#define LED_LB 2 // LED left bottom
#define LED_RB 3 // LED right bottom
#define LED_RT 4 // LED right top
#define LED_LT 5 // LED left top

char tmp_str[7]; // temporary variable used in convert function

char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
  sprintf(tmp_str, "%6d", i);
  return tmp_str;
}

void setup() {
   myservo.attach(9);
  Serial.begin(9600);
  pinMode(LED_LB, OUTPUT);
  pinMode(LED_RB, OUTPUT);
  pinMode(LED_RT, OUTPUT);
  pinMode(LED_LT, OUTPUT);
  digitalWrite(LED_LB, LOW);
  digitalWrite(LED_RB, LOW);
  digitalWrite(LED_RT, LOW);
  digitalWrite(LED_LT, LOW);
  Wire.begin();
  Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board)
  Wire.write(0x6B); // PWR_MGMT_1 register
  Wire.write(0); // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
}
void loop() {
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions Revision 4.2, p.40]
  Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As a result, the connection is kept active.
  Wire.requestFrom(MPU_ADDR, 7*2, true); // request a total of 7*2=14 registers
  
  // "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
  accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L)
  accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L)
  accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) and 0x40 (ACCEL_ZOUT_L)
  temperature = Wire.read()<<8 | Wire.read(); // reading registers: 0x41 (TEMP_OUT_H) and 0x42 (TEMP_OUT_L)
  gyro_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44 (GYRO_XOUT_L)
  gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) and 0x46 (GYRO_YOUT_L)
  gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x47 (GYRO_ZOUT_H) and 0x48 (GYRO_ZOUT_L)
  
  // print out data
  Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x));
  Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y));
  Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z));
  // the following equation was taken from the documentation [MPU-6000/MPU-6050 Register Map and Description, p.30]
  Serial.print(" | tmp = "); Serial.print(temperature/340.00+36.53);
  Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x));
  Serial.print(" | gY = "); Serial.print(convert_int16_to_str(gyro_y));
  Serial.print(" | gZ = "); Serial.print(convert_int16_to_str(gyro_z));
  Serial.println();
  
  if (accelerometer_x < 1000 && accelerometer_y < -8000) {
      for (pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
    delay(15); 
    }                    
    digitalWrite(LED_LB, HIGH);
    digitalWrite(LED_RB, HIGH);
    digitalWrite(LED_RT, LOW);
    digitalWrite(LED_LT, LOW);
  } else if (accelerometer_x < 1000 && accelerometer_y > 8000) {
       for (pos = 0; pos <= 180; pos -= 1) {
    myservo.write(pos);
    delay(15); 
    }    
    digitalWrite(LED_LB, LOW);
    digitalWrite(LED_RB, LOW);
    digitalWrite(LED_RT, HIGH);
    digitalWrite(LED_LT, HIGH);
  } else if (accelerometer_x > 8000 && accelerometer_y < 1000) {   
    for (pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
    delay(15); 
    }    
    digitalWrite(LED_LB, LOW);
    digitalWrite(LED_RB, HIGH);
    digitalWrite(LED_RT, HIGH);
    digitalWrite(LED_LT, LOW);
  } else if (accelerometer_x < -8000 && accelerometer_y < 1000) {
    for (pos = 0; pos <= 180; pos -= 1) {
    myservo.write(pos);
    delay(15); 
    }    
    digitalWrite(LED_LB, HIGH);
    digitalWrite(LED_RB, LOW);
    digitalWrite(LED_RT, LOW);
    digitalWrite(LED_LT, HIGH);
  } else {
    digitalWrite(LED_LB, LOW);
    digitalWrite(LED_RB, LOW);
    digitalWrite(LED_RT, LOW);
    digitalWrite(LED_LT, LOW);
  }
  
  // delay
  delay(10);
}

Best regards Aleksander

Please explain why you think the rocket will point down? Are you doing something to make that happen?

Paul

So Then the rocket dont have more power the rocket/plastic bottle Will just tilt Down and then the parachute Will be activated

cicango:
So Then the rocket dont have more power the rocket/plastic bottle Will just tilt Down and then the parachute Will be activated

Let me ask again. Why do you think the rocket/bottle will "tilt" down? Have you actually launched the thing and can see it tilt down?

If you just toss it up, does it tilt down? If you drop it does it tilt down?

Paul

Does your "rocket" have fins on the back end?

Yeah me "water rocket" have fins and flies straight into the air.
I've had already tested it three times without Arduino.

cicango:
Yeah me "water rocket" have fins and flies straight into the air.
I've had already tested it three times without Arduino.

Now you tell us! With fins, the rocket will actually turn over sometime on it's way down to earth. If it has time before reaching the earth. Does that work for your original question?

Paul

I've tested it like 100 times now, and its rocket turns over every time.
But my interest was only the code
Sorry to say

Aleksander

Then you need a simple tilt switch and someway to inhibit it until after launch.

Paul

An accelerometer will record zero acceleration the moment the thrust has stopped - well, it'll record a small acceleration due to air resistance as it flies up, which then slowly drops to zero as it reaches the top of its trajectory, and then rises again until full gravity as the rocket reaches terminal velocity on the way down.

That, presuming you can filter out the noise of the signal as the rocket hurls through the air.

Your next challenge after removing the noise is to deduct the acceleration caused by the wind resistance to figure out whether the thing is turning, which is an integration of the acceleration data and thus adds a lot of error.

cicango:
But my interest was only the code

I realise that. You should realise we've become good in detecting XY problems. This thread is an excellent example of this.

A tilt sensor may be what you need, but do realise it needs sufficient downward speed - and thus air resistance - to work, for the same reason as the accelerometer doesn't work well to tell orientation!

But if the rocket chances Acceleration speed while flying in the air, the tilt sensor Might recognise it

The two main changes in acceleration are the moment the propulsion ends (acceleration drops; rocket continues to fly up for some distance) and when it hits the ground (massive spike in acceleration as the speed suddenly drops).

But when the accelerometer drops then just can make a time interval so for example after 5 sec. Then the parachute will release.

Aleksander

For regular rockets it's known very well for how long the motor will burn, and how long it'll be flying up. Just start the timer upon launch...

So just make a timer from the launch, and then hope the timer release the parachute at the right time?

Indeed. Will work wonders if your flight time is consistent - which may be an issue in case of water rockets.

But if timer is unsafe why just make a tilt down function so when the rocket tilts down the parachute will release?

As explained before... Because tilt sensors don't work reliably during the zero gravity part of the flight...

All of the water rockets I have seen are either going up or going down and I have seen very few tumble while trying to go up unless it was a poor launch in which case a parachute won't matter. The better designs have fins and a nose cone for stability. While fancy sensors are nice they likely present more problems than they are worth. Rocket makes a vertical trip up, when fuel (pressure) is expended it rotates 180 degrees and starts a vertical trip down. Some may reach 100 feet in altitude on a good day with a good design.

All I see a need for is a simple mercury tilt switch and if you are adverse to mercury just about any tilt switch. The rocket is either nose up or nose down.

Ron

I think a gyroscope is the device you need. Luckily it seems your module has both gyroscope and accelerometer so you should be able to use it well. I would try to add Arduino into the rocket and log the data to have some idea how they look.