I'm extremely new to coding, thus, the way that I have done everything is the only way that I could self learn how to do it. Prior to this project I had ZERO experience in both coding and Arduino. Hence why my code most likely makes experienced coders cringe.
As I mentioned, the code will run perfectly if I comment out from line 175 down, I get values that are non zero, obviously the conductivity of the water is none zero. As soon as I uncomment from line 175 down, the values for the conductivity function become zero.
The serial output looks exactly as it should, excepting that the value of the conductivity is zero when it most definitely should not be, and definitely is not when the full code is not run.
I simply cannot get the value of conductivity to be non-zero when the full code is run, but it is non-zero when running only the section of code to line 175.
This code works perfectly.
[code]
float conductValue;
float level;
#define thermistorPin A4
#define numSamples 5
#define seriesResistor 10000
#define temperatureNominal 25
#define thermistorNominal 10000
#define bCoefficient 3950
int samples[numSamples];
float tempReading;
int elecCondSensor = A2; //Electrical Conductivity Sensor in outflow
int sedFreeTankSensor = A0;
float conductivity (int elecCondSensor)
{
uint8_t m;
float average3;
for (m = 0; m < numSamples; m++)
{
samples[m] = analogRead(elecCondSensor);
delay(10);
}
average3 = 0;
for (m = 0; m < numSamples; m++)
{
average3 += samples[m];
Serial.println(average3);
}
average3 /= numSamples;
Serial.println(average3);
return average3;
}
float fillTank (int sedFreeTankSensor)
{
uint8_t j;
float average2;
for (j = 0; j < numSamples; j++)
{
samples[j] = analogRead(sedFreeTankSensor);
delay(10);
}
average2 = 0;
for (j = 0; j < numSamples; j++)
{
average2 += samples[j];
}
average2 /= numSamples;
return average2;
}
float readTemps(int thermistorpin, int seriesresistor, int temperaturenominal, int thermistornominal, int bcoefficient)
{
uint8_t i;
float average;
for (i = 0; i < numSamples; i++)
{
samples[i] = analogRead(thermistorpin);
delay(10);
}
average = 0;
for (i = 0; i < numSamples; i++)
{
average += samples[i];
}
average /= numSamples;
average = 1023 / average - 1;
average = seriesresistor / average;
float steinhart;
steinhart = average / thermistornominal;
steinhart = log(steinhart);
steinhart /= bcoefficient;
steinhart += 1.0 / (temperaturenominal + 273.15);
steinhart = 1.0 / steinhart;
steinhart -= 273.15;
return steinhart;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(relay1, OUTPUT); //Sets Relay1 as Output
pinMode(relay2, OUTPUT); //Sets Relay2 as Output
pinMode(relay3, OUTPUT); //Sets Relay3 as Output
pinMode(relay4, OUTPUT); //Sets Relay4 as Output
pinMode(relay5, OUTPUT); //Sets Relay5 as Output
pinMode(relay6, OUTPUT); //Sets Relay6 as Output
pinMode(relay7, OUTPUT); //Sets Relay7 as Output
pinMode(relay8, OUTPUT); //Sets Relay8 as Output
pinMode(PWMA, OUTPUT);
pinMode(Ain1, OUTPUT);
pinMode(elecCondSensor, INPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
level = fillTank(sedFreeTankSensor);
Serial.print("Water Level: ");
Serial.println(level);
delay(150);
conductValue = conductivity(elecCondSensor);
Serial.print("Arbitrary conductivity Value ");
Serial.println(conductValue);
delay(150);
tempReading = readTemps(thermistorPin, seriesResistor, temperatureNominal, thermistorNominal, bCoefficient);
Serial.print("The Water Temperature is (this is wrong): ");
Serial.println(tempReading);
delay(5000);
}
[/code]