Outils pour utilisateurs

Outils du site


wiki:projets:phmetre2:ie

Ceci est une ancienne révision du document !


Voici comment fabriquer un pH-metre. Vous y trouverez le montage ainsi que le programme.

1- L'écran LCD:

Montage:

2- Adaptateur sonde pH:

Montage:

3- Boutons Poussoirs:

Les boutons poussoirs nous serviront à activer étalonnage du pH4 et du pH7. Ils sont très simples à brancher, en effet on les branche au 5V et à un pin digital qu'on déclarera comme input. Il n'y a pas besoin de brancher au GND sauf si vos boutons poussoirs contiennent des LED, si oui il faut brancher deux pins au 5V, un au GND et l'autre à un pin digital en input. Quand le bouton est activé le pin input recevra un signal.

4- Programme Final:

#include <Wire.h>
#include "rgb_lcd.h"
#define SensorPin 0          //Arduino Analog Input 0
 
unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int buf[10],temp;
const int bouton7 = 7;       //pin digital 7 pour bouton pH7
const int bouton4 = 4;       //pin digital 4 pour bouton pH4
float cst1 = 0;
float cst2 = 0;
 
rgb_lcd lcd;
 
//creation d'images/animations pour le lcd
byte smiley[8] = {
    0b00000,
    0b00000,
    0b01010,
    0b00000,
    0b00000,
    0b10001,
    0b01110,
    0b00000
};
 
byte frownie[8] = {
    0b00000,
    0b00000,
    0b01010,
    0b00000,
    0b00000,
    0b00000,
    0b01110,
    0b10001
};
 
byte armsDown[8] = {
    0b00100,
    0b01010,
    0b00100,
    0b00100,
    0b01110,
    0b10101,
    0b00100,
    0b01010
};
 
byte armsUp[8] = {
    0b00100,
    0b01010,
    0b00100,
    0b10101,
    0b01110,
    0b00100,
    0b00100,
    0b01010
};
 
 
void setup()
{
  lcd.begin(16, 2);               //declarer taille de l'ecran LCD
  Serial.begin(9600);             //initialiser l'ecran LCD
  pinMode(13,OUTPUT);             //temoin lumineux sur arduino
  pinMode(bouton4, INPUT);        //declarer pin digital 4 comme input pour bouton poussoir pH4
  pinMode(bouton7, INPUT);        //declarer pin digital 7 comme input pour bouton poussoir pH7
 
 
  //Ecran d'acceuil coportant message acceuil et animations
  lcd.print("pHmetre  Arduino");
  delay(3000);
  lcd.clear();
  lcd.print("     Salut!");
 
  #if 1   
    // create a new character
    lcd.createChar(1, smiley);
    // create a new character
    lcd.createChar(2, frownie);
    // create a new character
    lcd.createChar(3, armsDown);
    // create a new character
    lcd.createChar(4, armsUp);
  #endif 
 
    // set the cursor
    lcd.setCursor(11, 1);
    // draw the smiley
    lcd.write(1);
 
    // set the cursor to the bottom row, 5th position:
    lcd.setCursor(4, 1);
    // draw the little man, arms down:
    lcd.write(3);
    delay(500);
    lcd.setCursor(4, 1);
    // draw him arms up:
    lcd.write(4);
    delay(500);
 
    lcd.setCursor(4, 1);
    lcd.write(3);
    delay(1000);
    lcd.setCursor(4, 1);
    lcd.write(4);
    delay(500);
 
    lcd.setCursor(4, 1);
    lcd.write(3);
    delay(500);
    lcd.setCursor(4, 1);
    lcd.write(4);
    delay(500);
 
    lcd.setCursor(4, 1);
    lcd.write(3);
    delay(500);
    lcd.setCursor(4, 1);
    lcd.write(4);
    delay(500);
 
    lcd.setCursor(4, 1);
    lcd.write(3);
    delay(500);
    lcd.setCursor(4, 1);
    lcd.write(4);
    delay(500);
}
 
 
void loop()
{
  //Calcul pH
  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  { 
    buf[i]=analogRead(SensorPin);
    delay(10);
  }
  for(int i=0;i<9;i++)        //sort the analog from small to large
  {
    for(int j=i+1;j<10;j++)
    {
      if(buf[i]>buf[j])
      {
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i<8;i++)                      //take the average value of 6 center sample
    avgValue+=buf[i];
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  phValue=3.5*phValue;                      //convert the millivolt into pH value
 
  //Etallonage
  if(digitalRead(bouton7) == HIGH)          //bouton etalonnage pH7 activé
    {
      cst1 = 7 - phValue;                   //calcule constante 1
      lcd.setRGB(255,255,255);
      lcd.clear();
      lcd.print("Etalonnage  pH 7");
      lcd.setCursor(0,1);
      lcd.print("  Patientez...");
      pinMode(bouton7, OUTPUT);
      delay(1000);
    }
 
    else if(digitalRead(bouton4) == HIGH)     //bouton etalonnage pH4 activé
    {
      cst2 = 4 - phValue;                     //calcule constante 2
      lcd.setRGB(255,255,255);
      lcd.clear();
      lcd.print("Etalonnage  pH 4");
      lcd.setCursor(0,1);
      lcd.print("  Patientez...");
      pinMode(bouton4, OUTPUT);
      delay(1000);
    }
 
    else
    {
      float phValue2 = phValue + ((cst1+cst2)/2);   //ajoute la moyenne des deux constantes à la valeur du pH calculé
 
      //Affichage avec couleur selon le pH
      if( (0<=phValue2) && (phValue2<2) )
      {
        lcd.setRGB(255,0,0);            //change couleur ecran
        lcd.clear();                    //reinitialise ecran
        lcd.print("pH:");  
        lcd.print(phValue,1);           //affiche pH
        digitalWrite(13, HIGH);         //allume temoin lumineux sur l'arduino (verifier que le programme marche)
        delay(1000);                    //attend 1000ms pour afficher une nouvelle valeur
        digitalWrite(13, LOW);          //eteind temoin lumineux sur l'arduino
      }
 
      else if( (2<=phValue2) && (phValue2<4) )
      {
        lcd.setRGB(255,255,0);
        lcd.clear();
        lcd.print("pH:");  
        lcd.print(phValue2,1);
        digitalWrite(13, HIGH);       
        delay(1000);
        digitalWrite(13, LOW);
      }
 
      else if( (4<=phValue2) && (phValue2<6) )
      {
        lcd.setRGB(107,142,35);
        lcd.clear();
        lcd.print("pH:");  
        lcd.print(phValue2,1);
        digitalWrite(13, HIGH);       
        delay(1000);
        digitalWrite(13, LOW);
      }
 
      else if( (6<=phValue2) && (phValue2<8) )
      {
        lcd.setRGB(0,255,0);
        lcd.clear();
        lcd.print("pH:");  
        lcd.print(phValue2,1);
        digitalWrite(13, HIGH);       
        delay(1000);
        digitalWrite(13, LOW);
      }
 
      else if( (8<=phValue2) && (phValue2<10) )
      {
        lcd.setRGB(47,79,79);
        lcd.clear();
        lcd.print("pH:");  
        lcd.print(phValue2,1);
        digitalWrite(13, HIGH);       
        delay(1000);
        digitalWrite(13, LOW);
      }
 
      else if( (10<=phValue2) && (phValue2<12) )
      { 
        lcd.setRGB(0,255,255);
        lcd.clear();         
        lcd.print("pH:");  
        lcd.print(phValue2,1);
        digitalWrite(13, HIGH);       
        delay(1000);
        digitalWrite(13, LOW);
      }
 
      else if( (12<=phValue2) && (phValue2<14) )
      {
        lcd.setRGB(0,0,255);
        lcd.clear();      
        lcd.print("pH:");  
        lcd.print(phValue2,1);
        digitalWrite(13, HIGH);       
        delay(1000);
        digitalWrite(13, LOW);
      }
 
      //Si pH impossible affiche erreur
      else
      {
        lcd.setRGB(255,255,255);
        lcd.clear();
        lcd.print("     ERREUR");
        lcd.setCursor(0,1);
        lcd.print("  pH non valide");
        delay(1000);
      }
   } 
}
wiki/projets/phmetre2/ie.1461792869.txt.gz · Dernière modification: 2016/09/11 11:02 (modification externe)