Voici comment fabriquer un pH-metre. Vous y trouverez le montage ainsi que le programme. ====1- L'écran LCD:===== Description: Notre écran LCD est en liaison I2C, ainsi nous avons que 4 pins à connecter, un deux pour l’alimentation et deux autres pour le signal. Il nous servira à afficher la valeur du pH et à changer de couleur selon cette valeur. Montage: {{ :wiki:projets:phmetre2:lcdf.png?300 |}} {{ :wiki:projets:phmetre2:20160331_214632.jpg?300 |}} ====2- Adaptateur sonde pH:===== Description: Notre sonde de pH nécessite un adaptateur qui a pour fonction d'amplifier le signal émis par la sonde afin que l'Arduino le comprenne. En effet la sonde envoie un signal sous forme d'un tension qui peut être négative ainsi que positive selon le pH de la solution (cf. datasheet de la sonde pH), l'amplificateur est un additioneur de tension qui fait en sorte que le signal soit toujours positif car l'Arduino ne lit pas les tensions négatives. Il se branche par connexion BNC avec la sonde. Montage: {{ :wiki:projets:phmetre2:adaptateur2.png?300 |}} ====3- Boutons Poussoir:==== Description: Les boutons poussoir nous serviront à activer étalonnage du pH4 et du pH7. Montage: 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 #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); } } } Code couleur: {{ :wiki:projets:phmetre2:capture2.png |}} ====5- Boitier:==== Nous avons choisi de faire notre boitier en bois car c'est un matériau résistant et nous avions la possibilité de le découper à la découpeuse laser. Nous avons fait des trous pour l’écran, les deux boutons, la prise de branchement et la connexion BNC. {{ :wiki:projets:phmetre2:12992019_1136061686446835_1084925535_o.jpg?300 |}} {{ :wiki:projets:phmetre2:20160412_212142.jpg?300 |}} {{ :wiki:projets:phmetre2:20160412_212334.jpg?300 |}} {{ :wiki:projets:phmetre2:20160412_212440.jpg?300 |}} Rendu final planifié: {{ :wiki:projets:phmetre2:12992019_1136061686446835_1084925535_.jpg?300 |}}