Herramientas de usuario

Herramientas del sitio


sensores:phmether

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

sensores:phmether [2015/09/27 02:38] – creado noblesensores:phmether [2019/06/14 23:00] (actual) manuel.floresv
Línea 1: Línea 1:
-Medidor de PH.+====== Medidor de PH ====== 
 El pH es una medida de acidez o alcalinidad de una disolución. El pH indica la concentración de iones hidronio [H3O+] presentes en determinadas sustancias. Este kit permite medir de forma sencilla el pH de un líquido gracias a su placa controladora que ofrece un valor analógico proporcional a la medición. El controlador tiene un potenciometro multivuelta que permite la correcta calibración de la sonda. El pH es una medida de acidez o alcalinidad de una disolución. El pH indica la concentración de iones hidronio [H3O+] presentes en determinadas sustancias. Este kit permite medir de forma sencilla el pH de un líquido gracias a su placa controladora que ofrece un valor analógico proporcional a la medición. El controlador tiene un potenciometro multivuelta que permite la correcta calibración de la sonda.
  
Línea 24: Línea 25:
 {{:sensores:4.png?200|}} {{:sensores:4.png?200|}}
  
 +<code c>
 /* /*
- 
  # This sample code is used to test the pH meter V1.0.  # This sample code is used to test the pH meter V1.0.
- 
  # Editor : YouYou  # Editor : YouYou
- 
  # Ver    : 1.0  # Ver    : 1.0
- 
  # Product: analog pH meter  # Product: analog pH meter
- 
  # SKU    : SEN0161  # SKU    : SEN0161
- 
 */ */
- 
 #define SensorPin A0            //pH meter Analog output to Arduino Analog Input 0 #define SensorPin A0            //pH meter Analog output to Arduino Analog Input 0
- 
 #define Offset 0.00            //deviation compensate #define Offset 0.00            //deviation compensate
- 
 #define LED 13 #define LED 13
- 
 #define samplingInterval 20 #define samplingInterval 20
- 
 #define printInterval 800 #define printInterval 800
- 
 #define ArrayLenth  40    //times of collection #define ArrayLenth  40    //times of collection
  
 int pHArray[ArrayLenth];   //Store the average value of the sensor feedback int pHArray[ArrayLenth];   //Store the average value of the sensor feedback
- 
 int pHArrayIndex=0;     int pHArrayIndex=0;    
- 
 void setup(void) void setup(void)
- 
 { {
- 
   pinMode(LED,OUTPUT);     pinMode(LED,OUTPUT);  
- 
   Serial.begin(9600);     Serial.begin(9600);  
- 
   Serial.println("pH meter experiment!");    //Test the serial monitor   Serial.println("pH meter experiment!");    //Test the serial monitor
- 
 } }
  
 void loop(void) void loop(void)
- 
 { {
- 
   static unsigned long samplingTime = millis();   static unsigned long samplingTime = millis();
- 
   static unsigned long printTime = millis();   static unsigned long printTime = millis();
- 
   static float pHValue,voltage;   static float pHValue,voltage;
- 
   if(millis()-samplingTime > samplingInterval)   if(millis()-samplingTime > samplingInterval)
- 
   {   {
- 
       pHArray[pHArrayIndex++]=analogRead(SensorPin);       pHArray[pHArrayIndex++]=analogRead(SensorPin);
- 
       if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;       if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
- 
       voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;       voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;
- 
       pHValue = 3.5*voltage+Offset;       pHValue = 3.5*voltage+Offset;
- 
       samplingTime=millis();       samplingTime=millis();
- 
   }   }
- 
   if(millis() - printTime > printInterval)   //Every 800 milliseconds, print a numerical, convert the state of the LED indicator   if(millis() - printTime > printInterval)   //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
- 
   {   {
- 
  Serial.print("Voltage:");  Serial.print("Voltage:");
- 
         Serial.print(voltage,2);         Serial.print(voltage,2);
- 
         Serial.print("    pH value: ");         Serial.print("    pH value: ");
- 
  Serial.println(pHValue,2);  Serial.println(pHValue,2);
- 
         digitalWrite(LED,digitalRead(LED)^1);         digitalWrite(LED,digitalRead(LED)^1);
- 
         printTime=millis();         printTime=millis();
- 
   }   }
- 
 } }
  
 double avergearray(int* arr, int number){ double avergearray(int* arr, int number){
- 
   int i;   int i;
- 
   int max,min;   int max,min;
- 
   double avg;   double avg;
- 
   long amount=0;   long amount=0;
  
   if(number<=0){   if(number<=0){
- 
     Serial.println("Error number for the array to avraging!/n");     Serial.println("Error number for the array to avraging!/n");
- 
     return 0;     return 0;
- 
   }   }
  
   if(number<5){   //less than 5, calculated directly statistics   if(number<5){   //less than 5, calculated directly statistics
- 
     for(i=0;i<number;i++){     for(i=0;i<number;i++){
- 
       amount+=arr[i];       amount+=arr[i];
- 
     }     }
- 
     avg = amount/number;     avg = amount/number;
- 
     return avg;     return avg;
- 
   }else{   }else{
  
     if(arr[0]<arr[1]){     if(arr[0]<arr[1]){
- 
       min = arr[0];max=arr[1];       min = arr[0];max=arr[1];
- +    }else{
-    } +
- +
-    else{ +
       min=arr[1];max=arr[0];       min=arr[1];max=arr[0];
- 
     }     }
  
     for(i=2;i<number;i++){     for(i=2;i<number;i++){
- 
       if(arr[i]<min){       if(arr[i]<min){
- 
         amount+=min;        //arr<min         amount+=min;        //arr<min
- 
         min=arr[i];         min=arr[i];
- 
       }else {       }else {
- 
         if(arr[i]>max){         if(arr[i]>max){
- 
           amount+=max;    //arr>max           amount+=max;    //arr>max
- 
           max=arr[i];           max=arr[i];
- 
         }else{         }else{
- 
           amount+=arr[i]; //min<=arr<=max           amount+=arr[i]; //min<=arr<=max
- 
         }         }
- 
       }//if       }//if
- 
     }//for     }//for
  
     avg = (double)amount/(number-2);     avg = (double)amount/(number-2);
- 
   }//if   }//if
  
   return avg;   return avg;
 +}
  
-}+</code>
sensores/phmether.1443321498.txt.gz · Última modificación: por noble