HMI Arduino Monitoring and Control Automation Project

(Last Updated On: February 18, 2020)

HMI Arduino Monitoring and Control

Description:

HMI Arduino Monitoring and Control Automation Project- Arduino HMI TFT LCD Module Electrical Load controller- The 10.1” HMI Intelligent TFT LCD Module used in this video is sponsored by the Stone Technologies. Stone Technologies is a professional Manufacturer of HMI Intelligent TFT LCD modules.  Depending on the application the Stone Technologies offers Industrial Type, Advanced type, and Civil Type Intelligent TFT LCD modules available in different sizes. The one I am using in this series of videos is the Civil Type 10.1 inch HMI display Module. For more information visit stoneitech.com.

In this article, you will learn how to make an industrial monitoring and control system using the HMI TFT LCD Touchscreen Module and Arduino Uno. In this project, a sensor connected with the Arduino Uno can be monitored in real-time using the HMI Display. Two 220Vac light bulbs are connected with the Arduino which can be controlled directly from the HMI touchscreen display. This project is based on two-way Serial communication. The control commands from the HMI display are sent serially to the Arduino and also the Sensor data from the Arduino is sent serially to the HMI display, where the sensor data is stored in the specified memory location and displayed on the specific user interface.


To keep things simpler and understandable, I connected a variable resistor or Potentiometer as the sensor with the Arduino. You can replace this sensor with any other type of sensor you want.

This is my 5th Tutorial on the Arduino and HMI TFT LCD Module. This project is entirely based on my previous 4 tutorials. I highly recommend first, read my previous articles and then you can resume from here.  Link to the previous 4 tutorials is given below with a short description.

 

10.1” HMI Intelligent TFT LCD Module, Display Panel, & Touchscreen

 

In tutorial number1 I explained how to design a graphical user interface using the images designed in Adobe Photoshop. How to use the button function, data variable function, Hardware parameter function and how to use the Drag adjustment, and Slider Scale function for controlling the screen brightness.

 

10.1” HMI intelligent TFT LCD UART Serial Communication

 

In tutorial number 2 I explained the commands used for reading and writing, how to control the user interface without pressing the on-screen buttons… how to access the brightness control register and so on.

 

Arduino HMI TFT LCD Display Sensor Monitoring

 

In tutorial number 3, I explained how to monitor a sensor in real-time using Arduino and the HMI Touchscreen TFT LCD display module. The sensor values are displayed in the boxes.

 

Arduino HMI TFT LCD Module Electrical Load controller

 

In Tutorial Number 4, you will learn how to control electrical loads using 10.1” HMI TFT LCD Display Module and Arduino Uno. The control commands are sent serially from the HMI Touchscreen display Module through the max232 board to the Arduino. The Arduino then Turns ON and Turns OFF the desired load depending on the command. Using the same button you can Turn ON and Turn OFF the load, the buttons used on the HMI GUI works as the Toggle switches. For the demonstration purposes, I have connected 220Vac light bulbs which you can replace with other AC or DC loads.



Note: Be very careful while working on the 220Vac as it can be really dangerous, wear protective gloves. Make this project at your own risk.

HMI Arduino Monitoring and Control

This is the Final, main screen image. If you have read my previous articles, at this point you should know that this project is the combination of my previous two projects. If you click on the Sensors button, it will take you to the Sensors monitoring user interface and if you click on the control button it will take you to the control panel user interface as you can see in the image below.

HMI Arduino Monitoring and Control

This image is the main image of the control panel, while the image given below is the image which will be used as the button click effect.

HMI Arduino Monitoring and Control

Below is the image of the Sensor Monitoring user interface.

HMI Arduino Monitoring and Control

In this tutorial, we will cover

  1. Complete Circuit Diagram
  2. Arduino Interfacing with the HMI TFT LCD Module, and
  3. Arduino Programming

Without any further delay let’s get started!!!

The purchase links of the HMI TFT LCD Module and other components used in this project are given below:

HMI TFT LCD MODULE Amazon product link: https://amzn.to/3747ybU

Arduino Uno:  https://amzn.to/37oaksm

MAX232 board: https://amzn.to/359kcVS

RS232 Cable: https://amzn.to/2MFGb04

Two-channel Relay Module: https://amzn.to/2SEsKBs

Alibaba Product link: https://amzn.to/39IcqER

Official website link: Www.stoneitech.com

https://dwz.cn/xnz5pTK9 (Japan)

https://dwz.cn/t2Ji0v4E (UK)

https://dwz.cn/KUJ5kBgu (France)

https://dwz.cn/3Wqh7RAM (Italy)

https://dwz.cn/2XDDEq8f (Spain)

https://dwz.cn/XUUfpHEV (India)

eBay store link: Https://www.ebay.com/str/stonedisplay

Aliexpress store link: https://dwz.cn/PpQlr2RU

Other components and Tools:

Mega 2560: https://amzn.to/2ze1kdu

Super Starter kit for Beginners https://amzn.to/2KJvmKG

Jumper Wires: https://amzn.to/2KMoVXs

Bread Board: https://amzn.to/2MS4q8X

12v Adaptor:  https://amzn.to/2Ntr6h1

PCB plate: https://amzn.to/2IUwpCt

Variable Supply: https://amzn.to/2MT4Qfj

Digital Multimeter: https://amzn.to/2Nvft9i

Vero Board/stripboard: https://amzn.to/2MTf9jD

Soldering iron kit:  “best” You guys should definitely purchase this https://amzn.to/2zfoNuJ

Solder wire: https://amzn.to/2ufUMWf

Wire Stripper: https://amzn.to/2KOqxfU

wirecutter: https://amzn.to/2ucIq14

PCB small portable drill machine: https://amzn.to/2Nu62XF

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Arduino and HMI based Industrial Automation:

A perfect Industrial Automation project is the one that can Monitor different processes and control different loads automatically. The main advantage of the HMI “Human Machine Interface” system is that we can control hundreds of electrical loads/machines and monitor hundreds of sensors all at the same time using only one HMI display. Imagine if you need to control 20 machines, this way you will need 20 buttons with a lot of wiring. The same thing can be done using the HMI Touchscreen display; we can design different control panels in the HMI which can be used to control different processes.

So the project under discussion can be used at the industrial level, this can be used for the home automation, this can be used in colleges, Hospitals, Universities, Railways, Airports, etc.

HMI Arduino Monitoring and Control Project Circuit Diagram:

HMI Arduino Monitoring and Control

As you can see the circuit diagram is really simple. The 10.1 inch TFT LCD Module and Arduino is powered up using a 12v adaptor or battery. All the grounds are connected together. The DIN pin of the TFT LCD module which is data-in is connected with the TX pin of the db9, the DOUT pin which is the data-out pin is connected with the RX pin of the DB9. The VCC pin of the MAX232 board is connected with the Arduino’s 5 volts, the ground of the MAX232 is connected with the Arduino’s ground, while the TX and RX pins of the MAX232 Board are connected with the Arduino’s pin number 2 and Pin number 3. Later in the programming, I will explain, why am I using pin number 2 and pin number 3 as the Serial Port.

A two-channel relay module is connected with the Arduino’s pin number 12 and pin number 13. You can use a readymade relay module or follow the same connections and build the one by yourself. It’s very simple. The relays used in this project are of the type SPDT “Single Pole and Double Throw”. This type of relay has a total of 5 pins, two relay coil pins, common, normally open, and normally closed. The one side of the relay coil is connected with the 12 volts while the other side of the relay coil is connected with the collector of the 2n2222 NPN transistor. The emitter is connected with the ground, while the base is connected with the 10k ohm resistor. The 10k ohm resistor and the transistor together are used to control the relay which is also called the relay driver. If you want to learn in detail about the electro-mechanical relays, and relay driver design calculations then read my article available on electroniclinic.com you can find a link in the description.

The middle leg of the Potentiometer or variable resistor is connected with the Analog pin A0. While the other two legs are connected with the Arduino’s 3.3 Volts and Gnd.

HMI Arduino Monitoring and Control

This is a seven-channel relay module, but out of these 7 relays, I will be using only two relays. One relay will be connected with the Arduino’s digital pin 12 and the other relay will be connected with the Arduino’s digital pin 13.



Arduino Interfacing with MAX232 and HMI TFT LCD module:

HMI Arduino Monitoring and Control

The HMI TFT LCD display module connection with the MAX232 board and Arduino remain the same as explained in my previous tutorial, the link is given above. This time only the relay module is added. All the connections are done as per the circuit diagram. In the above image, a variable resistor is missing, which you can connect by following the same connections as explained in the circuit diagram.

HMI TFT LCD Module Control Panel GUI:

As you can see in the images above, I am using the same GUI, this time I added the control button on the main screen. So, when I click on the control button it takes me to the image8 which is the control panel user interface.

HMI Arduino Monitoring and Control

This time I used the Return pressed key value function. I selected the variable memory as 0011, which is same for all the buttons. But the keys values are different. For the load1 I selected 0001, for the load2 I selected 0002, and so on up to 0005. You can select any Keys value you want. Finally, when I click on the Back button it takes me to the main screen.

HMI Arduino Monitoring and Control

On the sensor user interface, I selected the variable memory 0002 for the Sensor1 and 0006 for the Sensor 2 which you can see in the Arduino programming given below. So that’s all about the GUI of the HMI TFT LCD Display Module. Now, let’s have a look at the Arduino programming.


HMI Arduino Monitoring and Control Project Programming:


HMI Arduino Monitoring and Control Program Explanation:

#include <SoftwareSerial.h>

SoftwareSerial max232(2,3);

I started off with the SoftwareSerial library. The SoftwareSerial is basically a library that enables the Serial Communication on digital pins other than the Arduino’s default Serial Port. Using the SoftwareSerial library we can create multiple software serial ports with speeds up to 115200bps.

In this particular project, you can also use the Arduino’s default Serial port which is on Pin number 0 and pin number 1. But trust me this will really make you tired, because each time you upload a program, you will have to remove the wires. That’s why I always say never use the Arduino’s default Serial Port for the communication with other devices. The Arduino’s default Serial Port should only be used for debugging purposes.

I created a software Serial Port with the name max232 on the Arduino’s pin number 2 and pin number 3. Pin number 2 is the RX while pin number 3 is the TX.

#define Sensor1_H               0x00

#define Sensor1_L               0x02

#define Sensor2_H               0x00

#define Sensor2_L               0x06

Then I defined the Sensors High and Low bytes. These are the same address used in the GUI. 0x0002 and 0x0006.

Then I defined a pin for the potentiometer. A potentiometer is connected with the Analog Pin A0 of the Arduino.

int vr = A0;

unsigned char sensor1_send[8]= {0xA5, 0x5A, 0x05, 0x82, Sensor1_H, Sensor1_L, 0x00, 0x00};

unsigned char sensor2_send[8]= {0xA5, 0x5A, 0x05, 0x82, Sensor2_H, Sensor2_L,  0x00, 0x00};

These are the same commands which I have already explained in my previous tutorial.

char data;

String mystring;

int load1 = 13;

int load1f = 0;

int load2 = 12;

int load2f = 0;

Then I defined a variable data of the type character. Then I defined another variable mystring of the type String. Then I defined pins for the relays which are connected with the Arduino’s pin number 13 and 12. The load1f and load2f will be used as the flags.


void setup()

{

Serial.begin(115200);

max232.begin(115200);

pinMode(vr,INPUT);

pinMode(load1, OUTPUT);

pinMode(load2, OUTPUT);

digitalWrite(load1, LOW);

digitalWrite(load2, LOW);

}

In this void setup function, I activated the serial communication and set the sensor as input and  loads as OUTPUT.

Then starts the void loop function.

if (max232.available()>0)

{

data = max232.read();

mystring = mystring + byte(data) ;

delay(10);

}

The above condition means if the Arduino has received data from the HMI TFT LCD display Module, simply read the max232 port store the character in variable data. Convert the received character into the byte and add it with the mystring to make the complete message.

if (max232.available() == 0)

{

//Serial.println(mystring);

load1control();

load2control();

// Sensors data to HMI Intelligent TFT LCD module

int sensor1 = analogRead(vr);

int sensor2 = -53;

sensor1_send[6] = highByte(sensor1);

sensor1_send[7] = lowByte(sensor1);

max232.write(sensor1_send,8);

delay(100);

sensor2_send[6] = highByte(sensor2);

sensor2_send[7] = lowByte(sensor2);

max232.write(sensor2_send,8);

delay(100);

mystring = “”;

}

This condition means if there is no more data on the max232 port then execute the load1control() and load2control() functions. Then we read the sensor and store the value variable Sensor1 which is of the type integer. In sensor2 we store a random value of -53, to check if we can display the negative value. The we divide the sensors values in high bytes and low bytes and the store the results at desired locations in the array. Then finally we empty the mystring value.



void load1control()

{

if (mystring.endsWith(“101”)&& (load1f == 0))

{

mystring = “”;

if(digitalRead(load1) == LOW)

{

digitalWrite(load1,HIGH);

Serial.println(“load1 High”);

}

load1f = 1;

}

if (mystring.endsWith(“101”) && (load1f == 1))

{

mystring = “”;

if(digitalRead(load1) == HIGH)

{

digitalWrite(load1,LOW);

Serial.println(“load1 LOW”);

}

load1f = 0;

}

}

Load1control() function is a user defined function, it has no return type and doesn’t take any argument as the input.

if (mystring.endsWith(“101”)&& (load1f == 0))

This condition means if the mystring ends with the 101 and load1f is 0 then empty the mystring variable, and check if the load is off then turn on the load. And change the load1f status from 0 to 1.

if (mystring.endsWith(“101”) && (load1f == 1))

If the same button is pressed again and the load1f is equal to 1, empty the mystring variable , and if the load1 is high then turn OFF the load1, and again change the load1f status from 1 to 0.

Similarly for the load2.

The same way you can do it for all the 5 buttons.

For the complete step by step explanation and practical demonstration watch videos give below. So now you know this code is the combination of the sensor monitoring and load controller projects.

Related Videos:

Arduino HMI Sensor Monitoring:

 

Arduino HMI 220Vac Load Controller:

 

Arduino HMI GUI Designing:

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply