Arduino Projects

Arduino Mega HMI touch screen

Description:

 

Arduino Mega HMI touch screen- In this tutorial, you will learn how to make an Arduino or Mega based HMI system using TFT LCD Touch Screen. This is an Introductory tutorial, in which we will be controlling an led and display the On the time of controller in seconds.

While in my Upcoming tutorials I will use this HMI touch screen for

  1. To display sensors data on this screen,
  2. I will interface this with the Neo 6M GPS module for making a real-time map tracking system.
  3. For controlling multiple loads
  4. I will also use this touch screen with the RFID for displaying the images.

we will also be using this with a fingerprint module for making a voting system. and so on.I will be using this touch screen in so many other projects. so Subscribe right now to my website and YouTube channel, so that you never miss any of my upcoming tutorials.



The HMI Touch screens are nowadays most commonly used in industries for control and monitoring. It eliminates the need for the hardware switches. Moreover, the HMI touch screen is easy to use. New functions can be added, the interface application can be modified at any time. Different pages can be designed for the control and monitoring of electrical machines and sensors.

In Industries the HMI touch screens are used with PLC’S and such HMIC touch screens are really expensive. So the purpose of this tutorial is to help you guys, how you can make your own HMI control system for the Arduino Mega using a 5 inch TFT touch screen. For the complete explanation, you can watch a video available at the end of this Article.


Amazon Links:

12v Adaptor:

Mega 2560:

ITDB02 Arduino mega shield 2.1:

5 Inch TFT LCD Touch Screen:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

DISCLAIMER:

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!

HMI Touch screen Breakout board soldering:

Breakout board for the touch screen

HMI TOUCH SCREEN

As you can see currently this module cannot be used with the output devices like for example relays, led’s, etc, for the external hardware interfacing we will need to make some changes, we will Solder some wires with the desired pins so that it can pass digital signals to the controlling circuit.


HMI TOUCH SCREEN

I started by soldering some jumper wires with the ground and other pins 13,12,11 and 10.  After the Solder is has done then perform the short circuit test and make sure there is no solder bridge, also make sure you check the continuity of the jumper wires, sometimes the jumpers wires are broken inside. I am saying this from my practical experience because this has happened to me so many times.


HMI TOUCH SCREEN

This breakout board will be used with Mega. As you can see all the pin’s of the mega are occupied by the breakout board, so that’s why we had to solder jumper wires with the breakout. Now any sensor you want to use you will need to solder wires with the breakout board. So, for now, our HMI touch screen setup is completed.

Numbers images:

The following are the number of images that I used for displaying the numbers.

HMI TOUCH SCREEN

HMI TOUCH SCREEN


HMI TOUCH SCREEN

HMI TOUCH SCREEN

HMI TOUCH SCREEN

HMI TOUCH SCREEN

HMI TOUCH SCREEN


HMI TOUCH SCREEN

HMI TOUCH SCREEN

HMI TOUCH SCREEN

Arduino Mega HMI Programming:

Before you start the programming first of all make sure that you download all the necessary libraries. The functions used in this program are explained in the pdf files which you can download by clicking on the links given below.

Download: UTFT

Download: UTFT_Buttons

Download: UTouch

#include <UTouch.h>
#include <UTouchCD.h>
#define TOUCH_ORIENTATION  LANDSCAPE

#include <UTFT_Buttons.h>

#include <UTFT.h>

extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

int button1on = 0; // USED AS A FLAG

int x, y;
int led=13;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";

  // variables for displaying seconds
  // Interval is how long we wait
// add const if this should never change
int interval= 1 ; // in secs 
// Tracks the time since last event fired
unsigned long previousMillis=0;
int previoussecs = 0; 
int currentsecs = 0; 

int bg[] = {
  0, 0, 255};

int fg[] = {
  255, 255, 255};
UTFT myGLCD(ITDB50, 38,39,40,41);   // Remember to change the model parameter to suit your display module!
UTouch        myTouch(6,5,4,3,2);


// Finally we set up UTFT_Buttons :)
void drawButtons()
{
// Draw the upper row of buttons
   myGLCD.setColor(bg[0], bg[1], bg[2]);
  myGLCD.fillRoundRect (90, 180, 220, 230);
  myGLCD.setColor(fg[0], fg[1], fg[2]);
  myGLCD.drawRoundRect (90, 180, 220, 230);
  myGLCD.print(" ON", 115, 195);
  myGLCD.setBackColor (0, 0, 0);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  
}

void setup()
{
  int led=13;
  Serial.begin(9600);
  pinMode(led,OUTPUT);
// Initial setup
  myGLCD.InitLCD();
  myGLCD.clrScr();

  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);

  myGLCD.setFont(BigFont);

  myGLCD.setBackColor(0, 0, 255);
  drawButtons();  
}

void loop()
{

   
   while (true)
  {
    if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
      
      
        if ((x>=90 && x<=220 && y >=180 && y<=230)&&(button1on == 0)  )  // Button: Enter
    {
      waitForIt(90, 180, 220, 230); 
        myGLCD.setColor(bg[0], bg[1], bg[2]);
  myGLCD.fillRoundRect (90, 180, 220, 230);
  myGLCD.setColor(fg[0], fg[1], fg[2]);
  myGLCD.drawRoundRect (90, 180, 220, 230);
  myGLCD.print(" OFF", 115, 195);
  myGLCD.setBackColor (0, 0, 0); 
   Serial.println("ON");
   digitalWrite(led,HIGH);
   button1on = 1;
   x=0;
   y=0;
   
   delay(1000);
    } 
            if ((x>=90 && x<=220 && y >=180 && y<=230)&&(button1on == 1)  )  // Button: Enter
    {
      waitForIt(90, 180, 220, 230); 
        myGLCD.setColor(bg[0], bg[1], bg[2]);
  myGLCD.fillRoundRect (90, 180, 220, 230);
  myGLCD.setColor(fg[0], fg[1], fg[2]);
  myGLCD.drawRoundRect (90, 180, 220, 230);
  myGLCD.print(" ON", 115, 195);
  myGLCD.setBackColor (0, 0, 0); 
   Serial.println("off");
   digitalWrite(led,LOW);
   button1on = 0;
   x=0;
   y=0;
   
   delay(1000);
    }


   
 
    } 
    
          // Get snapshot of time
   unsigned long currentMillis = millis();
   currentsecs = currentMillis / 1000; 
     // How much time has passed, accounting for rollover with subtraction!
   if ((unsigned long)(currentsecs - previoussecs) >= interval) {
      // It's time to do something!
      myGLCD.setColor(fg[0], fg[255], fg[0]); // set font color
      myGLCD.setFont(SevenSegNumFont);
   myGLCD.printNumI(currentsecs, CENTER, 300); 
  // write code here for anything you want to control on 
  //timely basis
      // Use the snapshot to set track time until next event
      previoussecs = currentsecs;
   } 
       myGLCD.setColor(fg[0], fg[0], fg[255]); // set font color
      myGLCD.setFont(BigFont);
    myGLCD.print("Electronic Clinic", CENTER, 400); 
}
 

        

}

void waitForIt(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  while (myTouch.dataAvailable()){
  }
  delay(20);

  
  // list all files in the card with date and size

  myGLCD.setColor(fg[0], fg[1], fg[2]);
  myGLCD.drawRoundRect (x1, y1, x2, y2); 
}

Watch Video

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...

3 Comments

  1. I think other site proprietors should take this web site as an model, very clean and fantastic user genial style and design, as well as the content. You’re an expert in this topic!

  2. One more thing I would like to state is that as an alternative to trying to suit all your online degree training on days that you complete work (considering that people are fatigued when they return home), try to obtain most of your classes on the week-ends and only a couple courses in weekdays, even if it means a little time off your end of the week. This is fantastic because on the weekends, you will be extra rested as well as concentrated upon school work. Many thanks for the different guidelines I have learned from your site.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button