เซ็นเซอร์วัดค่า pH ของน้ำรุ่น E-201-C เป็นอุปกรณ์ที่ใช้ตรวจวัดระดับความเป็นกรด-ด่างของน้ำ โดยหัววัด pH (pH Probe) จะสร้างแรงดันไฟฟ้าตามระดับ pH ของน้ำที่สัมผัส ซึ่งแรงดันนี้จะถูกขยายโดยวงจรขยายสัญญาณก่อนส่งออกเป็นสัญญาณอนาล็อกไปยัง Arduino เพื่อประมวลผล
1.ต่ออุปกรณ์
.png?alt=media&token=ded7ac36-5a73-44fe-8ec5-7fc9c0ac5783)
E-201-C > Arduino UNO
V+>5VG>GNDG>GNDPo>A5
2.ลงโปรแกรม
Copy โค้ดด้านล่าง
1const int analogPhPin = A5; //PH module pin P0 connected to analog pin A5
2long phTot, temTot;
3float phAvg, temAvg;
4int x;
5float C = 25.85; //Constant of straight line (Y = mx + C)
6float m = -6.80; // Slope of straight line (Y = mx + C)
7
8void setup() {
9
10 // sensors.begin(); //Start the DS18B20 Library
11 Serial.begin(9600);
12}
13void loop() {
14 phTot = 0;
15 temTot = 0;
16 phAvg = 0;
17 temAvg = 0;
18
19 //taking 10 sample and adding with 10 milli second delay
20 for (x = 0; x < 10 ; x++)
21 {
22 phTot += analogRead(analogPhPin);
23 temTot += analogRead(A4);
24 delay(10);
25 }
26 float temAvg = temTot / 10;
27 float phAvg = phTot / 10;
28 // float temVoltage = temAvg * (5000.0 / 1023.0); //convert sensor reading into milli volt
29 float phVoltage = phAvg * (5.0 / 1023.0); //convert sensor reading into milli volt
30
31
32 // float Etemp = temVoltage*0.1; //convert milli volt to temperature degree Celsius
33 float pHValue = phVoltage * m + C;
34
35 Serial.print("phVoltage = ");
36 Serial.print(phVoltage);
37 Serial.print(" ");
38 Serial.print("pH=");
39 Serial.println(pHValue);
40
41 delay(1000);
42}1const int analogPhPin = A5; //PH module pin P0 connected to analog pin A5
2long phTot, temTot;
3float phAvg, temAvg;
4int x;
5float C = 25.85; //Constant of straight line (Y = mx + C)
6float m = -6.80; // Slope of straight line (Y = mx + C)
7
8void setup() {
9
10 // sensors.begin(); //Start the DS18B20 Library
11 Serial.begin(9600);
12}
13void loop() {
14 phTot = 0;
15 temTot = 0;
16 phAvg = 0;
17 temAvg = 0;
18
19 //taking 10 sample and adding with 10 milli second delay
20 for (x = 0; x < 10 ; x++)
21 {
22 phTot += analogRead(analogPhPin);
23 temTot += analogRead(A4);
24 delay(10);
25 }
26 float temAvg = temTot / 10;
27 float phAvg = phTot / 10;
28 // float temVoltage = temAvg * (5000.0 / 1023.0); //convert sensor reading into milli volt
29 float phVoltage = phAvg * (5.0 / 1023.0); //convert sensor reading into milli volt
30
31
32 // float Etemp = temVoltage*0.1; //convert milli volt to temperature degree Celsius
33 float pHValue = phVoltage * m + C;
34
35 Serial.print("phVoltage = ");
36 Serial.print(phVoltage);
37 Serial.print(" ");
38 Serial.print("pH=");
39 Serial.println(pHValue);
40
41 delay(1000);
42}
3.การคาลิเบรท

ใช้ไขควงแบนหมุนที่โพเท็นที่ลูกศรสีแดงชี้ อาจจะต้องหมุนไปเยอะมากๆ
pH สูงกว่า หมุนตามเข็มนาฬิกา
pH ต่ำกว่า หมุนทวนเข็มนาฬิกา
*การคาลิเบรทควรใช้สารละลายที่ทราบค่า pH ที่แน่นอน
4.ผลลัพธ์
โค้ดนี้ทำหน้าที่อ่านค่า pH จากโมดูลวัดค่า pH ผ่านพิน A5 ของ Arduino โดยอ่านค่าอนาล็อก 10 ครั้งเพื่อหาค่าเฉลี่ย จากนั้นคำนวณแรงดันไฟฟ้าที่ได้และแปลงเป็นค่า pH ตามสมการเชิงเส้น
Y=mx+C ซึ่งมีค่าคงที่และความชันที่กำหนดไว้ล่วงหน้า ค่าที่ได้จะถูกพิมพ์ออกทาง Serial Monitor แต่ว่าค่าที่ได้ อาจจะต้องนำไปเทียบค่าอีกครั้ง

