nodemecu/arduino_master_1/arduino_master_1.ino

105 lines
2 KiB
Arduino
Raw Normal View History

2022-09-06 16:04:41 +00:00
#include <OneWire.h>
#include <DallasTemperature.h>
#define address 99 //default I2C ID number for EZO pH Circuit.
// SENSOR TEMPERATURA
// 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);
// Funcion que llama al sensor de temperatura
float getDataTemp() {
sensorDS18B20.requestTemperatures();
return (sensorDS18B20.getTempCByIndex(0));
}
// SENSOR TURBIDEZ
// Funcion que llama al sensor de turbidez
int getDataTur() {
int sensorValue = analogRead(A7);
return (map(sensorValue, 0, 700, 100, 0));
}
//
char devIDstr[5];
int inQuery;
void setup() {
Serial.begin(9600);
// Sensor temperatura
sensorDS18B20.begin();
}
void loop() {
if ( Serial.available() > 0) {
inQuery = Serial.read();
switch (inQuery) {
case 1:
2022-09-06 17:53:06 +00:00
Serial.write("1");
Serial.write(" ");
Serial.write("T");
Serial.write(" ");
Serial.write("00");
2022-09-06 18:01:02 +00:00
Serial.write(" ");
2022-09-06 17:53:06 +00:00
Serial.write("C");
Serial.write(" ");
Serial.write("99");
2022-09-06 16:50:50 +00:00
break;
case 2:
2022-09-06 17:53:06 +00:00
Serial.write("2");
Serial.write(" ");
Serial.write("Tur");
Serial.write(" ");
Serial.write("123");
2022-09-06 18:01:02 +00:00
Serial.write(" ");
2022-09-06 17:53:06 +00:00
Serial.write("TSS");
Serial.write(" ");
Serial.write("99");
2022-09-06 16:50:50 +00:00
break;
case 3:
Serial.write("3");
Serial.write(" ");
Serial.write("Con");
2022-09-06 16:04:41 +00:00
Serial.write(" ");
2022-09-06 17:30:57 +00:00
Serial.write("97");
2022-09-06 18:01:02 +00:00
Serial.write(" ");
2022-09-06 16:50:50 +00:00
Serial.write("Con");
2022-09-06 16:04:41 +00:00
Serial.write(" ");
2022-09-06 16:50:50 +00:00
Serial.write("99");
break;
case 4:
Serial.write("4");
2022-09-06 16:04:41 +00:00
Serial.write(" ");
2022-09-06 16:50:50 +00:00
Serial.write("Ph");
Serial.write(" ");
2022-09-06 17:30:57 +00:00
Serial.write("98");
2022-09-06 18:01:02 +00:00
Serial.write(" ");
2022-09-06 16:50:50 +00:00
Serial.write("Ph");
2022-09-06 16:04:41 +00:00
Serial.write(" ");
Serial.write("99");
2022-09-06 16:50:50 +00:00
2022-09-06 16:04:41 +00:00
break;
2022-09-06 16:50:50 +00:00
default:
;
}
2022-09-06 16:04:41 +00:00
}
delay(100);
}