Raspberry Pi Industrial Automation HMI/GUI designing using PYQT5

(Last Updated On: February 5, 2022)

Raspberry Pi Industrial Automation Project Description:

Raspberry Pi Industrial Automation

Raspberry Pi Industrial Automation HMI/GUI designing using PYQT5- The components used in this project are sponsored by the DFrobot. DFrobot is a leading robotics and open source hardware provider. They create innovative, user-friendly hardware & software products that become the building blocks in all kinds of electronic projects. I personally recommend you should definitely visit www.dfrobot.com.

Raspberry Pi Industrial Automation- In this tutorial, you will learn how to make Raspberry Pi based Industrial Automation system using Raspberry Pi 3 b+, 5.5inch Oled touch screen, Wifi keyboard, and Mouse. The HMI or GUI application is designed using the PYQT5 software and the Python programming is done using the Thonny IDE.

This is part1 of the Raspberry Pi Industrial Automation System which only covers how to design an HMI application for the Raspberry Pi and control some relays. For the demonstration purposes I have connected 220Vac Bulbs.  In part2 I will explain how to design an HMI application for the Raspberry Pi for monitoring different Sensors.

While in Part3 of the Raspberry Pi industrial Automation system, I will design a complete HMI application for the Raspberry Pi, which will be able to monitor different sensors and control different electrical loads. Subscribe right now so that you never miss any of my upcoming tutorials.

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

The components and tools used in this project can be purchased from Amazon, the components Purchase links are given below:

DFrobot components purchase links:

Raspberry pi 3 b+ :

Night Vision Camera:

5.5 inch HDMI Oled capacitive Touchscreen: 

Wireless Keyboard and Mouse Combo:

Amazon Purchase links:

Raspberry Pi

12v SPDT type 4-channel relay Module:

8 channel Relay Module

raspberry pi 4 4gb kit

Wireless Keyboard and Mouse for raspberry pi:

Night vision Camera for Raspberry Pi:

Oled HDMI touch display for raspberry pi:

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

*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!

Raspberry Pi Industrial Automation Components interfacing:

Raspberry Pi Industrial Automation

This is a 7 channel relay module, currently, I am using only 4 relays which are connected with the Raspberry Pi GPIO pins 26, 19, 13, and 21. While the grey wire is connected with the Raspberry Pi GND pin. This relay module is powered up using a 12v Adaptor.

Raspberry Pi Industrial Automation

The touch screen is powered up using the Raspberry Pi USB port. The LCD is connected with the HDMI port of the Raspberry Pi using the HDMI Adaptor. That’s all about the connections.

PYQT 5 Software Installation:

After you have installed the Operating System in the Raspberry Pi 3 B+, The next step is to configure your 5.5 inch O LED touch screen. If you don’t know how to set up your 5.5 inch HDMI supported touch screen then watch the following video tutorial.

After you are done with all the settings, the next step is to install the PYQT5 software which is really simple.


  • Before you continue, make sure that the system is updated to the latest version for this simply write this command on the Raspberry Pi terminal sudo apt-get upgrade and then press the enter key on your keyboard to continue.
  • Next, you have to update the apt-get package so that you can install the pyqt5, in the next step, for now simply write sudo apt-get update and press enter on your keyboard.
  • Now you will need to install the pyqt5 development headers using the command sudo apt-get install qt5-default and press enter.
  • Now install the pyqt5 qtcreator using the command sudo apt-get install qtcreator and press enter.

That’s it, you are done with the installation.

Raspberry Pi Industrial Automation HMI/GUI Designing and Programming:

This is a good designing and programming practice to keep all your project files in one place. I started off by creating a folder for my project files. While you are on the Raspberry Pi desktop, right-click and select Create New and then click on the folder. Enter the folder name as Industrial HMI System or any other name you like. This will create a new folder on the desktop with the name Industrial HMI System. I will save all my project files in this folder.

Raspberry Pi Industrial Automation

Open the Qt 5 designer software for designing the HMI or GUI application.

Raspberry Pi Industrial Automation

The Qt 5 designer software is provided with all the components and tools which can be used to design advanced level Raspberry PI HMI systems. The Qt 5 designer software is very user-friendly; drag and drop the component you want to use. In my case, I am going to use a Pushbutton. On the New Form – Qt Designer select Dialog without Buttons and then click on the create button.

Enter the form dimensions:

Width: 19200

Height: 1000

Now, select a label, drag and drop it on the form. Delete the default text and write any text you want, in my case I wrote “Industrial Raspberry Pi HMI System”.

Raspberry Pi Industrial Automation

