LAUNCHING A ROCKET USING ARDUINO

Good morning,

I’d like to ask some questions regarding arduino coding. I got a project, specifically it is to open gate to launch a rocket and return it back to its original position and finally close the gate back.

I try to use Servo motor for the gate and it works but however, I don’t know how to launch the rocket (up and down). I got a 3 wire stepper motor (black, red and white). The problem is I don’t know how to code the stepper motor to work along with the servo and push button.

The mechanism is like this:

  1. Push button
  2. Gate opens
  3. Rocket launch
  4. Wait for 5 seconds
  5. Rocket return back
  6. Gate closed

Can you help me with this? I hope you can help me. Thank you so much.

This is the code that I recently used.

#include <Servo.h>;

// pushbutton pin
const int buttonPin = 8;
// servo pin
const int servoPin = 9;
Servo servo;
//create a variable to store a counter and set it to 0
int counter = 0;
void setup()
{
servo.attach (servoPin);

// Set up the pushbutton pins to be an input:
pinMode(buttonPin, INPUT);
}
void loop()
{
// local variable to hold the pushbutton states
int buttonState;
//read the digital state of buttonPin with digitalRead() function and store the //value in buttonState variable
buttonState = digitalRead(buttonPin);
//if the button is pressed increment counter and wait a tiny bit to give us some //time to release the button
if (buttonState == LOW) // light the LED
{
counter++;
delay(150);
}
if(counter == 0)
servo.write (20); // zero degrees
if(counter == 1)
servo.write(90);
//else reset the counter to 0 which resets thr servo to 0 degrees
else
counter = 0;
}

I am not sure what component you are calling a rocket. Do you have a link to it?
Next, please read the stickies above the forum and put your code into code tags.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

Thanks… Tom… :slight_smile:

So… something like this?

What is the stepper motor for?

#include <Servo.h>

const int buttonPin = 8;
const int servoPin = 9;
const byte LaunchPin = 2;

Servo servo;

//create a variable to store a counter and set it to 0
int counter = 0;

const int GateOpen = 90;
const int GateClosed = 20;

void setup()
{
  servo.write(GateClosed);  // Gate initially closed
  servo.attach(servoPin);

  // Set up the pushbutton pins to be an input:
  pinMode(buttonPin, INPUT_PULLUP);

  // Make sure launch pin is LOW before it is set to OUTPUT
  digitalWrite(LaunchPin, LOW);
  pinMode(LaunchPin, OUTPUT);
}

void loop()
{
  // 1. Push button
  if (digitalRead(buttonPin) == LOW)
  {
    // 2. Gate opens
    servo.write(GateOpen);
    delay(500); // Give the gate plenty of time to open
    
    // 3. Rocket launch
    digitalWrite(LaunchPin, HIGH);
    delay(100);  // Give the rocket time to clear the pad
    digitalWrite(LaunchPin, LOW);
    
    // 4. Wait for 5 seconds
    delay(5000);
    
    // 5. Rocket return back
    //????????????
    
    // 6. Gate closed
    servo.write(GateClosed);
    delay(500);  // Give the gate plenty of time to close
  }
}

This must be a joke!

Paul

The stepper model is DS04-NFC. Actually there a rod that is attach to the stepper (so that when it rotates, the rod that is tied along with the rocket can drag the rocket upward and downward)

The rocket is actually a 3D Printed rocket.

johnwasser:
So… something like this?

What is the stepper motor for?

#include <Servo.h>

const int buttonPin = 8;
const int servoPin = 9;
const byte LaunchPin = 2;

Servo servo;

//create a variable to store a counter and set it to 0
int counter = 0;

const int GateOpen = 90;
const int GateClosed = 20;

void setup()
{
  servo.write(GateClosed);  // Gate initially closed
  servo.attach(servoPin);

// Set up the pushbutton pins to be an input:
  pinMode(buttonPin, INPUT_PULLUP);

// Make sure launch pin is LOW before it is set to OUTPUT
  digitalWrite(LaunchPin, LOW);
  pinMode(LaunchPin, OUTPUT);
}

void loop()
{
  // 1. Push button
  if (digitalRead(buttonPin) == LOW)
  {
    // 2. Gate opens
    servo.write(GateOpen);
    delay(500); // Give the gate plenty of time to open
   
    // 3. Rocket launch
    digitalWrite(LaunchPin, HIGH);
    delay(100);  // Give the rocket time to clear the pad
    digitalWrite(LaunchPin, LOW);
   
    // 4. Wait for 5 seconds
    delay(5000);
   
    // 5. Rocket return back
    //???
   
    // 6. Gate closed
    servo.write(GateClosed);
    delay(500);  // Give the gate plenty of time to close
  }
}

Hi,
Can you post a picture of your project please, so we can see your component layout and see what your rocket is?
The servo is a continuous rotation type.

Thanks.. Tom.. :slight_smile:

NSR97:
The stepper model is DS04-NFC. Actually there a rod that is attach to the stepper (so that when it rotates, the rod that is tied along with the rocket can drag the rocket upward and downward)

The rocket is actually a 3D Printed rocket.

A “DS04-NFC” is not a stepper. It is a “continuous rotation servo”, basically a geared-down motor.

To use it, connect it like another servo:

#include <Servo.h>

const int buttonPin = 8;
const int servoPin = 9;
const byte RocketMotorPin = 2;

Servo GateServo;
const int GateOpen = 90;
const int GateClosed = 20;

Servo RocketMotor;  // Continuous Rotation Servo
const byte RocketUp = 70;  // Closer to 90 goes slower.  Closer to 0 goes faster.
const byte RocketStop = 90; // May need to be adjusted for your DS04-NFC
const byte RocketDown = 110; // Closer to 90 goes slower.  Closer to 180 goes faster.


void setup()
{
  GateServo.write(GateClosed);  // Gate initially closed
  GateServo.attach(servoPin);

  RocketMotor.write(RocketStop);
  RocketMotor.attach(RocketMotorPin);

  // Set up the pushbutton pins to be an input:
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{
  // 1. Push button
  if (digitalRead(buttonPin) == LOW)
  {
    // 2. Gate opens
    GateServo.write(GateOpen);
    delay(500); // Give the gate plenty of time to open

    // 3. Rocket launch
    RocketMotor.write(RocketUp);
    delay(5000);  // Time for rocket to reach the top
    RocketMotor.write(RocketStop);

    // 4. Wait for 5 seconds
    delay(5000);

    // 5. Rocket return back
    RocketMotor.write(RocketDown);
    delay(5000);  // Time for rocket to reach the bottom
    RocketMotor.write(RocketStop);

    // 6. Gate closed
    GateServo.write(GateClosed);
    delay(500);  // Give the gate plenty of time to close
  }
}