How to connect Wi-Fi module to Arduino based PLC

How to connect Wi-Fi module to Arduino based PLC

On this post it is showed how to connect a WiFi module, ESP8266 WiFi shield on this example, to an Arduino based PLC. With all the Industrial Shields equipment it’s possible to add a WiFi module as ESP8266 WiFi shield.

ESP8266 is a cheap and popular WiFi/microcontroller system-on-chip. Furthermore it can be programmed like a normal controller. Actually ESP8266 is a serially-controlled WiFi gateway. It can be configured with AT command, so using the Industrial Shiedls equipment’s UART it’s possible to communicate to WiFi networks and interact with IoT world over TCP or UDP protocols.  

After the presentation it’s showed how to connect the WiFi shield to the Arduino based PLC.

How to connect the devices? 

Below is showed a table of how to connect both devices:

Industrial Shields PLC ESP8266
5V 5V

*The PLC must be powered supply between 12-24V to have enough power to feed ESP8266

How to configure ESP8266 ?

First it’s necessary to to download and change some things on ESP8266 library. Follow the next steps:

  • Download and install SparkFun ESP8266 WiFi Shield library to your Arduino IDE.
  • Open SparkFunESP8266WiFi.cpp and do the next changes:
    • On the firsts lines on HARDWARE_SERIAL declaration, change Serial for Serial1, next is showed a picture of where you must change it:

  • On any sketch using ESP8266 is required the function esp8266.begin(9600, ESP8266_HARDWARE_SERIAL); on the setUp() function for a proper functionality.
  • Put the switch selector on hardware serial position (UART HW):

How to use the AT commands  ?

Once the device is configured and the library is ready it’s time to set the ESP8266. Using AT commands it’s possible to configure the ESP8266 parameters. Next are showed the main parameters, see more information on the next link:

Function AT Command
Reset Device AT+RST
Default Parameters AT+RESTORE
Select WiFi mode (station mode) AT+CWMODE=1
Show AP’s List  AT+CWLAP
Connect to AP AT+CWJAP=»APname»,»APpass»
Disconnect to AP AT+CWQAP
Set IP address station AT+CIPSTA_CUR=»IP»,»gateway»,»netmark»
Get Connection Status AT+CIPSTATUS
Create as TCP Server AT+CIPSERVER=1,port


It’s required the proper sketch to use AT commands and communicate with ESP8266 through Serial1 (RX1, TX1). Using the ESP8266_Serial_Passthrough example it’s possible to do that. Remember to select on the Serial monitor parameter the Both NL & CR  and 9600 baud rate. Next is showed the code:

#include <SparkFunESP8266WiFi.h>

void setup() 
  esp8266.begin(9600, ESP8266_HARDWARE_SERIAL);

void loop() 

void serialPassthrough()
  while (Serial.available())
  while (esp8266.available())
Los comentarios están cerrados