Posted in IOT (Internet Of Things)

A PLC (Program Logic Controller) that Talks and Sends Email

The following project occupied my time for a couple of weeks.  It required learning how to use a PLC (Program Logic Controller);  do embedded programming on the Arduino platform; send email using IOT (Internet of Things) 8266-12E Wifi Chip.  The project was fun and rewarding. but most of all would enhance the user experience of the CNC Mill.

After working with the CNC mill, you will discover that engraving patterns on wood takes a long time.   One pattern took about 3 hours to complete.  There is no need for me to watch the machine for 3 hours, but I needed to know when the job was done so I can turn off the machine.   Leaving the machine running by itself with a sharp router bit turning is dangerous and asking for disaster to happen.  So I needed a device that would detect when the CNC job was done and would notify me by email.

The project used an “Open Source” PLC to detect when the mill completed a job.   When a job completed, the PLC would play a loud message telling anyone in the vicinity that the job was done.  Next the PLC would tell the 8266 Wifi Internet chip to send an email notification to me.  If I was in the shop, I would know the jobs was done because I can hear the message.  Also, if I was not in the shop, I would know the job was done, by checking my email.

The PLC and 8266 Wifi Chip.

The PLC was purchased from Digital Loggers via Amazon.

https://www.amazon.com/enabled-Powerful-durable-Ardino-compatible/dp/B01BFV7O1U/ref=sr_1_1?ie=UTF8&qid=1491885779&sr=8-1&keywords=plc

The PLC is based on the Arduino Mega2650 which contains the following devices

  • Speakers
  • A touch screen,
  • LCD display.
  • ESP8266 Wifi chip, but we used another 8266 Dev Kit.
  • Digital and Analog Input/Outputs.
  • Relays.
  • Card reader
  • Serial and USB ports.

The NodeMCU LUA WiFi Internet ESP8266 Dev Kit was added to the project.  The ESP8266 on the PLC was not used, because the Dev Kit was more advanced.  The kit was purchased from HiLetGo via Amazon.

https://www.amazon.com/HiLetgo-Version-NodeMCU-Internet-Development/dp/B010O1G1ES/ref=sr_1_1?ie=UTF8&qid=1491886314&sr=8-1&keywords=hiletgo

Setting up the KFLOP to control GPIO.

The CNC machine communicates to the PLC by hooking up an output of the CNC machine to an input of the PLC.  The CNC machine was configured so that the command M30 would set the IO26 state HIGH when executed.  Also the PLC was programmed to detect the state of the input signal.  The KMotionCNC.exe application allows you the configure the IO as shown below;

Also you must also modify the InitKStep3Axis.c program for the KFLOP to configure IO26 bit.  The program is located under C:\KMotion433\C Programs\KStep directory.  If you are using the PWM to control your servos, you will need to change a different program.

You need to add the 2 lines of code.

SetBitDirection(26,1);  // set Enable Signal as Output
SetStateBit(26, 0);        // the Signal is set LOw

Here is the code program that executes the M30 command.  The program was shortened for demonstration purposes.

When command is executed, the KFLOP will set the output state to HIGH.

Setting up the CNC Mill to the PLC and the 8266 NodeMcu Dev Kit

The setup is made up of the

  • PLC
  • 8266 NodeMcu Dev Wifi Internet Kit
  • Phone to detect the email.
  • A 3.3 V volt regulator was used, because the GPIO pins on the PLC and 8266 can only handle 3.3V signal levels.

In other words if you use a higher voltage, you will damage the part.  Do not use 5v on the 3.3v GPIO.

Theory of Operation

Hopefully this is the simplest explanation.  The PLC is connected to the CNC mill via GPIO (General Purpose Input Output).  To send email, the PLC sends a signal to the 8266 Nodemcu Dev Kit.  The implementation incorporates the following steps.

  1. After the CNC mill has finished a job, the G-Code program executes M30 to send a signal to the PLC.
  2. The PLC detects when the signal goes HIGH, then the PLC sends a signal to the 8266.
  3. The 8266 detects when the signal goes HIGH, then the 8266 logins into the Wifi and sends the email notification.

Connecting the KFLOP to PLC

To connect the KFLOP GPIO to the PLC, simply use a 2 conductor wire.  One side goes to ground of the KFLOP and PLC.  The other side goes from JP6 pin 5 (IO26) to IN-31 of the PLC.  When the signal changes the state from LOW to HIGH, the PLC plays a message “Your CNC job is done.  Please check your email for the notification.  Thanks you”.  The message ends with the Ferris Bueller “Oh Yeah”

Connecting the PLC to 8266 NodeMcu Dev Kit

To connect the PLC to the 8266, simply connect Digital Output 38 of the PLC to the Digital Input 16 which is connected to pin D0.

References for the NodeMCU-DEVKIT-V1.0 (8266-ESP12E based).

There are infinite number of the references on the chip but I will show a few.  The dev kit was less than $10 dollars on the Amazon.  I started using the ESPlorer and then moved on the Arduino.  There are many libraries implemented by the Arduino.

  1. NodeMCU-DEVKIT-V1.0 – https://github.com/nodemcu/nodemcu-devkit.
  2. Tutorial for the 8266 – http://www.kloppenborg.net/blog/microcontrollers/2016/08/02/getting-started-with-the-esp8266.
  3. Tutorial to setup the Arduino IDE to develop software on the 8266-http://www.instructables.com/id/Programming-ESP8266-ESP-12E-NodeMCU-Using-Arduino-/

A Video of a PLC (Program Logic Controller) that Talks and Sends Email

Hope you like the video.

Leave a Reply