//BOT
#include "CTBot.h"
CTBot bot_didactico;
String TOKEN = "6223517849:AAGBw8W6wrJVhvkdHbxH_ddDPiIT9NPzl2M";
String SSID = "Wokwi-GUEST";
String PSWD = "";
//esp32 sensor de temp y humedad
#include "DHTesp.h"
const int DHT_PIN =15 ;
DHTesp dhtSensor;
// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
#define LDR_PIN 13
//TERMISTOR
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
//CODIGO FOTOCELDA OBTENIDO DE :https://wokwi.com/projects/305193627138654786
analogReadResolution(12);
pinMode(LDR_PIN, INPUT);
//TERMISTOR
Serial.begin(9600);
analogReadResolution(10);
pinMode(4,INPUT);
//BOT
bot_didactico.wifiConnect(SSID, PSWD);
bot_didactico.setTelegramToken(TOKEN);
if(bot_didactico.testConnection()){
Serial.println("Conectado a telegram!");
}else{
Serial.println("No hay conexion a Telegram !");
}
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temperatura ambiente: " + String(data.temperature, 2) + "°C");
Serial.println("Humedad ambiente: " + String(data.humidity, 1) + "%");
Serial.println("---");
delay(1000);
//Foto celda
int analogValue = analogRead(13);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("Hoy ");
if (lux > 120000) {
Serial.print("hay demasiada luz!");
} else {
if (lux > 100000) {
Serial.print( "hay mucha luz!");
}else {
if (lux > 20000 && lux < 100000) {
Serial.print("es un hermoso dia!");
}else {
if (lux > 10000 && lux < 25000) {
Serial.print("parece medio dia!");
} else {
if (lux > 300) {
Serial.print("no hay mucho sol pero tampoco esta oscuro!");
}else {
if (lux < 100) {
Serial.print("esta nublado el dia!");
}else{
Serial.print("va a llover :(");
}
}
}
}
}
}
Serial.print(" ");
Serial.print("Lux: ");
Serial.print(lux);
Serial.print(" ");
Serial.print(" ");
delay(300);
//TERMISTOR
int analogValues = analogRead(4);
float celsius = 1 / (log(1 / (1023. / analogValues - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
//BOT
TBMessage mensaje;
if(bot_didactico.getNewMessage(mensaje)){
Serial.println("Mensaje Nuevo!");
Serial.println("enviado por: ");
Serial.println(mensaje.sender.id);
Serial.println("Mensaje leido: ");
Serial.println(mensaje.text);
}
}