# Programme / sonde de pH

**URL:** <https://forum.arduino.cc/t/programme-sonde-de-ph/516528>\
**Category:** Français\
**Created:** [March 26, 2018, 3:30pm UTC](https://forum.arduino.cc/t/programme-sonde-de-ph/516528 "2018-03-26T15:30:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DiamonnD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/diamonnd/32/1160129_2.png) [@DiamonnD](https://forum.arduino.cc/u/DiamonnD)\
**Post date:** [March 26, 2018, 3:30pm UTC](https://forum.arduino.cc/t/programme-sonde-de-ph/516528/1 "2018-03-26T15:30:15Z")

</div>

Bonjour,

Actuellement je travaille sur la mise en place d'une sonde de pH et j'ai besoin d'aide.

La sonde de pH c'est celle ci : [Sonde pH + interface SEN0161 - Gotronic](https://www.gotronic.fr/art-sonde-ph-interface-sen0161-21552.htm)

J'aurai besoin de vous pour m'expliquer en détail toutes les lignes de codes si possible et s'il y a la possibilité de le réduire.  
Merci d'avance :)

/\*

# This sample code is used to test the pH meter V1.0.

# Editor : YouYou

# Ver : 1.0

# Product: analog pH meter

# SKU : SEN0161

_/  
 #define SensorPin A0 //pH meter Analog output to Arduino Analog Input 0  
 #define Offset 0.00 //deviation compensate  
 #define LED 13  
 #define samplingInterval 20  
 #define printInterval 800  
 #define ArrayLenth 40 //times of collection  
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback  
int pHArrayIndex=0;  
void setup(void)  
{  
pinMode(LED,OUTPUT);  
Serial.begin(9600);  
Serial.println("pH meter experiment!"); //Test the serial monitor  
}  
void loop(void)  
{  
static unsigned long samplingTime = millis();  
static unsigned long printTime = millis();  
static float pHValue,voltage;  
if(millis()-samplingTime \> samplingInterval)  
{  
pHArray[pHArrayIndex++]=analogRead(SensorPin);  
if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;  
voltage = avergearray(pHArray, ArrayLenth)5.0/1024;  
pHValue = 3.5voltage+Offset;  
samplingTime=millis();  
}  
if(millis() - printTime \> printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator  
{  
Serial.print("Voltage:");  
Serial.print(voltage,2);  
Serial.print(" pH value: ");  
Serial.println(pHValue,2);  
digitalWrite(LED,digitalRead(LED)^1);  
printTime=millis();  
}  
}  
double avergearray(int_ arr, int number){  
int i;  
int max,min;  
double avg;  
long amount=0;  
if(number\<=0){  
Serial.println("Error number for the array to avraging!/n");  
return 0;  
}  
if(number\<5){ //less than 5, calculated directly statistics  
for(i=0;i\<number;i++){  
amount+=arr\*;\*

- }\*
- avg = amount/number;\*
- return avg;\*
- }else{\*
- if(arr[0]\<arr[1]){\*
- min = arr[0];max=arr[1];\*
- }\*
- else{\*
- min=arr[1];max=arr[0];\*
- }\*
- for(i=2;i\<number;i++){\*  
\_ if(arr\*\<min){_\_  
\__ amount+=min; //arr\<min\*\_  
_\_ min=arr\*;  
  }else {  
  if(arr\>max){  
  amount+=max; //arr\>max\*  
  max=arr\*;  
  }else{  
  amount+=arr; //min\<=arr\<=max\*  
 \* }  
  }//if\*  
 \* }//for\*  
 \* avg = (double)amount/(number-2);  
  }//if\*  
 \* return avg;  
 }\*\__

---

<div class="post-metadata">

**Author:** ![lesept](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lesept/32/238959_2.png) [@lesept](https://forum.arduino.cc/u/lesept)\
**Post date:** [March 26, 2018, 3:44pm UTC](https://forum.arduino.cc/t/programme-sonde-de-ph/516528/2 "2018-03-26T15:44:53Z")

</div>

Commence par lire les [messages de bienvenue du forum](https://forum.arduino.cc/index.php?topic=324322.0). C'est à toi de faire l'effort de comprendre le code, on ne va pas passer des heures à faire ton boulot à ta place.  
Si tu as des questions de détail, le forum est là pour t'aider.

---

<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, 3:08pm UTC](https://forum.arduino.cc/t/programme-sonde-de-ph/516528/3 "2021-05-06T15:08:45Z")

</div>

Closed on May 6, 2021, 3:08pm UTC


