Home › Forums › Mayfly Data Logger › Continous HAB monitoring › Reply To: Continous HAB monitoring
2024-11-11 at 4:56 PM
#18737
The calibration sheet from Turner was very accurate for the new sensor, so if you don’t want to buy expensive rhodamine standard right now, you’re probably fine to use the data from the sheet. But we’ve found that the sensors tend to drift over time so we do quarterly recalibrations of the sensors to make sure they’re still accurate.
Here’s a simple sketch to take 100 analog readings quickly and average them, then constantly repeat that, and printing all data to the serial port. Then I just copy/paste the text from the serial port into Excel so I can do an analysis and overall average.
Arduino
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 |
//Takes lots of readings from the EnviroDIY Mayfly's ADS1115 Aux Analog ADC and averages them, prints to screen #include <SPI.h> #include <Wire.h> #include <Adafruit_ADS1015.h> Adafruit_ADS1115 ads; // The Mayfly's ADS1115 Aux ADC is 16-bit version float average_volts; //variable to hold the calculated average int State8 = LOW; int State9 = LOW; int aux_channel = 0; //channel number of whatever pin you've got your input connected to for the ADS1115 Aux Analog chip (AA0 = 0, AA1 = 1, AA2 = 2, AA3 = 3) int readcount = 100; //the number of readings you want to take for each sample int time_between_readings = 10; //number of milliseconds between each reading in a sample void setup() { Serial.begin(57600); //Start the serial connection with the computer ads.begin(); //begin adafruit ADS1015 pinMode(8, OUTPUT); // define the red and green LEDs as outputs pinMode(9, OUTPUT); digitalWrite(8, HIGH); //turn on one of the LEDs to start with digitalWrite(9, LOW); pinMode(22, OUTPUT); //switched power pin declared as output digitalWrite(22, HIGH); //turn on the Switched sensor voltage Serial.println("EnviroDIY Mayfly Aux-Analog Averaging Sketch "); Serial.print("Aux ADC Channel: "); Serial.print(aux_channel); Serial.print("(AA"); Serial.print(aux_channel); Serial.print(") Number of readings per sample: "); Serial.println(readcount); Serial.println("-------------------------------------------------------------"); delay(2000); //wait 2 seconds } void loop() { auxanalog_sample(); //go take a measurement with the ADS1115 //blink the red and green LEDs in alternating fashion on each loop if (State8 == LOW) { State8 = HIGH; } else { State8 = LOW; } digitalWrite(8, State8); State9 = !State8; digitalWrite(9, State9); // Serial.print("Averaged analog voltage (volts): "); //print the results to the serial monitor Serial.println(average_volts,5); delay(100); //wait a little bit between loops, adjust as you want } //end loop void auxanalog_sample() // function that takes reading from ADS1115 Aux Analog chip on Mayfly { int16_t adc_bits = 0; //int to hold the value of the bits that get read float bit_sum = 0.0; //sum of all the bits read for (int i = 0; i < readcount; i++){ adc_bits = ads.readADC_SingleEnded(aux_channel); //take a single-ended reading with the ADS1115 bit_sum += adc_bits; //add the latest reading to the sum delay(time_between_readings); //wait x milliseconds between readings, adjust as you want } float average_bits = bit_sum / readcount; //find the average by dividing the bit_sum by readcount //now convert bits into volts //average_volts = (average_bits * 3.3)/17585.0; // use this next line instead of the previous line if you're using a voltage divider to reduce an external sensor's voltage average_volts = ((average_bits * 3.3)/17585.0) * 2.0; //multiply by 2 if you used a 50/50 divider } |