#include <WiFi.h>
#include <Ubidots.h>
#include <DHT.h>
#define DHTPIN 5 // Pin de datos del sensor DHT11
#define DHTTYPE DHT11 // Tipo de sensor DHT
const char* ssid = "TuSSID";
const char* password = "TuContraseña";
const char* token = "TuTokenDeUbidots";
#define LED1_PIN 2 // Pin para el LED 1
#define LED2_PIN 4 // Pin para el LED 2
int contador_led1 = 0; // Contador para el LED 1
int contador_led2 = 0; // Contador para el LED 2
Ubidots ubidots(token);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(5000);
Serial.print(".");
}
Serial.println("Conectado a WiFi");
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
ubidots.add("led1", 0);
ubidots.add("led2", 0);
ubidots.add("contador_led1", 0);
ubidots.add("contador_led2", 0);
ubidots.add("temperatura", 0);
ubidots.add("humedad", 0);
}
void loop() {
if (ubidots.isDirty()) {
ubidots.sendAll();
}
// Lectura del sensor DHT11
float temperatura = dht.readTemperature();
float humedad = dht.readHumidity();
// Envío de datos a Ubidots
ubidots.add("temperatura", temperatura);
ubidots.add("humedad", humedad);
// Control de LEDs
if (digitalRead(LED1_PIN) == HIGH) {
contador_led1++;
ubidots.add("contador_led1", contador_led1);
ubidots.add("led1", 1);
} else {
ubidots.add("led1", 0);
}
if (digitalRead(LED2_PIN) == HIGH) {
contador_led2++;
ubidots.add("contador_led2", contador_led2);
ubidots.add("led2", 1);
} else {
ubidots.add("led2", 0);
}
delay(1000);
}