Controle Remoto WI-FI 3 Canais – ESP para ESP8266 – Controlando Cargas
Olá a Todos!
Que você pode ver clicando no link abaixo!
- Comunicação entre 4 ESPs com central ESP sem Roteador!
Postamos esse artigo devido a uma dúvida de um dos nossos inscritos que queria construir um tipo de controle de ESP para ESP com vários botões de acionamento, decidimos trazer isso a todos, pois acreditamos que se um tem essa dúvida, dezenas de outros inscritos também devem ter.
Neste projeto, nós iremos criar um Controle Remoto Wi-Fi com o ESP8266, que pode acionar qualquer tipo de carga, só dependerá do tipo de evento que você irá fazer, podendo ser usado para, por exemplo, interruptores inteligentes sem fio para automação residencial.
Você pode se interessar também!
- Controlando LEDs com dois ESP8266 utilizando Protocolo ESP-NOW
- Como Ler Valores Analógicos ADC Usando NodeMCU ESP8266 – IDE Arduíno!
- Como Hackear Circuito Módulo Relé para funcionar com ESP8266 & ESP32 com 3.3V
- Como utilizar o Botão Flash do NodeMCU ESP8266
- Piscando LEDs Independentes sem delay() utilizando Função millis()
- Alarme de Segurança com Sensor PIR e ESP8266 – Sensor de Movimento
Descrição!
Controle de dispositivos, chave sem fio, interruptor sem fio, etc., não é uma ideia nova, e este conceito foi popularizado pela Amazon que criou o interruptor Dash, sendo um pequeno interruptor que envia comandos instantaneamente a um dispositivo remotamente, e hoje podemos ver dezenas de modelos de fabricantes diferentes no mercado.
Logo abaixo temos o código inscrito na IDE Arduíno, para que deseja uma melhor explicação, temos o vídeo no nosso canal do YouTube no final desse Post que explica passo a passo os principais conceitos dessa programação.
Código Fonte do Transmissor “Controle”
//==================================================================================//
// Created by: Engineer Jemerson Marques, On: 10.06.2019 - FVM Learning website //
// Available at: https://www.fvml.com.br and on Youtube channel //
// https://www.youtube.com/c/FVMLearning - I hope you have fun - Good luck //
//----------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------
// Libraries Needed For This Project
//------------------------------------------------------------------------------------
#include <ESP8266WiFi.h> // The Basic Function Of The ESP NODE-MCU
//------------------------------------------------------------------------------------
// Defining I/O Pins
//------------------------------------------------------------------------------------
#define LEDBOARD 2 // WIFI Module LED
#define BUTTON_1 D1 // Button 1 channel one
#define BUTTON_2 D2 // Button 2 channel two
#define BUTTON_3 D3 // Button 3 channel three
//------------------------------------------------------------------------------------
// WIFI Authentication Variables
//------------------------------------------------------------------------------------
char ssid[] = "fvml"; // SSID of your AP
char pass[] = "fvmlearning"; // password of your AP
//------------------------------------------------------------------------------------
// WIFI Module Mode & IP
//------------------------------------------------------------------------------------
IPAddress server(192, 168, 4, 15); // IP address of the AP
WiFiClient client;
//====================================================================================
void setup() {
Serial.begin(9600);
pinMode(LEDBOARD, OUTPUT); // Initiate the Onboard Led Output
pinMode(BUTTON_1, INPUT_PULLUP); // Initiate the ESP Pin: INPUT_PULLUP - Its mean that you no need put resistor
pinMode(BUTTON_2, INPUT_PULLUP); // Initiate the ESP Pin: INPUT_PULLUP - Its mean that you no need put resistor
pinMode(BUTTON_3, INPUT_PULLUP); // Initiate the ESP Pin: INPUT_PULLUP - Its mean that you no need put resistor
WiFi.begin(ssid, pass); // connects to the WiFi AP
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
//====================================================================================
void loop() {
ReadButton_1();
ReadButton_2();
ReadButton_3();
}
//====================================================================================
void ReadButton_1() {
int reading = digitalRead(BUTTON_1);
if (reading == LOW) {
client.connect(server, 80);
digitalWrite(LEDBOARD, LOW);
client.print("BUTTON_1r");
client.flush();
digitalWrite(LEDBOARD, HIGH);
client.stop();
} delay(75);
}
//====================================================================================
void ReadButton_2() {
int reading = digitalRead(BUTTON_2);
if (reading == LOW) {
client.connect(server, 80);
digitalWrite(LEDBOARD, LOW);
client.print("BUTTON_2r");
client.flush();
digitalWrite(LEDBOARD, HIGH);
client.stop();
} delay(75);
}
//====================================================================================
void ReadButton_3() {
int reading = digitalRead(BUTTON_3);
if (reading == LOW) {
client.connect(server, 80);
digitalWrite(LEDBOARD, LOW);
client.print("BUTTON_3r");
client.flush();
digitalWrite(LEDBOARD, HIGH);
client.stop();
} delay(75);
}
//====================================================================================
Código Fonte do Receptor “Central ESP”
//==================================================================================//
// Created by: Engineer Jemerson Marques, On: 10.06.2019 - FVM Learning website //
// Available at: https://www.fvml.com.br and on Youtube channel //
// https://www.youtube.com/c/FVMLearning - I hope you have fun - Good luck //
//----------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------
// Libraries Needed For This Project
//------------------------------------------------------------------------------------
#include // The Basic Function Of The ESP NOD MCU
//------------------------------------------------------------------------------------
// WIFI Module Config
//------------------------------------------------------------------------------------
WiFiServer server(80);
IPAddress IP(192, 168, 4, 15);
IPAddress mask = (255, 255, 255, 0);
//------------------------------------------------------------------------------------
// Defining I/O Pins
//------------------------------------------------------------------------------------
#define LedBoard 2 // WIFI Module LED
#define LED1 D0 // LED Receiver One
#define LED2 D1 // LED Receiver Two
#define LED3 D2 // LED Receiver Three
//====================================================================================
void setup() {
pinMode(LedBoard, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
WiFi.mode(WIFI_AP);
WiFi.softAP("fvml", "fvmlearning");
WiFi.softAPConfig(IP, IP, mask);
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
digitalWrite(LedBoard, LOW);
String request = client.readStringUntil('r');
client.flush();
if (request == "BUTTON_1") {
digitalWrite(LED1, !digitalRead(LED1));
digitalWrite(LedBoard, HIGH);
}
if (request == "BUTTON_2") {
digitalWrite(LED2, !digitalRead(LED2));
digitalWrite(LedBoard, HIGH);
}
if (request == "BUTTON_3") {
digitalWrite(LED3, !digitalRead(LED3));
digitalWrite(LedBoard, HIGH);
}
}
English
Español


