Joshua TowleJLCPCB
Published

Rocket avionics ESP32 project | JLC PCB

"Building a custom low-altitude rocket with ESP32-based avionics to record and share data. Open source, step-by-step, and full of passion!

AdvancedWork in progress7 hours218
Rocket avionics ESP32 project | JLC PCB

Things used in this project

Hardware components

ESP32-WROOM-32D-N8
×1
TERM BLK 2POS SIDE ENTRY 5MM
×1
TERM BLK 3POS SIDE ENT 3.5MM
×1
RELAY GEN PURPOSE SPDT 16A 5V
×1
TRANS NPN 45V 0.5A TO-236AB
×1
CONN MICRO SD CARD HINGED TYPE
×1
SENSOR DIGITAL -40C-125C 8MSOP
×1
IC REG LINEAR 3.3V 1A SOT223-4
×1
SWITCH TACTILE SPST-NO 0.05A 12V
×3
LED RGB CLEAR 4SMD
×4
MOSFET N-CH 100V 9.2A D2PAK
×4
CONN HEADER VERT 10POS 2.54MM
×4
CONN HEADER VERT 6POS 2.54MM
×4
SMD 1206 Electronic Components Assortment Book
All the smd components will be in this book
×1

Software apps and online services

KiCad
KiCad
EasyEDA
JLCPCB EasyEDA

Hand tools and fabrication machines

Solder Paste, Rework
Solder Paste, Rework
Soldering Station, 110 V
Soldering Station, 110 V
Solder Wire, 0.022" Diameter
Solder Wire, 0.022" Diameter
Solder Flux, Soldering
Solder Flux, Soldering
Hot Plate, 800 W
Hot Plate, 800 W
Tweezers, SMD Soldering/Desoldering
Tweezers, SMD Soldering/Desoldering

Story

Read more

Schematics

PCB FILES

all of this is if you just wanna be a lame person and just download the files to send off. If i were you though, I would try and follow the steps and learn how all this works.

Code

ESP32 code (Arduino)

Arduino
Here's the most updated code at the moment (12/15/24). I will update it accordingly
// Pin 5 control with TX LED blink and additional functionality

#include <SD.h>
#include <Adafruit_MPL3115A2.h>

#define PIN_SPI_CS 4
#define BUTTON_PIN_START 8
#define BUTTON_PIN_RESET 9
#define LED_PIN 3
#define PIN_5 5

File myFile;
Adafruit_MPL3115A2 baro;
unsigned long loggingStartTime = 0;
const unsigned long loggingDuration = 180000; // 3 minutes in milliseconds
const unsigned long postLoggingFlashInterval = 3000; // 3 seconds
const unsigned long totalDuration = 300000; // 5 minutes in milliseconds
boolean loggingStarted = false;
boolean resetPressed = false;
boolean postLoggingFlashing = false;
boolean pin5TurnedOn = false;

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN_START, INPUT);
  pinMode(BUTTON_PIN_RESET, INPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(PIN_5, OUTPUT);
  digitalWrite(BUTTON_PIN_START, LOW); // Enable internal pull-down resistor
  digitalWrite(BUTTON_PIN_RESET, LOW); // Enable internal pull-down resistor

  if (!SD.begin(PIN_SPI_CS)) {
    Serial.println(F("SD CARD FAILED, OR NOT PRESENT!"));
    while (1); // don't do anything more
  }

  Serial.println(F("SD CARD INITIALIZED."));

  if (!SD.exists("arduino.txt")) {
    Serial.println(F("arduino.txt doesn't exist. Creating arduino.txt file..."));
    myFile = SD.open("arduino.txt", FILE_WRITE);
    if (myFile) {
      myFile.close();
      Serial.println(F("Text written to arduino.txt file."));
    } else {
      Serial.println(F("Error opening arduino.txt file."));
    }
  } else {
    Serial.println(F("arduino.txt exists on SD Card."));
  }

  Serial.println("Adafruit_MPL3115A2 test!");

  if (!baro.begin()) {
    Serial.println("Could not find sensor. Check wiring.");
    while(1);
  }

  // use to set sea level pressure for the current location
  // this is needed for accurate altitude measurement
  // STD SLP = 1013.26 hPa
  baro.setSeaPressure(1013.26);
}

