Project background:
I am performing a drop test (from about 12 feet high) of a water ski to measure the force of impact, principal strain, etc. at different locations using strain gauge rosettes laid across the ski (with the necessary amplifier) at areas determined from an FEA model. The data will be saved to a micro SD card in a .csv format that I will remove after the test to analyze the results. At the moment, I don't have the code finished for the actual data recording from the strain gauges (feel free to chime in on this as well, but not crucial), but I do need help with a method to start and stop data collection using an IR remote. I will have an Arduino Nano running off a 9V battery and all electronics will be enclosed in a waterproof case mounted to the ski before it is lifted to 12 feet high. My idea is to lift the ski (using a crank and pulley attached top our test stand) and when it is at the top, power on the Arduino so it starts to collect data, then after it hits the water, turn it off with the IR remote so it stops collecting unnecessary data. It could be several minutes after lifting until it drops, so I don't want data to collect for that long. An alternative I thought of is simply powering on the Arduino after it is lifted, then telling it to record data for only 10 seconds, as defined in "void loop()" using a while loop. If you have any suggestions as to how I can do this and improve my own code, please do!
TL;DR I'm a noob with Arduino programming; need to start/stop data collection from strain gauges/amplifier using IR remote and send to SD card
#include "HX711.h"
#include "IRremote.h"
#include <SPI.h>
#include <SD.h>
#define calibration_factor -7500.0 // This value is obtained using the SparkFun_HX711_Calibration sketch
//HX711.DOUT - pin #A1
//HX711.PD_SCK - pin #A0
HX711 scale; // default gain value = 128.0
File DropTest;
int pinCS = 10; // CS pin of micro SD card adapter to digital pin 10
int receiver = 9; // signal pin of IR receiver to digital pin 9
/*----- Declare objects -----*/
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup() {
Serial.begin(9600);
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn(); // Start the receiver
if (!SD.begin(10)) {
Serial.println("Initializing SD card");
return;
}
Serial.println("Initialization successful");
DropTest = SD.open("DropTest.csv", FILE_WRITE);
DropTest.close();
Serial.println("File created!");
Serial.println("Drop test data:");
scale.begin(A1, A0);
// scale.set_scale(calibration_factor); // Only needs to be used if measuring force
scale.tare(); // Assuming there is no weight on the scale at start up, reset the scale to 0
}
void loop() {
if (irrecv.decode(&results)) // determines if the IR signal is received {
translateIR();
irrecv.resume(); // receive the next value
} // end if
/* Record data for 10 seconds after turning the Arduino on */
while (millis() <= 10000) {
if (SD.exists("DropTest.csv")) {
Serial.println("File exists!");
DropTest = SD.open("DropTest.csv", FILE_WRITE);
if (DropTest) {
Serial.println("File can now be written to");
DropTest.println((scale.read()) + " units"); // change "units" to either mV or delete and add later in excel if measuring strain
DropTest.close();
} // end nested if
else {
Serial.println("File cannot be written to");
} // end nested else
} // end if
else {
Serial.println("File doesn't exist");
} // end else
} // end while
} // end main loop
/*----- Function -----*/
void translateIR() // takes action based on IR code received
// describing Remote IR codes
{
switch(results.value) {
case FD00FF: Serial.println("POWER");
break;
case FD40BF: Serial.println("FUNC/STOP");
break;
default:
Serial.println("Other button selected");
} // end Case
delay(500); // Do not get immediate repeat
}
Measurement.ino (2.45 KB)