// Balloon payload cut-down program // // Hardware: Arduino Uno microcontroller and RC servo // Project: CSCI Solar Balloon project // // Author Morgan Miller, University of North Dakota REU July 2017 #include #include #define beta 3950 //the beta of the thermistor Servo myservo; // create servo object to control a servo const int arraySize = 120; const int readTempInterval = 15; //15 read temperature every X seconds int cutdownClock = 1800; // Master mission clock, seconds to cut-down // 3600 seconds per hour // 14400 seconds = four hours float insideTemperature; float outsideTemperature; float insideTempsArray[arraySize]; float outsideTempsArray[arraySize]; boolean cutDown = 0; boolean cutdownMotorIsSet = 0; const int analogInsideTemperaturePin = 0; const int analogOutsideTemperaturePin = 1; const int eepromActivityLight = 7; const int eepromSwitch = 4; int tempCounter = 0; // number of temperature readings int flightTime = 0; int eepromAddress = 1; // 0 is for temp counter void setup() { myservo.attach(8); // attaches the servo on digital pin 8 to the servo object pinMode(eepromActivityLight,OUTPUT); pinMode(eepromSwitch,INPUT); Serial.begin(9600); unsigned char eepromCounter = (unsigned char)EEPROM.read(0); if(eepromCounter != 0) { Serial.println("EEPROM contains data. Flip switch to overwrite"); } while(eepromCounter != 0) { //blink eeprom actuvity light digitalWrite(eepromActivityLight, HIGH); delay(100); digitalWrite(eepromActivityLight, LOW); delay(100); // run erase if eeprom switch is on if(digitalRead(eepromSwitch) == HIGH) { erase(); } char readEEPROM = Serial.read(); if(readEEPROM == 'r') { printEEPROM(); } eepromCounter = (unsigned char)EEPROM.read(0);// make sure that erase worked } } void loop(){ // we only need to close the servo once if (cutdownMotorIsSet == 0) { myservo.write(90); // run servo to 0 degrees (cutdown locked) cutdownMotorIsSet = 1; Serial.println("Starting launch"); } // get temperature readings every mod seconds if(((cutdownClock - flightTime) % readTempInterval) == 0 && tempCounter < arraySize) { // get temperature of inside satellite long a =1023 - analogRead(analogInsideTemperaturePin); //read thermistor value float tempC = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0; insideTemperature = 1.8*tempC + 32.0; //convert celsius to fahrenheit insideTempsArray[tempCounter] = insideTemperature; // get temperature of outside satellite a =1023 - analogRead(analogOutsideTemperaturePin); //read thermistor value tempC = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0; outsideTemperature = 1.8*tempC + 32.0; //convert celsius to fahrenheit outsideTempsArray[tempCounter] = outsideTemperature; // write to EEPROM if(eepromAddress < EEPROM.length()) { insideTemperature += 50; outsideTemperature += 50; unsigned char insideTmp = (unsigned char)floor(insideTemperature + 0.5); unsigned char outsideTmp = (unsigned char)floor(outsideTemperature + 0.5); EEPROM.write(eepromAddress, insideTmp); eepromAddress += sizeof(unsigned char); EEPROM.write(eepromAddress, outsideTmp); eepromAddress += sizeof(unsigned char); } tempCounter++; unsigned char counter = (unsigned char)tempCounter; EEPROM.write(0, counter); } // cutdown if time runs out if((cutdownClock - flightTime) <= 0 && cutDown == 0) { myservo.write(0); // run servo to 90 degrees (cutdown release) cutDown = 1; Serial.println("Cut Down"); delay(3000); // wait 3 seconds for servo to open and payload to release flightTime += 3; } flightTime++; delay(1000); // wait 1 second // print out recorded temps if(Serial) { printTemps(); } } void printTemps() { Serial.println("Inside Temps"); for(int i = 0; i < tempCounter; i++) { Serial.println(insideTempsArray[i]); } Serial.println("Outside Temps"); for(int i = 0; i < tempCounter; i++) { Serial.println(outsideTempsArray[i]); } } void printEEPROM() { digitalWrite(eepromActivityLight, HIGH); char exit; unsigned char tempCount= EEPROM.read(0); Serial.println("Printing EEPROM"); Serial.println("..............."); Serial.println("..............."); Serial.println("..............."); for(int i = 1; i < (tempCount * 2) - 1; i+=2) { unsigned char temp = (unsigned char)EEPROM.read(i) - 50; Serial.print("Inside "); Serial.println(temp); } for(int i = 2; i < (tempCount * 2) - 1; i+=2) { unsigned char temp = (unsigned char)EEPROM.read(i) - 50; Serial.print("Outside "); Serial.println(temp); } digitalWrite(eepromActivityLight, LOW); } void erase() { digitalWrite(eepromActivityLight, HIGH); Serial.println("Clearing EEPROM"); unsigned char zero = 0; for (int i = 0 ; i < EEPROM.length() ; i++) { EEPROM.write(i, zero); } unsigned char val = (unsigned char)EEPROM.read(0); while(digitalRead(eepromSwitch) == HIGH){} // wait fot eeprom switch to be in off position // make sure the address for tempCounter is cleared if(val == 0) { Serial.println("EEPROM is clear"); digitalWrite(eepromActivityLight, LOW); } }