sensor temperatura

This commit is contained in:
Sergio Pernas 2022-04-05 17:08:52 -03:00
parent f45f27b254
commit fbd5edd62b
3 changed files with 83 additions and 47 deletions

View file

@ -1,71 +1,76 @@
int inData;
char sensorValue = "10"; #include <OneWire.h>
const byte devID = 0x01; #include <DallasTemperature.h>
// Pin donde se conecta el bus 1-Wire
const int pinDatosDQ = 2;
// Instancia a las clases OneWire y DallasTemperature
OneWire oneWireObjeto(pinDatosDQ);
DallasTemperature sensorDS18B20(&oneWireObjeto);
// Dispositivo
const int devID = 1;
char devIDstr[5];
int inQuery;
char *senData[] {
"T", // Tipo de sensor
"s", // Lectura del sensor
"C"
};
float getData() {
sensorDS18B20.requestTemperatures();
return (sensorDS18B20.getTempCByIndex(0));
}
void setup() { void setup() {
Serial.begin(14400); Serial.begin(9600);
sensorDS18B20.begin();
}
}
void loop() { void loop() {
if ( Serial.available() > 0) { if ( Serial.available() > 0) {
inData = Serial.read(); inQuery = Serial.read();
switch (inData) { if ( inQuery = devID) {
case devID:
Serial.write(devID);
for (int i = 0; i <= 3; i++) {
Serial.write(senData[i]);
}
Serial.write("99");
break;
}
}
}
/*if ( Serial.available() > 0) {
inData = Serial.read();
switch (inData) {
case devID:
Serial.write("0x01");
Serial.write(itoa(devID, devIDstr, 10));
Serial.write(" "); Serial.write(" ");
Serial.write("hum"); Serial.write("T");
//Serial.write(" ");
float lectura = getData();
char lecturaStr[8]; // Buffer big enough for 7-character float
dtostrf(lectura, 6, 2, lecturaStr); // Leave room for too large numbers!
Serial.write(lecturaStr);
Serial.write(" "); Serial.write(" ");
Serial.write("78"); Serial.write("C");
Serial.write(" ");
Serial.write("P");
Serial.write(" "); Serial.write(" ");
Serial.write("99"); Serial.write("99");
Serial.write(" ");
Serial.write("pre");
Serial.write(" ");
Serial.write("100");
Serial.write(" ");
Serial.write("Hpa");
Serial.write(" ");
Serial.write("98");
Serial.write(" ");
break;
}
} }
} */
delay(1500);
}

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,30 @@
int inData;
const char* valueSensor;
void setup() {
Serial.begin(9600);
}
void loop() {
if ( Serial.available() > 0) {
inData = Serial.read();
switch (inData) {
case 2:
Serial.print(2);
Serial.print(" ");
Serial.print("hum");
Serial.print(" ");
Serial.print("78");
Serial.print(" ");
Serial.print("P");
Serial.print(" ");
Serial.print("99");
Serial.print(" ");
break;
}
}
}