# pH Sensor - how to code reading?

**URL:** <https://forum.arduino.cc/t/ph-sensor-how-to-code-reading/169967>\
**Category:** Sensors\
**Created:** [June 25, 2013, 1:25pm UTC](https://forum.arduino.cc/t/ph-sensor-how-to-code-reading/169967 "2013-06-25T13:25:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregmcc](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gregmcc/32/693677_2.png) [@gregmcc](https://forum.arduino.cc/u/gregmcc)\
**Post date:** [June 25, 2013, 1:25pm UTC](https://forum.arduino.cc/t/ph-sensor-how-to-code-reading/169967/1 "2013-06-25T13:25:16Z")

</div>

So I've build a pH amplifier circuit which gives a reading of 0V to 3.148V (0 - 14 pH) in 0.02pH per step.

How do I now interface this to the Arduino. I know I need to use the AnalogueRead function but how do I cater for the value being from 0 to 3.148V ( and not 0-5V)  
At 1.574V it should display a pH of 7.

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [June 25, 2013, 2:01pm UTC](https://forum.arduino.cc/t/ph-sensor-how-to-code-reading/169967/2 "2013-06-25T14:01:45Z")

</div>

To get better resolution you can connect the 3.3V pin to the Aref pin and in setup() write:

```cpp
analogReference(EXTERNAL);

```

Then the 0-1024 input range maps to 0-3.3V:

float voltage = (analogRead(pin) \* 3.3) / 1024.0;

---

<div class="post-metadata">

**Author:** ![gregmcc](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gregmcc/32/693677_2.png) [@gregmcc](https://forum.arduino.cc/u/gregmcc)\
**Post date:** [June 25, 2013, 2:43pm UTC](https://forum.arduino.cc/t/ph-sensor-how-to-code-reading/169967/3 "2013-06-25T14:43:15Z")

</div>

Thanks - I"ll try that. I found a few references and came up with this:

```cpp
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);

  Serial.print("pH:");
  
  float ph = voltage * (14.000 / 3.148);
  Serial.println(ph);
  
  delay(1000);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 10:01am UTC](https://forum.arduino.cc/t/ph-sensor-how-to-code-reading/169967/4 "2021-05-06T10:01:58Z")

</div>

Closed on May 6, 2021, 10:01am UTC