Select a horizontal line from the left side components Widget Box, and drop it on the form, change the width of the line as per your requirement. This line is optional and is only used for designing purposes to make the application looks attractive. If you don’t want to use this line, it’s just fine.

Select a Push Button Drag and drop it on the form. Change the dimensions of the Push Button as per your requirement.

Raspberry Pi Industrial Automation

On the right side, you can see the Property Editor, you can change the width and height values, the X and Y axis values, then scroll down and set the font size, again scroll down until you see the text, click and delete the text PushButton. This will delete the text written on the Push Button and write Load1 OFF. This will display the text Load1 OFF on the Push Button.

Now repeat the same steps for the remaining 3 Push Buttons.

After adding all the four buttons change the objectName of all the buttons.

Raspberry Pi Industrial Automation

Select Button number 1 and write the objectname as load_1.

Select Button number 2 and write the objectname as load_2

Select Button number 3 and write the objectname as load_3

Select Button number 4 and write the objectname as load_4

This is how the final Raspberry Pi Industrial Automation HMI application looks.

Raspberry Pi Industrial Automation

Finally, I saved the design with the name “design” in the folder which I created on the Raspberry Pi desktop.

Now we will start the Raspberry Pi Industrial Automation programming.

Raspberry Pi Industrial Automation

We will do the programming in Thonny Python IDE. After you click on the Thonny Python IDE, this will open the editor where you can write your program. Simply copy and paste the following program into the editor.

Raspberry Pi Industrial Automation HMI PYQT 5 Programming in Thonny Python IDE:

Raspberry Pi Industrial Automation HMI PYQT 5 Program Explanation:

I started off with the following instruction

import sys

import sys is used in the python to load the module named sys into the current namespace so, that we can use the name of the module to access the functions and anything else which is defined in the module.

from PyQt5.QtCore import pyqtSlot

The QtCore module contains the core non-GUI modules, including the event loop and the slot and signal function of Qt.

from PyQt5.QtWidgets import QApplication,QDialog

The Qt Widgets Module provides a set of UI elements to build user interfaces in the classic desktop style.

from PyQt5.uic import loadUi this code is used for loading the design.ui file


import RPi.GPIO as gpio

Inside RPi. GPIO, there are two ways to count the IO pins on a Raspberry Pi. The first one uses the numbering system of the BOARD. This refers to the Raspberry Pi board’s P1 header pin numbers. The advantage of using this numbering system is that irrespective of the RPi board revision, your hardware will always work. You won’t have to re-wire or update the code.

BCM numbers are the second numbering system. This is a way of working at a lower level. it applies to the channel numbers on the Broadcom SOC. You always have to deal with a diagram which channel number goes to which pin on the RPi panel. Your script might break with Raspberry Pi board revisions.

To specify which one you use (mandatory):




The following GPIO pins are used to control the relays. You can increase or decrease the number of GPIO pins.

load1=26 variable initialization for load




gpio.setmode(gpio.BCM) // this code is already define above


set all the GPIO pins as the output. Because these pins will be used to control the relays.






class industrial(QDialog):

def init(self):


loadUi(‘design.ui’,self) // calling the main gui design which we create in pyqt5 designer

self.setWindowTitle(‘Industrial Hmi System’)

self.load_1.clicked.connect(self.load1) // this code is used for calling the button function





def load1(self):

if gpio.input(load1):


self.load_1.setText(‘Load1 OFF’)



self.load_1.setText(‘Load1 ON’)


def load2(self):

if gpio.input(load2):


self.load_2.setText(‘Load2 OFF’)



self.load_2.setText(‘Load2 ON’)

def load3(self):

if gpio.input(load3):


self.load_3.setText(‘Load3 OFF’)



self.load_3.setText(‘Load3 ON’)

def load4(self):

if gpio.input(load4):


self.load_4.setText(‘Load4 OFF’)



self.load_4.setText(‘Load4 ON’)


widget=industrial()// variable initialization for main industrial class



If you have any questions regarding this project let me know in a comment. Don’t forget to subscribe to my Website and my YouTube Channel “Electroniclinic”.

Related project:

Raspberry Pi HMI Project using PYQT5 Software tutorial

Watch Video Tutorial:



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

1 Comment

  1. Hi.

    I did follow your guide, but when i try to run the code, i get this error:

    %Run main.py
    Traceback (most recent call last):
    File “/home/pi/Desktop/Relay/main.py”, line 2, in
    from PyQt5.QtCore import pyqtSlot
    ModuleNotFoundError: No module named ‘PyQt5’

    Is there a module i need, that is not described in the guide?


Leave a Reply

%d bloggers like this: