However, this sketch is giving me odd results. For a solution that has a 8.95 ppt (measuring using a stand-alone salinity probe, which I know that works correctly), my sketch measures:
Analog in reading: 38 - Calculated ppt: 0.15
Analog in reading: 44 - Calculated ppt: 0.18
Analog in reading: 46 - Calculated ppt: 0.18
Analog in reading: 45 - Calculated ppt: 0.18
Analog in reading: 45 - Calculated ppt: 0.18
Any thoughts on what I am doing wrong? Not only are the results quite different from the the independent probe's value, but also they seem to be jumping around quite a bit (due to the changes in the input voltage to my Uno)…
int potPin = 0;
float ppt = 0;
float refvoltage = 1.1;
void setup()
{
Serial.begin(9600);
Serial.println("Sal sensor ");
analogReference(INTERNAL);
}
void loop()
{
int samples = 20;
int aRead = 0;
for (int i = 0; i < samples ; i++)
{
aRead += analogRead(potPin);
}
float voltage = 5.0 * aRead/ (1023 * samples); // assuming 5V reference
ppt = 16.3 * voltage;
// convert voltage to pH
Serial.print("Analog in reading: ");
Serial.print(aRead);
// print pH value on serial monitor
Serial.print(" - Calculated ppt: ");
Serial.println(ppt, 2); // 1 = one decimal, 2 = two decimals (default),etc // removed the /10
delay(500);
}
You have one of 2 things:
1- the wiring is wrong (and you are not reading the output of the sensor);
2- the solution don't have the tds/salinity that you think.
I don't see anything wrong in your sketch.
This lines:
// convert voltage to pH
Serial.print("Analog in reading: ");
Serial.print(aRead);
beside the comment that is wrong (maybe from an old project), don't give you a value that can be interpreted. You can do sometging like this:
int samples = 20;
int aRead = 0;
for (int i = 0; i < samples ; i++)
{
aRead += analogRead(potPin);
}
int aSamples = aRead/ samples;
float voltage = 5.0 * aSamples/ 1023; // assuming 5V reference
ppt = 16.3 * voltage;
// print the mean value read from de CAD
Serial.print("Analog in reading: ");
Serial.print(aSamples);
EDIT: Do you have the sensor correct supplied with 5V. What kind of shield you are using sparkfun or vernier? Take a look to the vernier shield:
The values that you show:
Analog in reading: 38 - Calculated ppt: 0.15
Analog in reading: 44 - Calculated ppt: 0.18
Analog in reading: 46 - Calculated ppt: 0.18
Analog in reading: 45 - Calculated ppt: 0.18
Analog in reading: 45 - Calculated ppt: 0.18
like I said before are meaningless. For example the 44 (from the second reading) is the accumulated value from the 20 samples. If you dived it by 20 it gives you 2,2. If you convert if to voltage (by multiplying by 5 and dividing by 1023) it gives you 0,011V. Converting to TDS (ppt), by multiplying by 16,3 it gives you 0,175ppt. So the math of your sketch is correct. The problem is in the sampling (I guess that is in the supply of the sensor).
The only thing that I remember is that you can try to use a different solution to check the values. I can use a glass with water and the add regular salt. A few stones. Measure the result, then add some more stones of salt, measure the result. You must see the result increasing. If you repeat this a few time you will see the readings going to some place near the 3V. If don't something is wrong or with your connections or with your sensor.
yeah... you are right. I see that the values do change as I change the salinity of the solution. I think that it is something related to the calibration value itself. I will have to experiment a bit with this to see if I can get it to work correctly. Thanks for the guidance & suggestions... it was very helpful!
However, this sketch is giving me odd results. For a solution that has a 8.95 ppt (measuring using a stand-alone salinity probe, which I know that works correctly), my sketch measures:
Analog in reading: 38 - Calculated ppt: 0.15
Analog in reading: 44 - Calculated ppt: 0.18
Analog in reading: 46 - Calculated ppt: 0.18
Analog in reading: 45 - Calculated ppt: 0.18
Analog in reading: 45 - Calculated ppt: 0.18
Any thoughts on what I am doing wrong? Not only are the results quite different from the the independent probe's value, but also they seem to be jumping around quite a bit (due to the changes in the input voltage to my Uno)…
for (int i = 0; i < samples ; i++)
{
aRead += analogRead(potPin);
}
float voltage = 5.0 * aRead/ (1023 * samples); // assuming 5V reference
ppt = 16.3 * voltage;
// convert voltage to pH
Serial.print("Analog in reading: ");
Serial.print(aRead);
// print pH value on serial monitor
Serial.print(" - Calculated ppt: ");
Serial.println(ppt, 2); // 1 = one decimal, 2 = two decimals (default),etc // removed the /10
delay(500);
}
This works well. Can you explain the variables yo used mr. Programmer?
However, this sketch is giving me odd results. For a solution that has a 8.95 ppt (measuring using a stand-alone salinity probe, which I know that works correctly), my sketch measures:
Analog in reading: 38 - Calculated ppt: 0.15
Analog in reading: 44 - Calculated ppt: 0.18
Analog in reading: 46 - Calculated ppt: 0.18
Analog in reading: 45 - Calculated ppt: 0.18
Analog in reading: 45 - Calculated ppt: 0.18
Any thoughts on what I am doing wrong? Not only are the results quite different from the the independent probe's value, but also they seem to be jumping around quite a bit (due to the changes in the input voltage to my Uno)…
for (int i = 0; i < samples ; i++)
{
aRead += analogRead(potPin);
}
float voltage = 5.0 * aRead/ (1023 * samples); // assuming 5V reference
ppt = 16.3 * voltage;
// convert voltage to pH
Serial.print("Analog in reading: ");
Serial.print(aRead);
// print pH value on serial monitor
Serial.print(" - Calculated ppt: ");
Serial.println(ppt, 2); // 1 = one decimal, 2 = two decimals (default),etc // removed the /10
delay(500);
}
This works well. Can you explain the variables yo used mr. Programmer?