Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
float m = 0;
float tempF=0;
int sensorValue = 0; // value read from the pot
long int sensorValue1 = 0;
long int sensorValue2 = 0;
int temperatura1 = 67;
int temperatura2 = 21;
String inString = "";
int outputValue = 0; // value output to the PWM (analog out)
int SerialComando = 0;
void setup() {
Serial.begin(9600);
calibracion();
}
void loop() {
sensorValue = analogRead(analogInPin);
Serial.print("Sensor PT100 = ");
Serial.print(sensorValue);
Serial.print("\t Temperatura = ");
tempF=(float)(m*(sensorValue-sensorValue2)+temperatura2);
Serial.print(tempF);
Serial.println("°C"); delay(100);
}
void calibracion() {
Serial.println("Quieres iniciar con el proceso de calibracion? S/N");
while (Serial.available() == 0) {}
SerialComando = Serial.read();
if (SerialComando == 'S') {
calibracionProceso();
}
else if (SerialComando == 'N') {
Serial.println("No se requiere calibracion, se muestran datos del sensor");
delay(1000);
}
else {
Serial.println("Comando erroneo, reinicie el programa!");
while (1);
}
}
void calibracionProceso() {
Serial.println("Temperatura 1: Dejar sensor listo");
Serial.println("Escribe un caracter y da ENTER para comenzar:");
while (Serial.available() == 0) {}
Serial.println("Espere.... tomando datos");
for (int i = 0; i < 100; i++) {
sensorValue1 += analogRead(analogInPin);
delay(1);
}
sensorValue1 = sensorValue1 / 100;
Serial.print("Dato del sensor :");
Serial.print(sensorValue1);
Serial.print(" Corresponde a :");
Serial.println(temperatura1);
while (Serial.available()) {
Serial.read();
}
Serial.println("Temperatura 2: Dejar sensor listo");
Serial.println("Escribe un caracter y da ENTER para comenzar:");
while (Serial.available() == 0) {}
Serial.println("Espere.... tomando datos");
for (int i = 0; i < 100; i++) {
sensorValue2 += analogRead(analogInPin);
delay(1);
}
sensorValue2 = sensorValue2 / 100;
Serial.print("Dato del sensor:");
Serial.print(sensorValue2);
Serial.print(" Corresponde a :");
Serial.println(temperatura2);
Serial.print("La pendiente del sistema es m=(y2-y1)/(x2-x1)=");
m = (float)((temperatura1 - temperatura2)/(sensorValue1 - sensorValue2));
Serial.println(m);
while (Serial.available()) {
Serial.read();
}
Serial.println("Escribe un caracter y da ENTER para comenzar la lectura de los datos:");
while (Serial.available() == 0) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment