PLC Chapter 2
PLC Chapter 2
Wokwi is an online simulation platform primarily used for designing and prototyping electronic
circuits. It allows users to create, test, and debug circuits using various components like
Arduino, ESP32, sensors, and LEDs without the need for physical hardware. This is especially
useful for students, hobbyists, and developers working on embedded systems and IoT projects.
Wokwi is a powerful tool for learning and experimenting with electronics without the cost and
complexity of physical hardware. The working of Wokwi involves several key steps, from creating a
Blynk is a popular IoT (Internet of Things) platform that enables users to control hardware
remotely, visualize sensor data, store it, and create sophisticated automation systems. Blynk
20
Cloud is the cloud infrastructure of the platform, acting as a bridge between hardware devices
(like ESP8266, ESP32, Arduino, etc.) and a mobile app or web dashboard, allowing users to
1. Blynk App (iOS & Android): A mobile app where users create the user interface to
2. Blynk Server (Blynk Cloud): The server that handles the communication between the
devices and the mobile app. Blynk Cloud is the free, hosted version of the server.
3. Blynk Libraries: These libraries allow your hardware (like Arduino or ESP8266) to
consists of microcontroller boards (e.g., Arduino Uno, Nano, Mega) that can read inputs (such
as light, temperature, or button presses) and control outputs (such as LEDs, motors, or displays)
based on the programming loaded onto them. The main advantage of Arduino is its simplicity
21
and flexibility, allowing hobbyists, students, and professionals to create various interactive
A breadboard is a reusable platform used for constructing electronic circuits without the need
for soldering. It allows you to quickly and easily build temporary prototypes or experiment
with circuits by inserting components such as resistors, capacitors, LEDs, or integrated circuits
(ICs) into the breadboard’s holes. Breadboards are extremely useful for prototyping because
they allow components to be connected and tested in a flexible way. Once the design works, the
circuit board).
22
2.4.1. Advantages of a Breadboard:
No Soldering Required: Circuits can be built and modified without any permanent
connections.
Fig:-2.4 (Breadboard)
This image shows how various components, like resistors, LEDs, and wires, can be connected on a
Espressif Systems. It is popular for its integrated Wi-Fi and Bluetooth functionalities, making
it ideal for IoT (Internet of Things) projects and wireless communication applications. The
ESP32 is highly versatile and has more advanced features than its predecessor, the ESP8266.
23
It's commonly used in projects that need connectivity, like smart home devices, wireless
RAM), which is useful for memory-heavy applications like audio processing or image
recognition.
alike.
Wi-Fi and Bluetooth: It has built-in dual-mode wireless capabilities, which eliminates
battery-powered devices.
Rich Libraries and Community Support: There are extensive resources, libraries, and
Learning Curve: For beginners, it may have a steeper learning curve than simpler
Limited GPIO Pins: In some applications, the number of available GPIO pins may be
insufficient.
An LED is a semiconductor device that emits light when an electric current passes through it.
It's a type of diode, meaning it allows current to flow in only one direction, which is why it has
Fig:-2.6 (LED)
25
When a suitable voltage is applied across the leads of an LED, electrons recombine with holes
within the semiconductor, releasing energy in the form of photons (light). The color of the light
Lighting: LED bulbs are used in homes, vehicles, and flashlights for energy-efficient
lighting.
2.7. Wires:
Wires are used to connect components in an electronic circuit, allowing electricity to flow
between them. They come in different colors, thicknesses, and types (solid core, stranded core,
etc.).
Fig.2.7 (Wires)
Solid Core Wires: These are single, solid strands of wire. They are stiff and hold their
26
Stranded Wires: Made up of multiple thin strands of wire twisted together. They are
more flexible and durable than solid-core wires, ideal for applications where the wire
Jumper Wires: These are short wires with connectors on both ends, commonly used for
Raspberry Pi.
A USB cable is commonly used to connect devices like microcontrollers (Arduino, ESP32,
USB-A to Micro-USB: Commonly used with development boards like Arduino Nano,
USB-A to USB-B: Used with larger Arduino boards like the Arduino Uno and Mega.
USB-A to USB-C: Newer standard, used in some modern development boards and
phones.
27
2.9. What is a Push Button?
A push button is a simple switch mechanism used to control a circuit. When pressed, it either
completes or interrupts the flow of current, allowing an electronic device or circuit to perform
an action. Push buttons are widely used in everyday electronics like doorbells, calculators, and
1. Momentary Push Button: The most common type. It only completes the circuit while
Normally Open (NO): The circuit is open (no current flows) when the button is not
pressed. Pressing the button closes the circuit, allowing current to flow.
Normally Closed (NC): The circuit is closed (current flows) when the button is not
pressed. Pressing the button opens the circuit, stopping the flow of current.
2. Latching Push Button: Also known as a toggle or lock switch. Once pressed, it stays
in the "on" state until pressed again to return to the "off" state.
28
2.10. What is the HC-SR04 Ultrasonic Distance Sensor?
The HC-SR04 is a popular ultrasonic distance sensor used to measure distances between the
sensor and an object. It works by emitting ultrasonic sound waves and measuring the time it
takes for the sound to bounce back after hitting an object. This time is then used to calculate the
distance between the sensor and the object. It is widely used in applications like obstacle
avoidance in robots, level detection, and proximity sensing in various DIY and commercial
projects.
2. Receiver (Echo Pin): Receives the reflected sound waves (echo) and calculates the time
29
Easy to Use: Simple interface, with only four pins and straightforward communication
with microcontrollers.
Good Range: Can measure distances between 2 cm and 4 meters with reasonable
accuracy.
Non-contact: Measures distance without requiring physical contact with the object.
Operating Voltage DC 5V
Operating Current 15mA
Operating Frequency 40KHz
Max Range 4m
Min Range 2cm
Ranging Accuracy 3mm
Measuring Angle 15 degree
Trigger Input Signal 10µS TTL pulse
Dimension 45 x 20 x 15mm
using a low-voltage or low-current signal. It allows one circuit to control another circuit,
typically isolating the two. This makes relays useful in many applications where controlling
30
Fig. 2.11 (Relay)
movable contact (armature), and one or more stationary contacts. When a small current flows
through the coil, it generates a magnetic field that moves the armature, which either makes or
breaks a connection with the stationary contacts, thus controlling a separate high-power circuit.
Electrical Isolation: Relays provide electrical isolation between the control circuit (low
voltage) and the load (high voltage), preventing damage to sensitive components.
Control Large Loads: Relays can control high-power devices like motors, heaters, and
Durability: Electromechanical relays can handle large current loads and are durable in
high-power applications.
31
2.11.3. Disadvantages of Relays:
Mechanical Wear: Electromechanical relays have moving parts that can wear out over
Noise: Relays can produce audible clicking sounds when switching, which might be
A 16x2 LCD (Liquid Crystal Display) is a type of display module that can show 16 characters
per line and has a total of 2 lines. It is commonly used in various electronic projects to provide
a visual interface for displaying text, numbers, and other data. The 16x2 LCD is widely used
32
2.12.1. Working Principle:
The 16x2 LCD works by controlling the state of liquid crystals between two polarizing filters.
When an electric current is applied to the liquid crystals, they change orientation, allowing light
to pass through or be blocked, thus creating visible characters or graphics on the display.
libraries.
Low Power Consumption: Operates at low voltages, making it suitable for battery-
powered applications.
2.13. Libraries:-
libraries are packages of code that can be used to add function nality to a project.
Custom libraries can be created in Wokwi by including the library name, "@wokwi:", and the
unique identifier of the library's zip file on Wokwi's servers. Custom libraries can be copied to
These are small packages of code written by others to perform a specific function. For example,
a library can add support for a specific sensor. Arduino libraries can be found in three places:
the IDE installation folder, the core folder, and the libraries folder in the sketchbook.
33
2.13.3. Blynk ESP-32 wifi:
The Blynk library for ESP32 in Wokwi allows you to connect your ESP32 board to the Blynk
Cloud, which is an IoT platform that lets you control hardware remotely:
2.13.4. Blynk_Async_ESP_BT_WF:-
communication between the ESP32, Blynk, and either WiFi or Bluetooth, allowing you to build
smart IoT applications. If you're using Wokwi (an online simulator for electronics).
7. Non-Blocking Measurement
8. Unit Conversion
1. Robotics
2. Security Systems
4. Parking Sensors
34
5. Proximity Alerts
The LiquidCrystal library is a widely used library in Arduino and ESP-based projects that
allows for easy interfacing with LCD displays that use the controller or compatible models.
These LCDs are commonly available in sizes like 16x2 (16 characters by 2 lines) or 20x4, and
The LiquidCrystal library comes pre-installed with the Arduino IDE, so there’s no
VSS → Ground
VDD → 5V (power)
35
2. User Interfaces
4. Status Indicators
5. Game Displays
communicate seamlessly with the Blynk Cloud or Blynk IoT platform by using an
NCP module. This allows the microcontroller to send and receive data to/from the
2.13.11. ESP_DoubleResetDetectorlibrary:-
projects, allowing you to detect when the microcontroller has been reset twice within a short
36
period of time. This feature is often used to trigger specific actions, such as entering
ESP32 or ESP8266 has been reset twice within a defined time interval (usually a few
seconds).
When a double reset is detected, the device can switch to a special mode, like entering
In many IoT projects, you might want to allow users to change the Wi-Fi credentials or
ESP_DoubleResetDetector, you can make the device detect a double reset and enter a
configuration mode where the user can update settings via a web portal or similar
interface.
This is particularly useful for headless devices or those that are difficult to physically
Another common use of the library is to trigger an OTA update process. After
detecting a double reset, the device can switch into an OTA mode where it downloads
37
new firmware updates from a remote server.
This allows developers to update the firmware of ESP-based devices remotely without
erasing the stored configuration and resetting the device to its default state after
Additionally, the library can be used to put the device into a "safe mode" to
troubleshoot issues or prevent the device from running problematic code during
startup.
The library works by storing the first reset's timestamp in non-volatile memory
(NVS) or EEPROM, and if a second reset occurs within the defined time window, it is
This storage ensures that the detection mechanism works even if the device loses
PLC timer is a instruction to control and operate the device for a specific duration. With
the timer, we can perform any specific operations for a particular time span. The timer
instruction is used to provide programming logic and to decide when to turn on or off the
38
circuit. It has both normally open (NO) or normally closed (NC) contact.
For the ladder diagram programming, the classification of the PLC programming timer is-
An on-delay timer (TON) is a programming instruction which use to start momentary pulses
for a set period of time. Let’s see, a simple construction of the AB PLC On-delay timer
programming instruction.
A off-delay (TOF) timer is a PLC programming instruction which use to switch off the output
39
or system after a certain amount of time.
See here, a basic structure of AB PLC Off delay timer programming instruction.
The main function of the RTO is used to hold or store the set (accumulated) time.
RTO is used in the case when there is a change in the rung state, power loss, or any
We have seen three timers provide the time delay functions to control the PLC operations.
Timer Address
Preset Value
40
Accumulated value
Each timer instruction has three very useful status bits. These bits are…
An instruction which is useful for sequential counting as digital signal pulse or the number of
digits.
The basic internal counter circuit requires auxiliary power supply (APS), an input-output
terminal, a counter circuit, and a digital display. We can see PLC counter internal structure as
41
Fig.2.16 (Block Diagram of Counter)
Basically, PLC counter operates into four modes such as up mode, down mode, bidirectional
mode, and the quadrature mode. Counters in PLC are classified into three main different parts.
1. Up Counter:-
Up counter counts from zero to the preset value. Basically, it increases the pulse or number. Up
counter is known as the ‘CTU’ or ‘CNT’ or ‘CC’ or ‘CTR’. Up counter function block
diagram:
42
Fig.2.17 (Up counter)
2. Down Counter:-
The down counter counts from the preset value to zero. It decreases the pulse or number. Down
The down counter counts from target value to the initial value by decreasing it. This initial
3. Up-Down Counter:-
The up-down counter counts the value from zero to the preset value or from the preset value to
43
zero. In other words, this counter can be act as down counter or up counter.
Up-down counter is known as ‘CTUD’. For the bidirectional and quadrature operation
mode, the up-down counter is selected depending on the status (high or low) of the specified
The output coil of an AND gate turns on when both inputs are on.
44
2.17 Ladder logic of OR Gate:-
In ladder logic, an OR function is represented by two normal contacts placed on top of each
other.
45
2.19 ladder diagram of XNOR Gate:-
46
Fig.2.25 (Ladder Logic of NOT Gate)
RS Logix Micro programming software allows you to cost-effectively create, modify and
monitor your applications programs by leveraging this powerful, yet easier-to- use design
package.
47
Fig.2.27 (RS Logix Micro Starter Lite)
RSLogix 500 is mostly used to support older automation systems that are controlled by SLC
or MicroLogix PLCs. RSLogix Emulate 500 emulates all the programmable logic controllers
in the AllenBradley SLC 500 family, including the MicroLogix 1000, 1200, and 1500
controllers
48
2.23.2. RS LINUX CLASSIC LITE:-
The primary purpose of Rslinx Classic and Enterprise Software is to provide connectivity
Scilab is an open source software similar to MATLAB used for numerical computations, data
analysis, and simulation. Below is an overview of key commands and function commonly used
in Scilab:
1. Basic Operations
Addition: +
Subtraction: -
Multiplication: *
Division: /
Power: ^
Assignment: =
Matrix multiplication: A * B
49
Zeros matrix: zeros(m, n)
3. Functions
Defining a function:
scilab
Copy code
function y = f(x)
y = x^2 + 3*x + 2;
endfunction
4. Control Structures
If-else:
scilab
Copy code
if x > 0 then
disp("Positive");
else
disp("Negative or Zero");
end
For loop:
50
scilab
Copy code
for i = 1:10
disp(i);
end
While loop:
scilab
Copy code
while condition
// your code
End
5. Plotting
2D plot: plot(x, y)
3D plot: plot3d(x, y, z)
6. Polynomials
7. Basic Functions
Exponential: exp(x)
51
Logarithm: log(x) (natural), log10(x) (base 10)
Round: round(x)
8. File Operations
9. Statistical Functions
Mean: mean(x)
Variance: variance(x)
12. Utilities
52
Clear workspace: clear
This is just a subset of the commands available in Scilab. The software offers a wide range of
functions for different areas such as optimization, signal processing, control systems, and much
more. You can explore more commands and features by referring to the Scilab documentation.
53