top of page

Three Button Species Dive Time Recorder

Inspired by Whale Watches & the tracking of dive times for individual humpback whales. This system can track up to three individuals. A good idea is to push one color-coded button every time an individual surfaces or takes a dive (in terms of whales).

Schematics

Materials Needed:

  1. 3 Buttons

  2. SD Card 

  3. SD Card Adapter 

  4. 14-20 Wires

  5. Battery Pack (OPTIONAL)

  6. Breadboard

  7. Arduino UNO

In progress: adding a timer so that the time of each button push is recorded.

CODE 
Copy & paste into Arduino IDE

// 3 Button Species Tracker
// Spliced together from SparkFun Inventors Kit Circuit 2B and Adafruit Breakout SD Documentation. Run through ChatGPT for clarity.

// SPECIAL INSTRUCTIONS FOR CODE
// There are two places in which the file name is indicated. In order to change the file name, both of those places must be edited. Replace only the word "start"
// Places where it says "Serial.println" or "myFile.println" dictate what is written. This can be edited to have species names or code rather than button color according to the needs of each project. 

// Sarah Cheney Whale are We Now 

#include <SPI.h>
#include <SD.h>

File myFile;

//Define Pins, looking at schematic diagram, this is where the button connects to the RedBoard 
#define firstKeyPin  4 //Pin 4 on RedBoard, etc. 
#define secondKeyPin 3
#define thirdKeyPin  2
   
void setup()

{
  Serial.begin(9600);
  while (!Serial);
  pinMode(firstKeyPin, INPUT_PULLUP); //Makes it so that data is recorded when the button is pulled up 
  pinMode(secondKeyPin, INPUT_PULLUP);
  pinMode(thirdKeyPin, INPUT_PULLUP);

//Set up SD Card 
  if (!SD.begin(10)) {
    Serial.println("initialization failed!"); //This is due to miswiring or faulty connections
    while (1);
  }
  Serial.println("initialization done.");
}


void loop() {
// This part may be redundant
int firstKeyState = digitalRead(firstKeyPin);
int secondKeyState = digitalRead(secondKeyPin);
int thirdKeyState = digitalRead(thirdKeyPin);

myFile = SD.open("start.txt", FILE_WRITE); //place to update file name 

// Read to SD Card 
if (myFile) {
// Read to serial monitor
if (digitalRead(firstKeyPin) == LOW) {    
   delay(200);
           Serial.println(" Blue Button is pressed");  
           myFile.println(F(" Blue Button is pressed"));        
  }
  else if (digitalRead(secondKeyPin) == LOW) {
    delay(200);
          Serial.println(" Red Button is pressed");
          myFile.println(F(" Red Button is pressed"));
  }
  else if (digitalRead(thirdKeyPin) == LOW) { 
    delay(200);
          Serial.println(" Yellow Button is pressed");
          myFile.println(F(" Yellow Button is pressed"));
  }
 

 myFile.close();
  }

  else {
    // if the file didn't open, print an error:
    Serial.println("error opening tekt.txt");

// re-open the file for reading:
  myFile = SD.open("start.txt"); //place to update file name 
  if (myFile) {
    Serial.println("file open");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening file");
  }
}
}

IMG_3783_edited.jpg

Sarah Cheney

University of Maine School of Marine Science

All photos (unless otherwise noted) are my own 

bottom of page