Skip to content

AbdulkarimGit-Tech/Raspberry-Pi-PLC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi

Hi, I'm Abdul Karim 👋
Welcom to CODESYS PLC using Raspberry pi 5

PLC Programmer | HMI & SCADA Developer | Control Panel Designer | Siemens & CODESYS Expert
This Repository is to build DIY PLC for LOW Cost using Raspberry PI and CODESYS for real-world automation solutions using modern industrial technologies


💼 Table of Contents : Please click to expand

Hardwares List
  • Raspberry Pi 5 (4GB or 8GB)
  • microSD card (16GB or higher, Class 10) #Installed PI OS 64 / If not see Installation
  • Power supply (USB-C, 5V 3A+)
  • Ethernet cable (for stable communication)
  • Breadboard
  • Jumper wires
  • Optional: GPIO-connected 12V push buttons, LED indicators (via relay/level shifter)
  • Optional: Raspberry pi TCobbler if using breadboard
  • Optional: High voltage appliances (AC/DC)
  • Optional: Power Adapter (0-36V DC)

Softwares Download and Install

Installation

    

             Raspberry pi Setup     
                              Install Raspberry PI OS

Install Raspberry PI OS 64 into Raspberry PI 5 (RAM more than 4GB)

- Rasoberry PI 5
- Micro-SD Card (atleast 16GB) 
- USB SD Card Reader 
- Open PI Imager
  - Flash “Raspberry Pi OS 64-bit (Lite or Desktop)” to SD card and config additional settings before FLASH.
Open PI Imager
  PI_Imager
Choose Device
  PI_Choose_Device
Choose OS
  PI_Choose_OS
Select Storage
  PI_Choose_Storage
Edit Settings
  PI_Choose_Next
Configure OS
  PI_OS_Config
Enable SSH and Save
  PI_Enable_SSH
OS Writing
  PI_OS_Writing
OS Verifying
  PI_OS_Verifying

Once finished Remove SD Card and insert into pi 5

PUTTY Setup

    

                              PUTTY Setup
  Once PI OS 64/32 Installed on raspberry pi 5
    Open PUTTY and Login with raspberrypi.local -> Click OK
      - Login as: Your pi ID
      - Password: Your pi password 
      # Note password not visible
PUTTY Login
  PI_OS_Writing
PUTTY pi Login
  PI_OS_Verifying
    # After successfully logged in get your pi IP
    
      - ifconfig or hostname -I (Keep the IP of your PI similar like Ex: 192.168.xxx.xx)
      - sudo apt update && sudo apt upgrade -y   

To Enable VNC Check below Code snippet

sudo raspi-config

         VNC_Config

Click Down Arrow key on keyboad to select "Interface Options"
- Use Right Arrow key on keyboard to select "SELECT" Click Enter

  VNC


- Use Down Arrow key on keyboard to select VNC
- Use Right Arrow key to Select the option click enter and enter again

  VNC_Config


- Use Right Arrow key to Select "YES" and Enter

  VNC_Enable
--> To finsh the setup use Right arrow key 2 times select Finish and click Enter on keyboard

To apply the changes Reboot pi: "sudo reboot"

Once Completed

Open VNC

    

                              Connect Raspberry pi with VNC
  Open VNC on Windows
  Login with raspberrypi.local -> Click Enter
    - User: Your pi ID
    - Password: Your pi password
    - Open Terminal
    - Update Pi (sudo apt update && sudo apt upgrade -y)
    - sudo shutdown now (To Shutdown Pi)

VNC_Connect
VNC_pi_Terminal

Raspberry Pi is ready to use

    

             Install CODESYS Control Runtime on Raspberry pi
             
                                                            Install CODESYS Control Runtime from Windows

Install CODESYS Control Runtime from Windows

- Open CODESYS Development System on Windows
- From CODESYS Development System:
  
  - Go to Tools → Package Manager / Codesys Installer → Browse search below listed 4 package and install
    - ✅ CODESYS Control for Raspberry Pi SL
    - ✅ CODESYS Edge Gateway for Linux
    - ✅ CODESYS Control SL Extension Package
    - ✅ CODESYS SL Deploy Tool
    
- Boot your Pi with the OS
- Ensure it's connected to the same network as your PC

- On your Windows PC, open CODESYS Development System

- Go to Tools → Device Installer
- Install Raspberry Pi runtime:
- Menu: Tools → Update Raspberry Pi
- Enter your Pi IP address
- Provide username (pi) and password (raspberry or your custom)

It will install runtime over SSH

 - In CODESYS → Go to:
 - Tools → CODESYS Control for Raspberry Pi → Update Raspberry Pi
 - Enter your Raspberry Pi’s IP address
 - Choose:
  - Login: pi ( Your ID or default)
  - Password: raspberry (default; change if needed)
  - Select the Demo License (free, 2-hour runtime)
  - Wait for the runtime to install — success message will appear.

Activate License (optional)

- You can run a demo version (2 hours runtime).
- For production: Buy license from CODESYS Store and activate via License Manager.
                                                            Manual Installation from Raspberry Pi

Manual Installation from Raspberry Pi

Choose anyone ( I'm using VNC, you can use anyone process is same)
  
  -  External Monitor
  -  VNC Software laptop
  -  PUTTY

- Download or Locate "CODESYS Control for Raspberry Pi SL.deb" file on Windows folder
  Ex: C:\Program Files\CODESYS 3.5.21.0\CODESYS\CODESYS Control for Raspberry PI\Delivery\raspberry

- Open WinSCP, login with:
- Host: Your Pi’s ip or rapberrypi.local
- User: Your ID
- Password: Your password
- ✅ Drag & drop the .deb file to any folder (Ex: Downloads).

WinSCP Login
        
WinSCP_Login


Locate ".deb" file into your PC, Drag & Drop into pi Folder "Downloads"
         WinSCp_Copy


After Successfully Copied ".deb" file into pi folder
         WinSCP_Copied


Follow Below Step to Install and Run CODESYS Runtime Successfully

    Open PuTTY / VNC:
      - Enter ip of your Raspberry Pi
      - Login:
        - Username: Your ID
        - Password: Your password

    # PI Comand line (Update pi if needed "sudo apt update && sudo apt upgrade -y")
    - Locate The copied file .deb (Use below command)
    
        > ls (Pi folders)

        > cd Downloads (Copied file folder: you can "cd" where you have copied the ".deb" file)
        
        > ls (You will see .deb file Ex: codesyscontrol_raspberry_4.15.0.0_all.deb)
        
        > sudo dpkg -i [codesyscontrol_raspberry_4.15.0.0_all.deb] ( [] Rename with yours file name)

        > sudo systemctl status codesyscontrol (Check PLC Status Active or Dead)

        > cd (Come back to Starting section)

        > sudo systemctl start codesyscontrol (manual Start PLC Runtime)

        > sudo systemctl status codesyscontrol (#it will show Active)

        > sudo systemctl stop codesyscontrol (#it will stop PLC)

My PLC already Running so i Turned it Off then Turned it On

VNC_PI_PLC

Congrats you have successfully installed CODESYS Runtime into your pi 5


PLC Project creation
             
             Create a New PLC Project
             

Create a New PLC Project

  Go to: File → New Project → Standard Project
  Select device:
    CODESYS Control for Raspberry Pi 64 SL (64 bit)
    Choose programming language: Ladder Diagram (LD), ST, etc.

Project Creation: Go to: File → New Project → Standard Project
        
WinSCP_Login


Select the Device :
If no Hardware : WIN v3 64
If using pi 64 : pi 64 SL

        
WinSCp_Copy


Choose the logic lagnuage: I'm using "LD"
        
WinSCP_Copied


Programming Environment
        
Left side Device's/ POU's/ Modules | Middle LD logic page | Right side LD logic Tools | Upper side Menu  
      
WinSCP_Copied

             Setup PLC Development Environment without Raspberry pi
             

Setup PLC Development Environment without Raspberry pi

  - If no hardware select Simulation 
  - Click login -> Click Start
  - If have hardware no need to select Simulation

After Writing Logic Go to : File → Save → Generate Code (F11) to Compile
Down side you can see if there is any Error or Not

        
WinSCP_Login


After Compilation Go to : Online → Click Simulation → Click Login
        
WinSCp_Copy


You'll see Application in Stop Mode To Run the Code : Ciick on ▶ Play button
        
WinSCP_Copied


You'll see Application in Run Mode

        
WinSCP_Copied


To Change the I/O's : click on → Prepfered value it will show TRUE / FALSE : Click Ctrl + F7 to change the Input state
        
WinSCP_Copied


You can see the Output Change :
Output LED Turned ON

        
WinSCP_Copied


Again click on → Prepfered value it will show TRUE / FALSE : Click Ctrl + F7 to change the Input state
        
WinSCP_Copied


You can see the Output Change :
Output LED Turned OFF

        
WinSCP_Copied

             Setup PLC Development Environment for Raspberry pi
             

Setup PLC Development Environment for Raspberry pi

Go to: PLC PRG(PRG): Write down your PLC code -> Save it -> Click Generate code to compile

- Add devices:
  - GPIO (Digital Input/Output)
  - Modbus, Ethernet/IP, etc. (if needed)
  - Map GPIOs (I/O Configuration)
  - Under “Device → Raspberry Pi GPIOs”

Write your PLC code → Click Generate code to compile and Save
        
PI_PLC


Go to GPIOs → GPIO Parameters → Double click to Asign GPIO as INPUT or OUTPUT
 

      
GPIO_Parameter

      
GPIO_Parameter_IO


GPIO IO Maping → Double click on variable → Click Application → PLC PRG → Click the Ladder Logic I/Os and OK
# Note : Asign Digital Input & Output Seperately

        
GPIO_IO_maping       
GPIO_IO_maping


Right click on Application → Add Object → Visualization click Active and OK
        
HMI


Go to Visualization → Drag and Drop icons → Double Click on variable → Click 3 dots → Application → PLC PRG → Click the Ladder Logic I/Os and OK
Do it for all HMI icons

        
HMI_Setup


Go to deploy Control → Click → Scan → click on Pi IP → Give User name and Password → Click Connect :
It will show connected (pi connected to CODESYS)

        
Deploy_Control       
PI_Connected_CODESYS


Go to Device → Scan Network → Click raspberrypi and OK
        
Device_Network       
Device_Network_Connected


Go to Taskber → Right click on Drop Down → Right Click on .64 and Start PLC
        
Start_PLC


Go to Online : → It will ask for CODESYS login ID and Password → Enter → PLC will be in STOP Mode → Ciick on ▶ Play button → PLC will be in RUN mode
        
Compile_LD       
RUN_LD       
RUN_LD

Your Raspberry Pi is now a fully running PLC using CODESYS!


📁 Featured Projects

Project Description Tech Stack
Raspberry Pi 5 Relay Control PLC automation with Raspberrypi 5 and Codesys Runtime basic relay control, using push button and LED feedback CODESYS, Pi 5, LD

Bill of Materials (BOM) Example

Item Description Qty
Raspberry Pi 5 (4GB) Main controller 1
microSD (128GB) Storage 1
USB-C PSU (5V 3A) Pi Official Power supply 1
GPIO TCobbler Board Easy I/O access 1
12V Relay Module (16 Channel) For output control 1
12V LED indicators For output test 2–4
3.3V Push Buttons For input 2–4
12V power supply Relay & LED power 1
Ethernet cable / WiFi Communication 1
Bread Board, Jumper wires For Connection 1-10

▶️ Watch the video

Hardware Circuit
 

      
Hardware Circuit


Hardware Wiring
 

      
PI_PLC_Wiring


Hardware Connection

Connector Connected
Raspberry pi VCC5vRelay Channel5v
Raspberry pi GNDGNDRelay ChannelGND
Raspberry pi GPIO23Relay ChannelIN 7
Raspberry pi GPIO24Relay ChannelIN 6
Raspberry pi GPIO3.3v4x4 PB MatrixR 1
Raspberry pi GPIO174x4 PB MatrixC 1
Raspberry pi GPIO184x4 PB MatrixC 2
Raspberry pi GPIO224x4 PB MatrixC 3
Raspberry pi GPIO274x4 PB MatrixC 4
Relay Channel VCC12v12v Power SupplyVCC
Relay Channel GNDGND12v Power SupplyGND
Relay Channel D7NOConnected to Green LED +ve12v
Relay Channel D7COMConnected to 12v Power VCC + D6 COM12v
Relay Channel D6NOConnected to Red LED +ve12v
Relay Channel D6COMConnected to 12v Power VCC + D7 COM12v
12v Green LEDGNDConnected to 12v Power GND + D6 COM12v
12v Red LEDGNDConnected to 12v Power GND + D6 COM12v

PLC Ladder Logic ex:

      
PLC Ladder Logic


#NOTE: I have used Active LOW Relay Channel (Activate on LOW signal) and Raspberry PI 5 Output is Active High to avoid logic error, i have inverted my Active HIGH GPIO OUT Logic to LOW in my Code


Code Snipit

🔌 Tech Stack

PLC & HMI

CODESYS HMI

Programming Languages

Ladder Logic Structured Text FBD Raspberry Pi

Electrical Design

FreeCAD Procreate QElectroTech Fritzing

DevOps & Cloud Tools

GitHub Raspberry Pi Modbus


🌐 Connect with Me

LinkedIn
email


💡 GitHub Repositories

  • Upcoming – Upcoming Project Repositories

☕ Support My Work

PayPal


License

License: MIT

Releases

No releases published

Packages

No packages published