Turn on Light From Thindspeak With Esp32

by CarlosVoltT in Circuits > Electronics

95 Views, 0 Favorites, 0 Comments

Turn on Light From Thindspeak With Esp32

portada-1-820x461 (11).png

In this tutorial, we will show you how to control lights over the Internet using an ESP32 and the ThingSpeak platform.

In this tutorial, we will show you how to control lights over the Internet using an ESP32 and the ThingSpeak platform. Imagine being able to turn the lights in your home on or off from anywhere in the world with just a couple of clicks, or even automate the process based on real-time data. This is possible thanks to the combination of the ESP32, a powerful microcontroller with WiFi connectivity, and ThingSpeak, a cloud service that allows you to store and process data from sensors and other devices.

Throughout this tutorial, you will learn how to configure your ESP32 to connect to ThingSpeak, read data from a specific channel, and act on that data by turning lights on or off. This project is ideal for those who want to delve into the world of the Internet of Things (IoT) and explore how connected devices can interact with cloud services to create smart solutions.

Whether you're looking for a way to automate your home, create a remote lighting system, or just want to experiment with IoT, this tutorial will guide you step-by-step so you can do it easily and effectively.




An Esp32


Female pins

Dupont cables female male

PCB

Download gerber file –> Gerber_esp32




Relay Module




TECHNICAL SPECIFICATIONS

  1. Operating Voltage: 5V DC
  2. Control Signal: TTL (3.3V or 5V)
  3. Number of Relays (channels): 1 CH
  4. Max capacity: 10A/250VAC, 10A/30VDC
  5. Max current: 10A (NO), 5A (NC)
  6. Action time: 10 ms / 5 ms
  7. To activate output NO: 0 Volts


#include <WiFi.h>
#include <ThingSpeak.h>
// Configuración de red WiFi
const char* ssid = "Tu_red_wifi"; // Nombre de la red WiFi
const char* contrasena = "Tu_clave_wifi"; // Contraseña de la red WiFi
// Configuración de ThingSpeak
unsigned long idCanal = 0000000; // Reemplaza con tu ID de canal
const char* claveAPIlectura = "Read_API_Keys"; // Reemplaza con tu clave de lectura
WiFiClient cliente;
int pinLuz = 12; // Pin donde está conectada la luz o el relé
void setup() {
Serial.begin(115200);
// Configurar el pin como salida
pinMode(pinLuz, OUTPUT);
// Conectar a la red WiFi
WiFi.begin(ssid, contrasena);
Serial.print("Conectando a WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Conectado a WiFi");
// Conectar a ThingSpeak
ThingSpeak.begin(cliente);
}
void loop() {
// Leer el valor del canal
int estadoLuz = ThingSpeak.readIntField(idCanal, 1, claveAPIlectura); // Leer el campo 1
if (estadoLuz == 1) {
digitalWrite(pinLuz, HIGH); // Encender la luz
Serial.println("Luz encendida");
} else if (estadoLuz == 0) {
digitalWrite(pinLuz, LOW); // Apagar la luz
Serial.println("Luz apagada");
} else {
Serial.println("Error al leer el estado de la luz");
}
delay(15000); // Esperar 15 segundos antes de la próxima lectura
}