Here is something you can try using a slight modification of your code.
void setup() {
analogReference(EXTERNAL); // use AREF for reference voltage
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.print("AnalogRead: ");
Serial.println(sensorValue);
float voltage = sensorValue * (3.3 / 1023.0);
Serial.print("V: ");
Serial.println(voltage);
Serial.println("\n");
delay(5000);
}
I am guessing Arduino Uno or similar. Since your Analog Input will likely only see a max of 3.3 volts as was mentioned in your setup code we added this line:
analogReference(EXTERNAL); // use AREF for reference voltage
Now connect the 3.3 volt out on your board to the AREF pin. This way your new analog reference becomes 3.3 volts so we also change:
float voltage = sensorValue * (3.3 / 1023.0);
Eventually you may want to think about averaging maybe ten samples and using a map function to get the readout in PH. That assumes a linear input as I have no experience with your sensor.
Whatever you end up getting , its worth having some means of calibrating within your software to get things spot.
I always try to stick with integer maths if you are dealing with an analog input , it’s easier to think you are getting more resolution/accuracy than you think by converting to a float .
zoomkat:
People have reported in the past that reading the analog input has a more stable reading on a second read like below.
That is only if you are using more than one analog input, and the ADC has to switch inputs. High impedance outputs (such as from a voltage divider) may cause the ADC take too long to settle, hence the second reading.
Your code example will give a "redefined" error from the compiler...
herbschwarz:
Yes, aarg. But the float variable uses very much more
memory than an int would use.
The program has to print the value as a decimal scaled to 5.0V. So, you have to create a float somewhere anyway. Unless you want to write custom output routines. Also I would not call 2 bytes "very much more".