Introduction: Encender Una Bombilla Por Medio De WI-FI Con Un ESP8266( ARDUINO)
Este proyecto trata de encender una luz de la casa a distancia por medio de WI-FI con los componentes electronicos: arduino y el (ESP8266) ,.
El arduino lo utilizaremos sin el micro controlador ya que podría producir interferencia.
¿Que es un ESP8266?
El ESP8266 es un chip Wi-Fi. Este pequeño módulo permite a los microcontroladores conectarse a una red Wi-Fi y realizar conexiones sencillas utilizando comandos de tipo Hayes (Comandos estandar).
Se presenta un diagrama de los pines del modulo.
Step 1: A Continuación Haremos La Conección Del Circuito Electrico, El Arduino Y Los Demas Componentes.
Lista de componentes:
- 2 Resistencias 1K, 2K.
- Protoboard.
- Modulo de Relay de 5V.
- Jummpers.
- Un plafón con bombilla.
- Cable calibre 14 o 18.
- El modulo ESP8266.
- El arduino.
Step 2: EL Circuito
En la imagen del circuito podemos apreciar como se debe conectar cada componente, claro siempre esta a disposicion del usuario modificar el circuito.
Step 3: Instalamos El Driver Necesario Para Nuestro ESP8266 El Cual Podremos Instalar Siguiendo Los Siguentes Pasos
Nos vamos a nuestro programa arduino y procedemos a descargar la tarjeta adicional con el link http://arduino.esp8266.com/stable/package_esp8266c... de esta manera podremos instalar posterioirmente el Driver.
Ya estando en el gestor de tarjetas podremos descargar el modulo de ESP 8266 de la versión mas actualizada, luego lo seleccionaremos.
Step 4: Código
Este código es adaptable para realizar el proyecto.
- Se debe tomar en cuenta que se debe configurar la red WI-FI en la pc y también en la programación.
- A continuación se brinda el código a utilizar:
- Lo escribire para que lo puedan copiar y les dejare la imagen del codigo para que vean como de ir correctamente.
#include <p>const char* ssid = "RED-WIFI";//type your ssid const char* password = "CONTRASEÑA";//type your password</p><p>int PinRele = 2; // GPIO2 of ESP8266 WiFiServer server(80);//No cambiar esta parte del codigo</p><p>void setup() { Serial.begin(115200); delay(10);</p><p>pinMode(PinRele, OUTPUT); digitalWrite(PinRele, LOW);</p><p>// Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid);</p><p>WiFi.begin(ssid, password);</p><p>while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected");</p><p>// Start the server server.begin(); Serial.println("Server started");</p><p>// Print the IP address Serial.print("Use this URL to connect: "); Serial.print("http://"); Serial.print(WiFi.localIP()); Serial.println("/"); }</p><p>void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; }</p><p>// Wait until the client sends some data Serial.println("new client"); while(!client.available()){ delay(1); }</p><p>// Read the first line of the request String request = client.readStringUntil('\r'); Serial.println(request); client.flush();</p><p>// Match the request</p><p>int value = LOW; if (request.indexOf("/LIGHT=ON") != -1) { digitalWrite(PinRele, HIGH); value = HIGH; } if (request.indexOf("/LIGHT=OFF") != -1){ digitalWrite(PinRele, LOW); value = LOW; }</p><p>//Set PinRele according to the request //digitalWrite(PinRele, value);</p><p>// Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // do not forget this one client.println(""); client.println(" ");</p><p>client.print("pin Rele is now: ");</p><p>if(value == HIGH) { client.print("On"); } else { client.print("Off"); } client.println("<br><br>"); client.println("Click <a href="\"/LIGHT=ON\"">here</a> turn the LED on pin 2 ON<br>"); client.println("Click <a href="\"/lIGHT=OFF\"">here turn the LED on pin 2 OFF<br>"); client.println("</a></p><p><a href="\"/lIGHT=OFF\"">");</a></p><p><a href="\"/lIGHT=OFF\"">delay(1); Serial.println("Client disconnected"); Serial.println(""); }</a></p>
Step 5: Paso Importante Antes De Subir El Código
Para este paso es muy importante recordar que si se desea subir la programación se debe conectar el negativo del ESP8266 a Negativo de la protoboard.
Step 6: Paso Importante Después De Subir El Código
Una vez subida la programación debemos desconectar el arduino y pasar el negativo del ESP8266 a al positivo de la protoboard y volver a conectar el arduino a la pc.
Step 7: Como Incluir La Red WI-FI Al ESP8266
Una vez ya con la programación subida y ejecutándose ,seleccionamos la opción "MONITOR SERIAL".
En este preciaremos una dirección http en la cual indica donde se va a abrir nuestro sitio web para ejecutar el mando del Relay y así encender y apagar la bombilla.
En este punto ya estaría concluido nuestro proyecto.
Y puede desconectar el arduino de la pc utilizando una batería para el mismo.
Step 8:
Muchas gracias por ver el tutorial esperamos que su proyecto también haya sido todo un éxito.
5 Comments
3 years ago
Una pregunta el mostaza y el azul de un lado, ¿donde están conectados??
Reply 3 years ago
El moztaza va a GPIO 2 y el azul a RX
4 years ago
una pregunta, ¿el dispositivo mediante el cual vamos a controlar las luces, sea un smartphone o una laptop, debe estar conectado a la misma red wifi que está conectado el módulo ESP8266?
5 years ago
Welcome to the Instructables community. Thanks for sharing the great project.
Tip 5 years ago on Step 4
Acá esta el código para que lo copien y modifiquen a su conveniencia ya que instructable no me dejo subirlo de la menera correcta
_________________________________________________
#include
const char* ssid = "RED-WIFI";//type your ssid
const char* password = "CONTRASEÑA";//type your password
int PinRele = 2; // GPIO2 of ESP8266
WiFiServer server(80);//Service Port
void setup() {
Serial.begin(115200);
delay(10);
pinMode(PinRele, OUTPUT);
digitalWrite(PinRele, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
int value = LOW;
if (request.indexOf("/LIGHT=ON") != -1) {
digitalWrite(PinRele, HIGH);
value = HIGH;
}
if (request.indexOf("/LIGHT=OFF") != -1){
digitalWrite(PinRele, LOW);
value = LOW;
}
//Set PinRele according to the request
//digitalWrite(PinRele, value);
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("