I am building my first arduino on a mega platform to perform water quality testing in an estuary during plankton pulling and sediment sampling. I have a TDS sensor, external waterproof thermometer, lcd screen, RTC, and SD card module.
I'm trying to build the code and each time I think I have fixed something, another error pops up. I'm 10 days into this and still going nowhere. I'm a newbie and know just enough code to get myself in trouble, but not enough to know what something is/should be doing/not doing.
Here is my firmware code - I am currently getting a compilation error for a conflicting declaration "GravityTDS &onewire. I have gotten other errors for the RTC addressing (it wanted 2 wire configuration from another library), and void loop and void setup errors. I just want this thing to be able to read the temperature of the water in Celcius, the total dissolved salts in ppm, via the real-time clock of when the unit started reading/gathering data, and write the info to the SD card and display data on the LCD screen. Seems simple, but this coding has me bungled. Can you help me figure out where I am going wrong in my coding and fix any other potential errors?
// Include Libraries
#include "Arduino.h"
#include "EEPROM.h"
#include "DS18B20.h"
#include "GravityTDS.h"
#include "LiquidCrystal.h"
#include "Adafruit_NeoPixel.h"
#include "OneWire.h"
#include "DallasTemperature.h"
#include <SPI.h>
#include "SD.h"
#include "Button.h"
// Pin Definitions
#define DS18B20WP_PIN_DQ 2
#define ONE_WIRE_BUS 7
#define LCD_PIN_RS 8
#define LCD_PIN_E 7
#define LCD_PIN_DB4 3
#define LCD_PIN_DB5 4
#define LCD_PIN_DB6 5
#define LCD_PIN_DB7 6
#define LEDRGB_PIN_DIN 9
#define SDFILE_PIN_CS 53
#define TdsSensorPin 10
#define VREF 5.0 // analog reference voltage(Volt) of the ADC
#define SCOUNT 30 // sum of sample point
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int pinCS = 52; //Pin 52 on Arduino
OneWire oneWire(ONE_WIRE_BUS);
OneWire ds(7);
GravityTDS (&oneWire);
DallasTemperature sensors(&oneWire);
float tdsValue = 0;
float tempSensor1
const int sensor_pin = 2, 10
const int chipSelect = 50; //chipSelect pin for SD card Reader
File mySensorData; //Data object for writing sensor data to
void setup() {
Serial.begin(9600);
pinMode(pinCS, OUTPUT)
pinMode(sensor_pin,INPUT)
//SD Card Initialization
if (SD.begin())
{
Serial.printIn("SD card is ready to use.");
} else
{
Serial.printIn("SD card initialization failed.");
return;
}
//Create/Open file
mySensorData=SD.open("test.txt", FILE_WRITE)
//if the file opened okay, write to it:
if(mySensorData){
Serial.println("Writing to file...");
//Write to file
mySensorData.println("Testing text 1, 2, 3...");
mySensorData.close(); //close the file
Serial.println("Done.");
}
//if the file didn't open, print an error:
else {
Serial.println("Error opening test.txt");
}
//Reading the file
mySensorData=SD.open("test.txt");
if (mySensorData) {
Serial.println("Read:");
//Reading the whole file
while (mySensorData.available()){
Serial.write(mySensorData.read());
}
mySensorData.close();
}
else {
Serial.println("error opening test.txt");
}
void loop(){
//empty
}
void setup()
{
Serial.begin(115200);
lcd.begin(16,2);
sensors.begin();
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds.begin(); //initialization
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Time ");
DateTime now = RTC.now();
lcd.print(now.hour(), DEC);
lcd.print(": ");
lcd.setCursor(11,0);
lcd.print(now.second(), DEC);
float temp_c;
float TDS;
//Read values from the sensor
temp_c = shtlx.readTemperatureC();
TDS = shtlx.readTDS();
// Print the values to the serial port
lcd.setCursor(0,1);
lcd.print("Temp ");
lcd.setCursor(5,1);
lcd.print(temp_c, DEC);
lcd.setCursor(7,1);
lcd.print(" TDS ");
lcd.print(TDS);
lcd.print("%");
Serial.print("Temperature: ");
Serial.print(temp_c, DEC);
Serial.print("TDS: ");
Serial.print(TDS);
Serial.println("%");
}
}
void loop()
{
sensors.requestTemperatures();
gravityTds.setTemperature(sensors.getTempCByIndex(0)); // set the temperature and execute temperature compensation
gravityTds.update(); //sample and calculate
tdsValue = gravityTds.getTdsValue(); // then get the value
Serial.print(tdsValue,0);
Serial.println("ppm");
Serial.print("Temperature is: ");
Serial.print(sensors.getTempCByIndex(0));
lcd.setCursor(0, 0);
lcd.print("TDS: ");
lcd.print(tdsValue,0);
lcd.print(" PPM");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(sensors.getTempCByIndex(0));
lcd.print(" C");
delay(1500);
lcd.clear();
}
}