The ESP8266 Module controls the relay status

The ESP8266 Module controls the relay status

ESP8266 is a low-power UART-WiFi module. It can be widely used in many aspects such as smart power system, smart transportation, smart home, handheld devices, industrial control and so on. This module uses 3.3V power supply, and supports the wireless 802.11 b/g/n standard. In addition, the WiFi module has three operating modes, namely STA, AP and STA + AP
The following is a using routine about this ESP8266 WiFi module on the Arduino platform .

 

 

 

 

 

 

 

 

 

Overview
The PC software “USR-TCP232-Test.exe” send control commands via the WiFi wireless network to change the relay module. Then the status of the relay module will be returned to the computer through ESP8266.

Requirement

  • 1* Adeept UNO R3 Board
  • 1* USB Cable
  • 1* Relay Module
  • 1* RGB LED
  • 1* Breadboard
  • 1* WiFi Router
  • Several Jumper Wires

Procedures
1. Build the circuit

2. Network Configuration
Run the software USR-TCP232-Test.exe on your computer, then enter the following configuration information:AdeeptData

3.Program  AdeeptESP8266Relay.ino:

/***********************************************************
File name:   AdeeptESP8266Relay.ino
Description: Arduino receive wifi data and then control relay
Website:     www.adeept.com
E-mail:      support@adeept.com
Author:      Tom
Date:        2017/01/16 
***********************************************************/

int RelayPin   = 8;    //   Relsy module connected to digital pin 8  

void setup()    
{   
   Serial.begin(115200);       // set up a wifi serial communication baud rate 115200
   pinMode(RelayPin, OUTPUT);    // sets the RelayPin to be an output 
   delay(4000);
   Serial.println("AT+CWMODE=3");//set to softAP+station mode
   delay(4000);     //delay 4s
   Serial.println("AT+RST");     //reset wifi
   delay(4000);     //delay 4s
   Serial.println("AT+CWJAP=\"MERCURY_BE90\",\"adeept1205\"");   //replace "MERCURY_BE90" to your WiFi AP name(SSID), replace "adeept1205" to your WiFi password
   delay(4000);     //delay 4s
   delay(4000);     //delay 4s
   Serial.println("AT+CIPSTART=\"TCP\",\"192.168.0.101\",8080");   //TCP Protocol, server IP addr, port
   delay(4000);     //delay 4s
   delay(4000);     //delay 4s
   Serial.println("AT+CIPMODE=1");//Open transparent mode
   delay(4000);     //delay 4s
   Serial.println("AT+CIPSEND");  //Starting transparent mode
   delay(4000);     //delay 4s
   Serial.println(" Adeept_wifi connection is successful! ");//wifi send 'Adeept_wifi connection is successful!'
} 

void loop()   
{      
  while(Serial.available())
   {      
     switch(Serial.read())
     {
         case '1': digitalWrite(RelayPin,HIGH); //drive relay open conduction
                   Serial.println("Relay Open ");//Adeept wifi send Relay status 'Relay Open'
                   break;
         case '2': digitalWrite(RelayPin, LOW);  //drive the relay is closed off
                   Serial.println("Relay Close ");//Adeept wifi send Relay status 'Relay Close'
                   break;
         default:  break;
       }
    }
}

4.Compile the program and upload to the Adeept UNO R3 board

note:
When downloading the program, please disconnect the communication port(URXD , UTXD) of ESP8266 from Adeept UNO R3 Board. After the program is completed, connect the ESP8266 communication port(URXD , UTXD) to Adeept UNO R3 Board.Otherwise the program download may fail.

6.Observe the experimental phenomena

Send different character to the Adeept UNO R3 Board via WiFi. Such as and “2”.

Leave a Reply