void loop() {
  unsigned long currentMillis = millis();

  if (digitalRead(BUTTON_PIN_START) == HIGH && !loggingStarted) {
    loggingStartTime = currentMillis;
    loggingStarted = true;
    Serial.println(F("Logging started."));
  }

  if (digitalRead(BUTTON_PIN_RESET) == HIGH && !resetPressed) {
    resetPressed = true;
    baro.setSeaPressure(baro.getPressure()); // Reset sea level pressure
    Serial.println(F("Sea level pressure reset."));
  } else if (resetPressed && digitalRead(BUTTON_PIN_RESET) == LOW) {
    resetPressed = false;
  }

  if (loggingStarted && (currentMillis - loggingStartTime) < loggingDuration) {
    flashLed(); // Flash LED during logging

    // Check if 8.1 seconds into the countdown
    if ((currentMillis - loggingStartTime) >= 9100 && !pin5TurnedOn) {
      // Turn on pin 5 for 0.5 second
      digitalWrite(PIN_5, HIGH);
      delay(500);
      digitalWrite(PIN_5, LOW);
      pin5TurnedOn = true;
      // Write "Parachute deployed" to SD card
      myFile = SD.open("arduino.txt", FILE_WRITE);
      if (myFile) {
        myFile.println("Parachute deployed");
        myFile.close();
        Serial.println(F("Parachute deployed. Written to arduino.txt file."));
      } else {
        Serial.println(F("Error opening arduino.txt file for writing."));
      }
    }

    float pressure = baro.getPressure();
    float altitude = baro.getAltitude();
    float temperature = baro.getTemperature();

    Serial.println("-----------------");
    Serial.print("pressure = "); Serial.print(pressure); Serial.println(" hPa");
    Serial.print("altitude = "); Serial.print(altitude); Serial.println(" m");
    Serial.print("temperature = "); Serial.print(temperature); Serial.println(" C");

    // Append the altitude information to the SD card
    myFile = SD.open("arduino.txt", FILE_WRITE);
    if (myFile) {
      myFile.println("-----------------");
      myFile.print("pressure = "); myFile.print(pressure); myFile.println(" hPa");
      myFile.print("altitude = "); myFile.print(altitude); myFile.println(" m");
      myFile.print("temperature = "); myFile.print(temperature); myFile.println(" C");
      myFile.close();
      Serial.println(F("Altitude information written to arduino.txt file."));
    } else {
      Serial.println(F("Error opening arduino.txt file for writing."));
    }
  } else if (loggingStarted) {
    loggingStarted = false;
    Serial.println(F("Logging stopped."));
    postLoggingFlashing = true; // Set the flag for post-logging flashing
  }

  if (postLoggingFlashing) {
    postLoggingFlash(); // Flash LED after logging

    if (currentMillis - loggingStartTime >= totalDuration) {
      // Turn off LED after 5 minutes
      digitalWrite(LED_PIN, LOW);
      postLoggingFlashing = false; // Reset the flag
      sendCompletionMessage(); // Send completion message to the SD card
    }
  }

  delay(250); // Adjust delay as needed
}

void flashLed() {
  static unsigned long previousMillis = 0;
  const unsigned long interval = 100; // Flashing interval in milliseconds

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    // Toggle the LED state
    if (digitalRead(LED_PIN) == HIGH) {
      digitalWrite(LED_PIN, LOW);
    } else {
      digitalWrite(LED_PIN, HIGH);
    }
  }
}

void postLoggingFlash() {
  static unsigned long previousMillis = 0;
  const unsigned long interval = postLoggingFlashInterval;

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    // Toggle the LED state
    if (digitalRead(LED_PIN) == HIGH) {
      digitalWrite(LED_PIN, LOW);
    } else {
      digitalWrite(LED_PIN, HIGH);
    }
  }
}

void sendCompletionMessage() {
  myFile = SD.open("arduino.txt", FILE_WRITE);
  if (myFile) {
    myFile.println("Flight has completed");
    myFile.close();
    Serial.println(F("Completion message written to arduino.txt file."));
  } else {
    Serial.println(F("Error opening arduino.txt file for writing completion message."));
  }
}

Credits

Joshua Towle
1 project • 0 followers
Contact
JLCPCB
74 projects • 48 followers
JLCPCB, is the largest PCB and PCB Assembly prototype enterprise in Asia. Coupon code "JLCPCBcom" for all and permanantly available.
Contact
Thanks to Pieter dirk and pieterinhetbos.

Comments

Please log in or sign up to comment.