Projeto 23
Sensor de pH
Projeto 23 - Sensor de pH
Código (download)
// Projeto 23 - Sensor de pH (Pode ser usado para calibrar o sensor)
#define SensorPin A0
unsigned long int avgValue;
float b;
int buf[10];
int temp;
void setup()
{
Serial.begin(9600);
}
void loop()
{
for(int i=0;i<10;i++) // Guarda 10 valores para serem analisados
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) // Organiza os valores por ordem crescente
{
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++) // Faz a média dos 6 valores do meio (depois de organizados por ordem crescente)
{
avgValue+=buf[i];
}
float pHvalue=(float)avgValue*5.0/1024/6; // O valor é convertido em mV
pHvalue=3.5*pHvalue; // O valor é convertido em valor de pH
pHvalue=pHvalue+0.00; // Faz a calibração por código
Serial.print("pH = ");
Serial.println(pHvalue,2);
delay(800);
}
Projeto 23 - Sensor de pH com botão
Código (download)
// Projeto 23 - Sensor de pH (faz a medição do pH depois de se pressionar o botão)
#define SensorPin A0
#define btnPin 7
unsigned long int avgValue;
float b;
int buf[10];
int temp;
int estado;
void setup()
{
Serial.begin(9600);
pinMode(btnPin, INPUT);
}
void loop()
{
estado = 0;
while(estado == 0)
{
estado = digitalRead(btnPin);
}
for(int i=0;i<10;i++) // Guarda 10 valores para serem analisados
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) // Organiza os valores por ordem crescente
{
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++) // Faz a média dos 6 valores do meio (depois de organizados por ordem crescente)
{
avgValue+=buf[i];
}
float pHvalue=(float)avgValue*5.0/1024/6; // O valor é convertido em mV
pHvalue=3.5*pHvalue; // O valor é convertido em valor de pH
pHvalue=pHvalue+0.00; // Faz a calibração por código
Serial.print("pH = ");
Serial.println(pHvalue,2);
delay(1000);
}
Código (download)
// Projeto 23 - Sensor de pH (Curva de Titulação)
#define SensorPin A0
#define btnPin 7
unsigned long int avgValue;
float b;
int buf[10];
int temp;
int estado;
float DeltaVolume = 1.00; // Volume de titulante adicionado em cada medição
int k = 0;
float volume;
void setup()
{
Serial.begin(9600);
pinMode(btnPin, INPUT);
}
void loop()
{
estado = 0;
while(estado == 0)
{
estado = digitalRead(btnPin);
}
for(int i=0;i<10;i++) // Guarda 10 valores para serem analisados
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) // Organiza os valores por ordem crescente
{
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++) // Faz a média dos 6 valores do meio (depois de organizados por ordem crescente)
{
avgValue+=buf[i];
}
float pHvalue=(float)avgValue*5.0/1024/6; // O valor é convertido em mV
pHvalue=3.5*pHvalue; // O valor é convertido em valor de pH
pHvalue=pHvalue+0.00; // Faz a calibração por código
volume = k*DeltaVolume;
Serial.print(volume,2);
Serial.print("\t");
Serial.println(pHvalue,2);
delay(1000);
k++;
}
Projeto 23 - Sensor de pH com botão e ligação ao EXCEL
Código (download)
// Projeto 23 - Sensor de pH (Curva de titulação no EXCEL)
// Indica o valor do volume de titulante e o valor do pH depois de se pressionar o botão.
// Os valores são enviados para a folha de EXCEL projeto_23_sensor_de_pH_excel.xlsm
#define SensorPin A0
#define btnPin 7
unsigned long int avgValue;
float b;
int buf[10];
int temp;
int estado;
float DeltaVolume = 1.00; // Volume de titulante adicionado em cada medição
int k = 0;
float volume;
void setup()
{
Serial.begin(9600);
Serial.println("CLEARDATA");
Serial.println("LABEL, ,V/mL,pH");
pinMode(btnPin, INPUT);
}
void loop()
{
estado = 0;
while(estado == 0)
{
estado = digitalRead(btnPin);
}
for(int i=0;i<10;i++) // Guarda 10 valores para serem analisados
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) // Organiza os valores por ordem crescente
{
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++) // Faz a média dos 6 valores do meio (depois de organizados por ordem crescente)
{
avgValue+=buf[i];
}
float pHvalue=(float)avgValue*5.0/1024/6; // O valor é convertido em mV
pHvalue=3.5*pHvalue; // O valor é convertido em valor de pH
pHvalue=pHvalue+0.00; // Faz a calibração por código (adaptar para o nosso caso - neste momento está 0.00)
volume = k*DeltaVolume;
Serial.print("DATA, ,");Serial.print(volume,2);Serial.print(",");Serial.println(pHvalue,2);
delay(1000);
k++;
}