Home › Forums › Other Data Loggers › Arduino datalogger › Reply To: Arduino datalogger
Here’s some sample code for running 6 Decagon 5TM probes with a standard Uno board. It could be modified by changing the pin number for the LED, in the example below I used the default pin 13 for the onboard LED. Mayfly users would want to select either 8 or 9. I usually prefer to do long-time recording with a separate real-time-clock module like what’s on the Mayfly, but in this example I just polled the rolling “millis” counter to get the time since the board was started. I set the example interval to 60 seconds, but you could adjust that if you wanted.
Remember that first you have to connect each 5TM sensor to the Arduino board one at a time and configure each one with a unique channel number. To work with the code below, you should number them sequentially from 1 to 6. Use the “address change” example that’s included with the SDI12 library, making sure to hook the sensor data pin to the correct pin that’s stated in the example, or change the example to match your wiring. In my example code below, I put the sensor data pin on D7.
I think this code should work, it compiles properly, I just don’t have 6 sensors handy to test it completely. It’s based on some thoroughly-tested Mayfly code, but I just removed all of the code regarding the Mayfly’s RTC, memory card, and sleeping functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#include <SDI12.h> #define DATAPIN 7 // change to the proper pin for sdi-12 data pin, I prefer D7 SDI12 mySDI12(DATAPIN); unsigned long previousMillis = 0; const long interval = 60000; //set the interval (in milliseconds). ex: 60000 = 60 seconds void setup () { pinMode(13, OUTPUT); digitalWrite(13, LOW); //turn off the onboard LED to start with Serial.begin(57600); mySDI12.begin(); Serial.println("Sketch for sampling multiple SDI12 sensors"); delay(1000); } void loop () { unsigned long currentMillis = millis(); if(currentMillis - previousMillis >= interval || previousMillis == 0) { previousMillis = currentMillis; digitalWrite(13, HIGH); //turn on the onboard LED to show that samples are being taken Serial.print("Time: "); Serial.print(currentMillis/1000); //print out the current time, in seconds Serial.print(" ---- "); for (char j = '1'; j <= '6'; j++) { //go through channels 1 to 6 tmMeasurement(j); } Serial.println(); digitalWrite(13, LOW); //turn off the LED to show that samples are done } delay(1000); } void tmMeasurement(char c){ //5TM soil moisture sensor String command = ""; float Ea = 0.0; float temp = 0.0; float VWC = 0.0; command += c; command += "M!"; // SDI-12 measurement command format [address]['M'][!] mySDI12.sendCommand(command); delay(500); // wait a sec mySDI12.flush(); command = ""; command += c; command += "D0!"; // SDI-12 command to get data [address][D][dataOption][!] mySDI12.sendCommand(command); delay(500); if(mySDI12.available() > 0){ int channel = mySDI12.parseInt(); Ea = mySDI12.parseFloat(); temp = mySDI12.parseFloat(); VWC = (4.3e-6*(Ea*Ea*Ea)) - (5.5e-4*(Ea*Ea)) + (2.92e-2 * Ea) - 5.3e-2 ; //the TOPP equation used to calculate VWC Serial.print("Sensor:"); Serial.print(channel); Serial.print(": Ea="); Serial.print(Ea); Serial.print(", VWC="); Serial.print(VWC); Serial.print("%, Temp="); Serial.print(temp); Serial.print("degC .... "); } mySDI12.flush(); } |