So I have a boat robot it has a ph level sensor, the value of ph sensor being sent to hc-12 is accurate when being powered through USB to pc/laptop, but when powered by battery with buck converter the data being sent is out of range to the water buffer the ph sensor being submerged.
This is how I get and send the ph value to another microcontroller:
float readPH() {
int measuring = 0;
for (int i = 0; i < samples; i++) {
measuring += analogRead(PHpin);
delay(10);
}
float voltage = 5.0 / adc_resolution * (measuring / samples);
return phLevel = ph(voltage);
}
void transmitPHLevel() {
unsigned long currentTime = millis();
if (currentTime - lastPHTransmitTime >= phTransmitInterval) {
lastPHTransmitTime = currentTime;
phLevel = readPH(); // Implement this to get the actual pH sensor reading
hc12.print("PH");
hc12.println(phLevel);
}
}
I tested the voltage coming through the ph-4502c it is 5v when powered through battery, and when powered through pc/laptop 4.89 ranging up and down
Neither can the forum. Not enough information from you.
My best guess is that you already know the answer. The voltage supplied to the sensor is different when circuit is powered from laptop versus battery, leading to different readings. Adjust them to be the same if you can, or use the Arduino's internal voltage reference.
Any pH sensor will need to be calibrated regularly. Not only the supply voltage but temperature and age will have dramatic effects on the readings. You need to work out a calibration routine to correct the values and then accept that you will have to repeat that process whenever you change anything.
Typically calibration is done using buffered standards at pH 4, 7, and 10 to create a 3 point calibration curve.