float sensorvalue;
float volt;
float NTU;
void setup() {
Serial.begin(9600); // To use the Serial Monitor that reads NTU (Nephelometric Turbidity Units) of the water
}
void loop()
{
for (int i=0; i<200;i++)
{
sensorvalue = analogRead(A0);
volt = volt + sensorvalue * (5.0 / 1024.0); // La lectura analógica se cambia de 0 - 1023 a 0 - 5V; además, se se suman los datos
}
volt = volt/200; // Promedio de los valores de voltaje
if (volt >4.2){
NTU = 0;
Serial.print(NTU);
Serial.print(" NTU");
Serial.println("\n");
}
else if(volt < 2.5){ // El sensor solo trabaja con valores entre 2.5 y 4.2
NTU = 3000; // Lecturas menores a 2.5 serán iguales a 3000
Serial.print("\n");
Serial.print(NTU);
Serial.print(" NTU");
Serial.println("\n");
Serial.print("returbio");
Serial.println("\n");
}else{
NTU =-1120.4*square(volt)+5742.3*volt-4352.9;
}
Serial.print(volt);
Serial.print(" v");
Serial.print("\n");
Serial.print(NTU);
Serial.print(" NTU");
Serial.println("\n");
delay(2000);
}
int sensorPin = A0;
int valorsensor;
float voltaje, r1, r2;
void setup() {
Serial.begin(9600);
r2 = 68; // R2 = 10KΩ
}
void loop() {
valorsensor= analogRead(sensorPin); // Lee el valor del pin analogico A0
voltaje = 5.0*valorsensor/1024;// Calcula el voltaje
r1 = ((r2*5)/voltaje)-r2;
/*
// Otra forma de calcular R1, sera ignorar el voltaje y tomar las divisiones directamente del valor medido
r1 = ((r2*1024)/valorsensor)-r2;
*/
Serial.print("Vout = ");
Serial.print(voltaje);
Serial.print("V | R1 = ");
Serial.print(r1);
Serial.println("Ω");
delay(1000);
}