/********************************************************* * Callisto power switch spawnded from CSV_Logger_TinyGPSPlus.ino * plan is to use gps data to turn on the DC power feed to the receivers from ~ 20:00 ut to about 09:50UT * uses software serial on pins 3 and 4 for GPS * uses 'digital' time and is configured for South Aust to turn the power off at night * uses D6 as trigger for switch (an output pin) * Arduino Uno / nano board and GPS shield * Blair 23/03/2021 * *********************************************/ #include // #include #include //const int chipSelect = 10; // was 4 think this was for the SD card const int powerSw = 6; // using pin 6 for trigger of switch high = on // data to be logged: // #define LOG_COLUMN_COUNT 9 // char * log_col_names[LOG_COLUMN_COUNT] = // { // "latitude","longitude", "nT","altitude", "speed", "course", "date", "time", "satellites" // }; // log column names printed out on top of file //Log Rate Control// #define LOG_RATE 5000 // log rate in milliseconds, was 5000 (5 seconds) unsigned long lastLog = 0 ; // global variable //TinyGPS Definitions// TinyGPSPlus tinyGPS; // TinyGPS object to be used throughout #define GPS_BAUD 9600 // GPS modules default baud rate // GPS Serial Port Definitions// //If we are using the Uno, that uses 0/1 UART for programming / serial monitoring, then use the softwareSerial #include #define ARDUINO_GPS_RX 4 //GPS TX , Arduino Rx pin #define ARDUINO_GPS_TX 3 // GPS Rx, Arduino Tx Pin SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX);// create a Software Serial object #define gpsPort ssGPS // #define SerialMonitor Serial boolean swOn = false; boolean pwrSwOn = false; double TimeOn; // time in UT that we want to turn the power ON double TimeOff; // time in UT that we want to turn the power OFF float decimalTime ; int myHours; int myMinutes; int mySeconds; void setup() { // put your setup code here, to run once: Serial.begin(115200); gpsPort.begin(GPS_BAUD); Serial.println ("GPS power switch"); pinMode(6, OUTPUT); // using D6 (powersw making it an output digitalWrite (powerSw, LOW); // start it low (off) TimeOn = 20.50; //decimal hours // time in UT that we want to turn the power ON TimeOff = 10.00; //// time in UT that we want to turn the power OFF } void loop() { // put your main code here, to run repeatedly: if ((lastLog + LOG_RATE) <= millis()) //if greater than the millis + log then do { myHours = tinyGPS.time.hour(); myMinutes = tinyGPS.time.minute(); mySeconds = tinyGPS.time.second(); decimalTime = (myHours * 1.0) + (myMinutes / 60.0 ) + (mySeconds/3600.0) ; Serial.print ("Time On = "); Serial.print (TimeOn); Serial.print (" UT, Current Time = "); Serial.print (decimalTime , 4); Serial.print (" UT, Time Off = "); Serial.print (TimeOff); Serial.print (" UT, Power is "); if (pwrSwOn == true) { Serial.println ("ON"); } if (pwrSwOn == false) { Serial.println ("OFF"); } if ((decimalTime>=TimeOn) || (decimalTime<=TimeOff)) // if >= 20UT or <=10UT turn it on { if (tinyGPS.location.isUpdated())// if the GPS data is valid { swOn = true; lastLog = millis(); // update the lastlog (time) variable } } if ((decimalTime> TimeOff) && (decimalTime < TimeOn ) ) // if > 10UT or < 20UT turn it off { if (tinyGPS.location.isUpdated())// if the GPS data is valid { swOn = false; lastLog = millis(); // update the lastlog (time) variable } } } while (gpsPort.available()) tinyGPS.encode(gpsPort.read()); // following sets the on / off latch as needed if ((pwrSwOn != swOn) && (swOn == true) ) // if not on and need to turn on then sw on. { digitalWrite (powerSw, HIGH); // turn it on pwrSwOn = swOn; Serial.println ("switch on"); } if ((pwrSwOn != swOn) && (swOn == false) ) // if not off and need to turn off then sw off. { digitalWrite (powerSw, LOW); // turn it off pwrSwOn = swOn; Serial.println ("switch off"); } }