Public cloud computing systems enable businesses to complement their data centers with worldwide servers that can scale processing capabilities up and down as required. In terms of value and security, hybrid public-private clouds are unparalleled.
However, real-time AI applications demand substantial local processing capacity, frequently in areas distant from centralized cloud servers. speedpak tracking is among the services including AI for the safety of your goods and parcels.
Moreover, some workloads demand low latency or data residency and must stay on-premises or specified locations.
That is why many businesses use edge computing to implement AI applications.
Instead of storing data in a centralized cloud, edge computing saves data locally in an edge device. Moreover, the gadget may function as a stand-alone network node without an internet connection.
Cloud and edge computing offer many advantages and application cases.
Cloud computing is a computing approach in which scalable and elastic IT-enabled capabilities are supplied as a service through the Internet.
Cloud computing's popularity is growing as a result of its many advantages. Cloud computing, for example, has the following benefits:
Edge computing is the process of physically bringing computational capacity closer to the source of data, which is generally an Internet of Things device or sensor. Edge computing, so named because of how computing power is delivered to the network's or device's edge, enables quicker data processing, higher bandwidth, and data sovereignty.
Edge computing lowers the need for huge volumes of data to travel between servers, the cloud, and devices or edge locations to be processed by processing data at the network's edge. It is especially relevant for current applications like data science and artificial intelligence.
Edge and cloud computing have unique advantages, and most businesses will utilize both. Here are some things to think about when deciding where to deploy certain workloads.
In contrast, cloud computing is ideal for non-time-sensitive data processing, but edge computing is ideal for real-time data processing.
Also, the former requires a dependable online connection, while the latter should encompass rural regions with little or no internet access.
Furthermore, cloud computing stores data in the cloud, but edge computing includes very sensitive data and tight data rules.
Medical robotics is one example of when edge computing is superior to cloud computing because surgeons want real-time data access. These systems include a significant amount of software running on the cloud.
Still, the sophisticated analytics and robotic controls increasingly used in operating rooms cannot tolerate latency, network stability difficulties, or bandwidth limits. In this case, edge computing provides the patient with life-saving advantages.
Convergence of cloud and edge is required for many enterprises. Organizations centralize when possible and disseminate when necessary.
Firms may benefit from the security and management of on-premises systems with hybrid cloud architecture. It also makes use of a service provider's public cloud resources.
For each firm, a hybrid cloud solution implies something different. It might imply training in the cloud and deploying at the edge, training in the data center and deploying at the edge using cloud management tools, or training at the edge and deploying in the cloud to centralize models for federated learning. There are several options to connect the cloud and the edge.
Though both the computing systems are equally important, each carries distinctive perks. As the world is moving toward the hybrid approach, understanding the right computing choice will ease your process. Our guide will assist in this regard.
The IoT is the interconnection of physical objects or devices with sensors and software accessing capabilities to communicate data or information over the internet.
To build an IoT network, we need an interface medium that can fetch, control, and communicate data between sender and receiver electronics devices or servers.
Espressif Systems created the ESP32 Wi-Fi chip series. The ESP32 module is equipped with a 32-bit Tensilica microcontroller, 2.4GHz Wi-Fi connectivity, an antenna, memory, and power management modules, and much more. All of these built-in features of this ESP32 module make it ideal for IoT applications.
Hello readers, I hope you all are doing great. In this tutorial, we will learn another application of ESP32 in the field of IoT (Internet of Things). We are using a PIR sensor to detect motion and an Email alert will be generated automatically whenever a motion is being detected.
Fig.1
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | ESP32 | Amazon | Buy Now |
The HCSR-501 sensor module is used with ESP32 to detect the motion. So whenever a motion is detected, the PIR sensor will generate a HIGH output signal which will act as an input to the ESP32 module. In the absence of motion, the output of the PIR sensor will remain LOW. If a HIGH input signal is generated from the PIR sensor module, the LED (either peripheral or inbuilt) will be turned ON and along with that, an Email will be generated to the receiver’s email address as per the program instructions.
Fig. 2 PIR Motion Sensor
PIR stands for Passive Infrared sensors. It detects heat energy in the surrounding environment using a pair of pyroelectric sensors. Both sensors are placed next to each other, and when motion is detected or the signal differential between the two sensors changes, the PIR motion sensor returns a LOW result (logic zero volts). It means that in the code, you must wait for the pin to go low. The desired function can be called when the pin goes low.
There are two potentiometers available in the HCSR-501 PIR motion sensor module. One of the potentiometers is to control the sensitivity to the IR radiations. Lower sensitivity indicates the presence of a moving leaf or a small mouse. The sensitivity can be changed depending on the installation location and project specifications.
The second potentiometer is to specify the duration for which the detection output should be active. It can be programmed to turn on for as few as a few seconds or as long as a few minutes.
PIR sensors are used in thermal sensing applications such as security and motion detection. They're commonly found in security alarms, motion detection alarms, and automatic lighting applications.
The simple mail transfer protocol (SMTP) is an internet standard for sending and receiving electronic mail (or email), with an SMTP server receiving emails from email clients.
SMTP is also used to establish server-to-server communication.
Gmail, Hotmail, Yahoo, and other email providers all have their own SMTP addresses and port numbers.
Fig. 3 SMTP
To send emails, the SMTP protocol, also known as the push protocol, is used, and IMAP, or Internet Message Access Protocol (or post office protocol or POP), is used to receive emails at the receiver end.
The SMTP protocol operates at the application layer of the TCP/IP protocol suite.
When the client wants to send emails, a TCP connection to the SMTP server is established, and emails are sent over the connection.
SMTP commands:
There are various email service providers available like, Gmail, Yahoo, Hotmail, Outlook etc. and each service provider have unique service parameters.
In this tutorial, we are using the Gmail or Google Mail service.
Gmail is the email service provided by Google and Gmail SMTP server is free to access and anyone can access this service, who has a Gmail account.
It is recommended to create a new email account for sending emails using ESP32 or ESP8266 modules.
If you are using your main (personal) email account (for sending emails) with ESP and by mistake something goes wrong in the ESP code or programming part, your email service provider can ban or disable your main (personal) email account.
In this tutorial we are using a Gmail account.
Follow the link to create a new Gmail account : https://accounts.google.com
Fig. 4 create new gmail account
To get access to this new Gmail account, you need to enable Allow less secure apps and this will make you able to send emails. The link is attached below:
https://myaccount.google.com/lesssecureapps?pli=1
Fig. 5 permission to less secure apps
Table 1
Fig. 6 ESP32 and HCSR-501 connections
We are using Arduino IDE to compile and upload code into ESP32 module. To know more about ESP32 basics, Arduino IDE and how to use it, follow our previous tutorial i.e., on ESP32 programming series. Link is given below:
https://www.theengineeringprojects.com/2021/11/introduction-to-esp32-programming-series.html
To enable the email service in ESP32 it is required to download the ESP-Mail-Client Library. This library makes the ESP32 able to send email over SMTP server.
Follow the steps to install the ESP-Mail-Client library:
https://github.com/mobizt/ESP-Mail-Client
Fig. 7 Adding ESP-Mail-Client Library
//To use send Email for Gmail to port 465 (SSL), less secure app option should be enabled. https://myaccount.google.com/lesssecureapps?pli=1
//----Add the header files
#include <WiFi.h>
#include <ESP_Mail_Client.h>
//-----define network credentials
#define WIFI_SSID "public"
#define WIFI_PASSWORD "ESP32@123"
//--add the Server address and port number with respect to a particular email service provider
#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT esp_mail_smtp_port_587 //port 465 is not available for Outlook.com
//----The log in credentials
#define AUTHOR_EMAIL "techeesp697@gmail.com"
#define AUTHOR_PASSWORD "Tech@ESP123"
//----The SMTP Session object used for Email sending
SMTPSession smtp;
//---Declare the message class
SMTP_Message message;
//---Callback function to get the Email sending status
void smtpCallback(SMTP_Status status);
const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n"
"-----END CERTIFICATE-----\n";
int inputPin = 4; // connect with pir sensor pin
int pir_output = 0; // variable to store the output of PIR output
void setup()
{
pinMode(inputPin, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
pir_output = digitalRead(inputPin);
Serial.println();
Serial.print("Connecting to AP");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(200);
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1
*
* Debug port can be changed via ESP_MAIL_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h
*/
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
/* Declare the session config data */
ESP_Mail_Session session;
/* Set the session config */
session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = "mydomain.net";
/* Set the NTP config time */
session.time.ntp_server = "pool.ntp.org,time.nist.gov";
session.time.gmt_offset = 3;
session.time.day_light_offset = 0;
/* Set the message headers */
message.sender.name = "ESP Mail";
message.sender.email = AUTHOR_EMAIL;
message.subject = "Email Alert on Motion detection";
message.addRecipient("Anonymous",
"replace this with receiver email adderss");
String textMsg = "Motion Detected!!!!!";
message.text.content = textMsg;
message.text.charSet = "us-ascii";
message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
/* Set the custom message header */
message.addHeader("Message-ID: <abcde.fghij@gmail.com>");
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
}
void loop()
{
if (pir_output == HIGH)
{
//----Start sending Email and close the session
if (!MailClient.sendMail(&smtp, &message))
Serial.println("Error sending Email, " + smtp.errorReason());
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("Motion detected!");
Serial.println("Email sent");
}
else {
digitalWrite(LED_BUILTIN, LOW);
Serial.println("No Motion detected!");
}
delay(1000);
ESP_MAIL_PRINTF("Free Heap: %d\n", MailClient.getFreeHeap());
//to clear sending result log
smtp.sendingResult.clear();
}
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status)
{
/* Print the current status */
Serial.println(status.info());
/* Print the sending result */
if (status.success())
{
Serial.println("----------------");
ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
ESP_MAIL_PRINTF("Message sent failled: %d\n", status.failedCount());
Serial.println("----------------\n");
struct tm dt;
for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
/* Get the result item */
SMTP_Result result = smtp.sendingResult.getItem(i);
time_t ts = (time_t)result.timestamp;
localtime_r(&ts, &dt);
ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
ESP_MAIL_PRINTF("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients);
ESP_MAIL_PRINTF("Subject: %s\n", result.subject);
}
Serial.println("----------------\n");
//You need to clear sending result as the memory usage will grow up as it keeps the status, timstamp and
//pointer to const char of recipients and subject that user assigned to the SMTP_Message object.
//Because of pointer to const char that stores instead of dynamic string, the subject and recipients value can be
//a garbage string (pointer points to undefind location) as SMTP_Message was declared as local variable or the value changed.
smtp.sendingResult.clear();
}
}
Note: The exact code cannot be used. As a result, before uploading the code, you must make some changes such as replacing the SSID and password with your network credentials, email address of sender and receiver, SMTP setting parameters for respective email service providers, and so on. We'll go over these details as well during the code description.
Fig. 8
Fig. 9
Fig. 10
Fig. 11
Fig. 12
Fig. 13
Fig. 14
Fig. 15
Fig. 16
Fig. 17 Variable for PIR sensor
Fig. 18
Fig. 19
Fig. 20
Fig. 21
Fig. 22
Fig. 23
Fig. 24
Fig. 25 ‘If motion detected’
Fig. 25 No motion detected
Fig. 26 Clear the email log
Fig. 27 select development board and COM port
Fig. 28 ESP32’s Inbuilt LED is turned ON when a motion is detected
Fig. 29 Serial monitor
Fig.30 received email on motion detection
This concludes the tutorial. We hope you found this of some help and also hope to see you soon with a new tutorial on ESP32.
Hi Friends! Hope you’re well today. In this post, I’ll walk you through What is Edge Computing?
Edge computing is the extension of cloud computing. Cloud computing is used for data storage, data management, and data processing. While Edge Computing does serve the same purpose with one difference: edge processing is carried out near the edge of the network which means data is processed near the location where it’s produced instead of relying on the remote location of the cloud server.
Confused?
Don’t be.
We’ll touch on this further in this article.
Curious to know more about what is edge computing, the difference between edge computing and cloud computing, benefits, and applications?
Keep reading.
Edge computing is the process where data is processed near or at the point where it’s produced. The word computing here is used for the data being processed. Simply put, Edge computing allows the data to be processed closer to the source of data (like computers, cell phones) rather than relying on the cloud with data centers. This process is used to reduce bandwidth and latency issues.
For instance, Surveillance cameras. When these cameras are required simultaneously to record a video, if you use cloud computing and run the feed through the cloud, it will increase its latency (latency is the time delay between actual data and processed data) and reduce the quality of the video.
This is where edge computing comes in handy. In this particular case, we can install a motion detector sensor that will sense the movement of the physical beings around the camera. This motion-sensing device will act as an edge device that is installed near the data source (camera). When live feed data is processed near the edge devices instead of the cloud or data centers, it would increase the video quality and practically reduce the latency to zero.
Cloud storage takes more time to process and store data, while edge computing can locally process data in less time. The market of edge computing is expected to grow from $3.5 billion to $43.4 billion by 2027, according to experts in Grand View Research. Many mobile network carriers are willing to apply edge computing into their 5G deployment to improve their data processing speed instead of picking the cloud server.
Normally in cloud computing, two components are used: the device and the cloud server. In edge computing an intermediate node is introduced between the device and the cloud server, this node is called an edge device.
How data was stored in data centers before edge computing stepped in? Yes, this is the main question to discuss before we explain how edge computing works.
Before edge computing, data was gathered from distributed locations. This data was then sent to the data center which could be an in-house facility or the public cloud. These data centers were used to process the stored data.
In edge computing that data processing is carried out near or at the point from where data originates. This is very useful for making real-time decisions that are time-sensitive. Like in the case of automatic cars interacting with each other.
Plus, less computing power is required in edge computing since we don’t need to push back all data to the data center. Like in the case of a motion-detecting sensor installed near the camera. In case we require a video of a particular instance, we need to pull out the entire information recorded inside the camera to reach that particular instant clip. However, when the motion sensor is installed near the camera that acts as an edge device, we only require that information where that sensor has detected the movement of any physical beings, and we can easily discard the rest of the information and we don’t need to store that information into the cloud server.
Know that edge data centers are not the only way to store and process data. Rather, edge computing involves the network of different technologies. Some IoT devices can become a part of this edge computing and can process data onboard and send that data to the smartphone or edge server to do the difficult calculations and efficiently handle the data processing.
An edge computing environment is developed using a network of data centers spread across the globe. The data centers in edge computing are different than the data centers at cloud computing. In former data centers store and process information locally and comes with the ability to replicate and transfer that information to other locations. While in the latter, data centers are located hundreds of thousands of miles away. The network latency issues and unpredictable pricing model of the cloud storage allow the organizations to prefer private data centers and edge locations over public cloud.
Google Cloud, Amazon Web Services, and Microsoft Azure are the best examples of cloud computing. They use cloud computing infrastructure which is developed to transfer the data from data source to one centralized location called data centers.
While facial recognition lock feature of the iPhone uses an edge computing model. If the data in this feature runs through cloud computing, it would take too much time to process data, while the edge computing device, which is the iPhone itself, in this case, does this processing within a few seconds and unlocks the mobile screen.
For massive data storage or for software or apps that don’t require real-time processing needs, cloud computing is the better solution and is commonly called the centralized approach. And if you require less storage with more real-time processing power that is carried out locally, edge computing is the answer and is called a decentralized approach where not a single person is making a decision, rather decision power is distributed across multiple individuals or teams.
Know that companies typically harness the power of both cloud computing and edge computing to develop advanced IoT frameworks. These two infrastructures are not opposite but are complementary for designing a modern framework.
Edge computing is a form of distributed computing infrastructure that is location-sensitive while IoT is a technology that can use edge computing to its advantage. Edge computing is a process that brings the processing data as near to an IoT device as possible.
Don’t confuse an edge device with an IoT device. The device is the physical device where data is stored and processed while the IoT device, on the other hand, is the device connected to the internet. It is nothing but the source of the data.
Edge computing is changing the way how data is stored and processed. This gives a more consistent and reliable experience at a significantly lower cost.
With new technology comes new security issues and edge computing is no different. From a security point of view, data at the edge computing can become vulnerable because of the involvement of local devices instead of the centralized cloud-based server. A few ricks of edge computing include:
Hackers always seek to steal, modify, corrupt, or delete data when it comes to edge computing. They strive to manipulate edge networks by injecting illegal hardware or software components inside the edge computing infrastructure. The common practice followed by these hackers is node replication where they inject malicious node into the edge network that comes with an identical ID number as assigned to the existing node. This way they can not only make other nodes illegitimate but also can rob sensitive data across the network.
Tampering of connected physical devices in edge networks is another malpractice carried out by potential hackers. Once they approach the physical devices they can extract sensitive cryptographic information, change node software and manipulate node circuits.
Routing attach is another security risk in edge computing. This approach can affect the way how data is transferred within the edge network. The routing information attacks can be categorized into four different types:
In wormholes attach, hackers can record packets at one location and tunnel them to another. In grey holes attach, they slowly and selectively delete the data packets within the network. In a hello food attack, they can introduce a malicious node that sends hello packets to other nodes, creating routing confusion within the network. While in black holes attach the outgoing and incoming packets are deleted which increases the latency.
Know that these practices can be avoided by establishing reliable routing protocols and incorporating effective cyber security practices within the network. It’s wise to put your trust in manufacturers who have proper policies in practice to guarantee the effectiveness of their edge computing solutions.
Edge computing comes in handy where quick data processing is required. With computing power near the data source, you can make better and quick real-time decisions.
A few edge computing examples include:
Predictive maintenance is another example where edge computing can play a key role. It helps to identify if the instrument needs maintenance before its major failure or total collapse. This saves both time and money which would otherwise require for entire instrument replacement.
Edge computing becomes common practice among many organizations since it provides more control over processed data.
This trend will continue to grow with time and it is expected by 2028 edge services will become widely available across the globe.
Wireless technologies such as WiFi 6 or 5G will work in favor of edge computing, giving chance to virtualization and other automation capabilities, at the same time making the wireless network more economical and flexible. Many carriers are now working to incorporate edge computing infrastructure into their 5G developments to provide fast real-time processing capabilities, particularly for connected cars, mobile devices, and automatic vehicles.
It is not about which one is better cloud computing or edge computing. It’s about the requirement. If you want data to be processed quickly near the source, you’ll adopt edge computing and if you want more data storage and data management, you will pick cloud computing.
The prime goal of edge computing is to reduce bandwidth and practically reduce the latency to zero. With the extension of real-time applications that require local computing and storage power, edge computing will continue to grow over time.
That’s all for today. Hope you find this article helpful. If you have any questions, you can reach out in the comment section below. I’d love to help you the best way I can. Thank you for reading this article.
Hi guys! Hope you’re well today. In this post today, I’ll cover What is Industrial IoT (Internet of Things?)
IIoT is now a talk of mainstream conversation. This term has blown up in the past couple of years. Before we move further to describe IIoT, it is evident that industries are no longer dependent on the traditional production processes that happened to be costly and guaranteed no optimal results. Now companies are willing to incorporate automation in manufacturing and production processes. Smart systems, no doubt, are dangerous for the traditional labor workforce, but on the other hand, they create more opportunities for the people equipped with the latest business trends.
Curious to know more about Industrial IoT, how does it work, the difference between IoT and IIoT, examples of IIoT, the impact of IIoT on jobs and workers, and the advantages of IIoT?
Keep reading.
The Industrial Internet of Things, also known as Industry 4.0 or Industrial Internet, is the use of smart connected machines, embedded sensors, and actuators mainly used to enhance the overall efficiency and productivity of manufacturing and production processes.
At its core, it is used to automate processes for the production of optimal products that build a strong connection with the customers and create new revenue streams. Automation leads to accuracy and better efficiency and removes the likelihood of error that is difficult to attain by a simple human workforce. The Industrial IoT is used across a range of industries including manufacturing, oil and gas, logistics, mining and metals, transportation, aviation, energy/utilities, and more.
The smart devices deployed in Industrial IoT are used to capture, store and analyze data in real-time and that data is delivered to the company leaders to make faster, smarter business decisions.
A typical Industrial IoT system contains:
For example, I own a PCB manufacturing industrial unit. And I want to know which types of PCBs are most popular among customers. With IoT technology I can:
The information gathered by the smart devices helped me to make better decisions on which items to stock up on which ultimately helped me save both time and money.
You’ll find a range of Industrial IoT examples. A few of them include:
When a certain industrial process or a piece of instrument is at the brink of total failure, preventive and proactive maintenance is applied to allow a quick fix to the problem beforehand. This saves both time and money which otherwise results in costly instrument replacement. Traditional methods are obsolete to identify the problem in advance since they often required access of labor to remote places to perform manual testing. With IIoT, you get an alert when the problem starts developing, which provides a valuable insight into whether the instrument requires overhauling or complete replacement.
Automating the process is the main takeaway of employing IoT in industrial settings. When industrial processes are automated and involve no human intervention, it removes the likelihood of errors and improves operational productivity, and reduces overall production costs.
Remote monitoring is challenging for the industries. With traditional methods, not only is it difficult but also inefficient and risky. The businesses require consistent monitoring of the instruments working out in the field. Manual testing is risky since the field environment is often occupied with lots of heat, vibration, or humidity. And the access of humans is not recommended to those places.
With the inception of digital technology, workforce transformation is on the rise. This new wave of technology, no doubt, removes the need for certain jobs but it also creates the possibility of generating new ones. According to the survey of business leaders in Accenture, this new digital era will create more jobs than it will eliminate.
The Industrial IoT provides scores of opportunities in optimization, automation, smart industry, intelligent decision making, industrial control, asset performance management, and in the sectors directly dealing with the customer’s behavior. They strive to create an environment tailored to the exact customer’s needs and demands so they keep coming back for what industries have to offer.
The IIoT makes the processes more efficient and improves productivity. It advocates for smart work, not hard work. Plus, the smart devices in IIoT removes the possibility of errors that may otherwise affect the production process if the traditional workforce is employed. Automation can gather data from hard-to-reach places, even reducing the risks to human lives. When a worker knows, they will get a notification on the smartphone about the tank leakage or the certain equipment that needs replacement, which means danger can be predicted in advance before it goes catastrophic.
This leads us to the conclusion: to survive in the ocean of digital transformation, it’s obligatory to equip yourself with the latest trends in engineering and information technology and liberate yourself from traditional research and development processes.
There are many advantages of industrial IoT and low operating cost tops the list. With IIoT, you no longer need the physical presence of a human that requires monthly wages, paid leaves, healthcare costs, and holidays. Moreover, it doesn’t require commissions, monthly bonuses, and pensions that are compulsory if you induct human employees into your industry. More advantages of IoT include:
Industries have been incorporating automation into their production and manufacturing processes.
And this trend will increase over time and you’ll witness more industries are stepping into the realm of automation.
Industries are committed to upgrading their system and instruments to keep up with the modern trends and to make a footing in disruptive technologies.
This process is, no doubt, more efficient, delivers better results, maintains product quality, and is more economical. Even though it requires a high initial cost, it doesn’t need a regular labor force, reducing the overall operating cost of the processes.
If you want to make your worth in the industry, it is wise to keep you updated with the latest industry trends to make sure you’re not left out in the traditional industry jobs.
That’s all for today. Hope you find this article helpful. If you have any questions regarding IIoT, you are most welcome to ask in the section below. I’d love to help you the best way I can. Thank you for reading this article.
Welcome to the fourth lesson of this python course. Our previous session taught us how to utilize the print function in python, so we have a firm grasp of the terminology and the functions themselves. In this lesson, we'll cover a few more Python terms, such as:
Also, we'll build a simple program to print out an imagined dog so that we may better grasp how these concepts are employed. So, let's get started now.
Programming is a lot like building a structure out of blocks. Even with just a few types of children's toy blocks and some time and imagination, you can build anything. Because we'll be utilizing these phrases all the time in programming, it's critical that you know what they mean and how to use them.
An alphabet, word, or other character collection is referred to as a "string." As one of the most fundamental data structures, it serves as a framework for manipulating data. An in-built string class called "str" is available in Python. After they've been produced, strings are "immutable," which means that they can't be rewritten. Because of the immutability of strings, we must generate new ones each time we want to represent newly computed values.
Quotes are used to denote a string. There are a variety of ways to accomplish this:
"Double quotes allow you to embed 'single' quotes in your string."
Triple quoted strings to make it possible to work with a set of multiple-line strings and include all of the whitespaces that accompany them.
The fact that a string cannot be changed results in an error if you try to do so. The adjustments require the creation of a new string.
Instead, use this method.
The built-in len() function can be used to determine the length of a string:
Strings can be sliced and indexed since they are a sequence of characters. A string's indexing starts at 0 and is based on each character in the string.
The initial character in the string is C, which is located at position 0 of the index. The final syllable is a period, which is the string's sixteenth character. When you want to access characters in the opposite direction, you can use -1 as an index. when it's strung together, Chocolate and cookie are separated by a whitespace, which has its own index, 9 in this example. Slicing is a good way to verify this.
For the same reason as for other sequential data types, you can read and manipulate Python strings using their associated index numbers. It is possible to slice an object using its index values in Python to select a specific element or a subset of elements. You don't have to write a loop expression to identify or access specific substrings in a string. Slicing does this for you automatically.
Suppose you were trying to find the cookie substring in the following string. What's the best way to go about it?
Range slicing is used in these situations. The range slicing syntax is as follows:
Alternatively, you might use a negative stop index:
In this case, when you slice a sentence without giving an end index, you get characters from the first index to its last. In the same way, slicing a string without a starting index indicates that you begin at the beginning and end at the end.
Additionally, the stride parameter can be accepted by string-slicing as a third argument, which specifies the number of characters to advance once the initial one is picked from the string. In the default configuration, stride has a value of 1.
stringnu = "1020304050"
print (stringnu [0:-2:2])
Striding allows you to reverse a string, which is a really cool feature. With a stride of -1, you can begin at the end of the string and move forward one character at a time. With a value of -2, you can start at the end and move two characters at the same time.
String operations such as slicing and range slicing are frequent. As simple as adding, string concatenation is also available.
Concatenating a string with another data type, on the other hand, will fail.
You attempted to concatenate an integer value with a string, which is not permitted. Integer addition or string concatenation is not understood implicitly by the interpreter. However, give this a try:
The reason for this is that you used concatenation after you turned the integer into a string.
A string can be repeated using the * method.
wordsig = 'hip '
line1 = wordsig * 2 + 'hurray! '
print (line1 * 3)
To manipulate strings, Python comes with several built-in methods and utility functions. It is possible to use these built-in techniques to replace substrings, to put some words in a paragraph in capital letters, and to locate the position of a string within another text.
Multiple string formatting options are available in Python. To better understand these formatting strings, let`s dive right in.
Python has a built-in modulo percent operation. The interpolation operator is the name given to it. There is a percent followed by the data type that must be prepared or transformed. This operation then replaces the word "percent datatype" with one or more components of that type:
Percent d is used for integers, whereas percent s is used for strings; you've seen both. Octal values can be converted to octal equivalents with this type of conversion, as can Hexadecimal values with this type, and Floating-Point Decimal Format with this type.
One of the built-in string classes is the formatter class. The format () method can be used to perform sophisticated variable substitutions and value formatting. Rewriting public methods such as format () and vformat () allows you to build your own string formatting techniques (). There are a number of methods that are designed to be replaced by subclasses, such as parse (), get field, get value, check unused arguments, format field, and convert field ().
Templates allow substitutions based on dollars rather than percentages. A major reason for template syntax creation in Python Version 2.4 was that, despite the strength of percent string formatting, errors are easy to make, because the forms that follow '%'are extremely restrictive. This is a common blunder when it comes to percent formatting: forgetting to include the e in percent (variable).
substitution () and safe_substitute() are two methods specified within templates (). You can use them in the following ways:
Safe substitution () is an advantage to employing a template, in addition to other advantages.
In Python 3, this is yet another way to format strings. A prefixed 'f' or 'F' string literal is known as a formatted string literal or f-string. Within curly brackets, you may include identifiers that will be utilized in your string.
What's the point of adding another string formatting option? well, this is because practicality and simplicity are appealing.
To demonstrate why f-strings are the best way to format strings in Python, check out the examples below.
Please note that the preceding code is only compatible with Python 3.6 and above. With f-strings, Python expressions can be used inside curly braces, which is a significant benefit of using them.
Syntax is the most important consideration here. For the most part, it boils down to the trade-off between simplicity and the amount of verbosity you're willing to sacrifice. People with a C programming background will find it easy to use the percent sign to format strings, for example. Using the format () function can be more verbose, but it provides a wider range of options.
While your application is running, you can utilize input routines to get data from the user. A key benefit of this approach is that it does not rely on preexisting values or file content to function. The syntax for the input function is as follows.
input([prompt])
Input functions will cause our application to pause. After the user inserts the text into the Python shell or command line, the application resumes.
input(message)
In order to prompt the user for text, you'll need to provide a message. It's important that a user understands what they need to do by reading this message. As a result, a user may wonder why the software isn't progressing. For example,
input ("Enter email address: ")
print ("Confirm it is your email address:")
In order to request an email address from a user, we've implemented the input () method. Messages in brackets are displayed on the same line where a user is expected to enter text in the command line.
Note that as soon as a user inputs data into the input () function, it is automatically converted to a string.
Using the fundamentals of strings that we've learned in this lesson; we'll construct a simple program that prints out an image of a dog.
Let's open up our favorite coding editor, Atom, and get started. Before looking at the solution, I advise you to give it a shot on your own.
Congratulations! You've made it this far. You have learned about string slicing, what strings are, and explored a variety of string-related processes. Many approaches to formatting strings have also been discussed. But don't forget that practice is the key to mastering any skill! I'll see you in the next tutorial.
Hello readers, we hope you all are doing great. Welcome to the 1st lecture of Section 4 in the ESP32 Programming Series. In this section, we will interface the ESP32 module with common Embedded modules(i.e. LCD, Keypad, RTC etc.).
In today's tutorial, we will interface ESP32 with a 16x2 LCD and will display data using both Data Mode and I2C Mode. LCD is the most commonly used embedded module in IoT Projects. It is used to display different types of data i.e. sensor readings, warning messages, notifications etc.
Before going forward, let's first have a look at what is LCD and How it works:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | ESP32 | Amazon | Buy Now |
LCD(Liquid Crystal Display) is a type of electronic display module that is used in a wide variety of applications and devices such as calculators, computers, mobile phones, TVs, etc. There are different types of LCDs available for commercial use. Today, we are going to use the most simple one i.e. 16x2 LCD, shown in the below figure:
This 16x2 LCD has 16 columns and 2 rows, so in total of 32 blocks to display characters. Each Block can display a single character at a time. We can display text in different styles on this LCD i.e. blinking, scrolling etc. Another variant of this LCD is 20x4 LCD and as the name suggests, it has 20 columns and 4 rows and so can display 80 characters at a time. The operating principle of both of these LCDs is quite similar. So, if you are working with a 20x4 LCD, you can still follow this tutorial.
Let's have a look at the LCD pinout:
Both 16x2 and 20x4 LCDs have 16 pins each, used to control 7 write on these LCDs. Among these 16 pins, we have:
LCD Pinout and its working is shown in the below table:
LCD Pinout |
||||
---|---|---|---|---|
Pin No. | Name | Working | ||
1 |
GND(Ground) |
Connected to Ground Terminal. |
||
2 |
Vcc(+5V) |
Connected to +5V. |
||
3 |
VE |
To Control the LCD Contrast. |
||
4 |
RS(Register Select) | If RS=0(GND), LCD operates in Data Mode and we can write characters on the LCD. |
||
If RS=1(+5V), LCD Command Mode gets activated and we can send commands to LCD i.e. erase, new line etc.. |
||||
5 |
R/W(Read & Write) | R/W=0(GND) enables the write operation on the LCD. (So, we normally keep this pin LOW, as we are interested in printing on the LCD). | ||
R/W=1(+5V) enables the read operation on the LCD. |
||||
6 |
EN(Enable) |
Enables the LCD to operate, so it should be kept HIGH. |
||
7 |
Data Pin 0 |
LCD has a total of 8 Data Pins(D0-D7) | ||
8 |
Data Pin 1 |
|||
9 |
Data Pin 2 |
|||
10 |
Data Pin 3 |
|||
11 |
Data Pin 4 |
|||
12 |
Data Pin 5 |
|||
13 |
Data Pin 6 |
|||
14 |
Data Pin 7 |
|||
15 |
LED+ |
Connected to +5V. Turn on the backlight LED. |
||
16 |
LED- |
Connected to GND. |
Now, let's interface the LCD with ESP32:
There are two methods to interface ESP32 with a 16x2 LCD:
In the Data Mode, we use the LCD Data Pins and send data serially, while in the I2C mode, we solder an I2C adapter with the LCD, which acts as a bridge and maps I2C data coming from the microcontroller to the Data Pins. Let's first interface ESP32 and LCD via Data Pins:
As we discussed earlier, LCD has 8 Data Pins used to communicate with the Microcontroller. There are two ways to send data from the Microcontroller to the LCD:
In complex projects, where you are dealing with multiple sensors & modules, its quite difficult to spare 8 Pins for LCD interfacing. So, normally 4-Pin method is preferred, which we are going to design next:
Here are the components required to interface LCD with ESP32:
Now, let's design the ESP32 LCD Circuit Diagram:
[Image]
As you can see in the above figure:
Here's our hardware setup for ESP32 LCD Interfacing:
[Image]
Now let's design the Programming Code to print a simple message on the LCD:
We are using Arduino IDE to compile and upload code in the ESP32 module. If you haven't installed it yet, please read How to Install ESP32 in Arduino IDE. Here's the code to print a message on the LCD:
#include
LiquidCrystal lcd(22,23,5,18,19,21);
void setup()
{
lcd.begin(16, 2);
lcd.clear();
// go to row 0 column 5, note that this is indexed at 0
lcd.setCursor(5,0);
lcd.print("ESP32");
// go to row 1 column 0, note that this is indexed at 0
lcd.setCursor(0,1);
lcd.print (" TheEnggProjects");
}
void loop()
{
}
#include
LiquidCrystal lcd(22,23,5,18,19,21);
In the Setup() Function:
lcd.begin(16, 2);
So, if you are using a 20x4 LCD, you should change its arguments to 20 and 4, as shown below:
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(5,0);
lcd.print("ESP32");
lcd.setCursor(0,1);
lcd.print (" TheEnggProjects");
As you can see, the LCD code is quite simple and I hope now you can easily print on the LCD. So, let's check the results:
Fig. 6
Sol. : Check the EN pin.
Fig. 7
This concludes the tutorial. We hope you found this of some help and also hope to see you soon with a new tutorial on ESP32.
Tech tools can make or break a business in this day and age, regardless of the industry or niche a venture is in. As such, it’s vital to source the best possible technologies that will help you make your organization the best it can be and the most likely to reach its goals. As you invest in technology, it pays to avoid some common mistakes.
Many entrepreneurs have a detailed business plan they created when they began or bought their business, but they fail to plan much for technology. It’s essential to have a vision and strategy for your technological needs so you don’t keep jumping from one system, app, or product to another with no clarity on why you need certain programs.
A lack of planning can add to your total costs, too, since you’re more likely to have to keep buying new software to try to find the right things to suit your needs, rather than understanding from the start what’s required. Consider the various areas of your business and what you need in each.
For example, think about your sales and marketing processes, HR and payroll requirements, finance and accounting needs, where you’re up to with strategic sourcing in 2022, customer service plans, and more. Where possible, invest in tech tools that can be used across different parts of your organization and that will integrate well, too.
With so many different tech products coming out all the time, it’s easy to be like a bowerbird and get distracted by shiny new objects in this field that seem fun and interesting. However, focusing on trends and the latest gear rather than what’s actually the best fit for your company and needs is a common mistake.
Going down this path will mean you likely end up spending a lot more money than you need to on technology and buying devices or programs that aren’t suited to your business or are simply irrelevant. Instead, refer back to your tech plan to see if new products will provide the solutions you’re after and, if not, appreciate what they offer but don’t bother buying them.
If you feel called to test a new offering, at least sign up for a free trial so you don’t have to outlay money on it. You can always cancel after the zero-cost introductory period if you can tell you really won’t use the software or that it doesn’t do enough for your needs.
Another common mistake many business owners and managers make is not creating a budget for technological items at the start of the calendar or financial year. When you have a budget in place, you stop and think twice before signing up for a subscription service when it releases or the latest gadget you hear other entrepreneurs talking about.
A set budget specifically for tech goods keeps you on track financially and keeps you and your team accountable. Keep in mind, too, that every new tool you buy needs setting up and learning in some way, which is time-consuming. When you adhere to a budget, you’re less likely to end up getting bogged down with too many things to wrap your head around.
Unfortunately, though, many people get so busy with general day-to-day tasks that they forget about this area or think it’s something they can consider later (a time that never really comes until the worst happens). If you want to protect your firm’s and customers’ data from prying eyes and stop hackers from charging you ransom or stealing money, you need to spend plenty of time and energy upgrading your company’s security processes.
Invest in quality, comprehensive security software and firewalls that protect devices and accounts. Ensure all computers and programs are kept updated at all times so there are fewer security gaps for hackers to take advantage of. Train your staff to be very careful about what links they click on and emails they open. They should choose solid passwords that can’t be easily guessed. Proper codes are at least eight characters in length, made up of a mixture of numbers, letters, and symbols, and changed every so often.
Other mistakes to avoid include rushing into purchases, neglecting free downloadable tools, and not testing systems enough before going live or otherwise implementing them. Be wary of considering price only when evaluating products, as customer support, security, scalability, and other factors also matter.
Technology can help us considerably to run our ventures but only when we invest in suitable options. Think about all these errors that others have made before you when buying tech tools so you can save yourself cash, headaches, and time.
The more you learn about Python, the more you may use it for your own purposes. Data analyst, application developer, or the ability to automate your work processes are all examples of jobs that can be automated.
This Python 3 tutorial will show you how to create a simple "Hello, World" program. Python's basic syntax and components include the following:
An IDE (Integrated Development Environment) is a software development tool. Integrated development environments (IDEs) include a variety of software development-specific tools. Examples of these instruments include:
There are many distinct programming languages supported by IDEs, as well as a wide range of additional functionality. Because of this, they can be very huge and take a long time to download and install. Using them correctly may necessitate additional training.
A function is a piece of code that serves a single purpose and can be reused multiple times. Functions provide for greater modularity and code reuse in your program. Functions have the benefit of being well-known by a variety of names. Functions, methods, subroutines, procedures, etc. are all referred to in different ways by different programming languages. Think about what we'll be talking about later in this session if you come across any of these terms.
Since you all learned Python by printing Hello, World! you might think that there is nothing new to learn about the Python Print function. As with any language, learning to use the Print function in Python or any other is like taking your first baby steps into a new world of programming. When studying a programming language, it's easy to get caught up in the more advanced concepts and lose sight of the simplicity and usefulness of basic functions.
Today's tutorial is all about Python's Print function; you'll learn about one of the most underappreciated functions.
For example, in Python3, parenthesis is required or else you'll get a syntax error as illustrated in the image below.
In Python3, print () is not a statement but a function, as demonstrated by the above output. First things first, let's see what the print () function returns.
Built-in functions and methods are returned by this method, which indicates that it is a Python function.
A new line or vertical space between the two outputs can be added by simply using the print () function without sending any arguments in.
The Command Palette, which is possibly Atom's most essential command, is shown to us on that welcome page. The command palette will appear if you press Ctrl+Shift+P while in an editor pane.
Packages from the Atom community are available to help you assemble and run programs. We'll be utilizing "script" to run our application in this example.
go to file>settings>install
Install script by searching for it in the search bar. It should appear under "Packages" in the Settings menu after installation. Please be aware that script does not support human input. The "apm" package manager can be used to install packages on Mac OS or Linux.
Go to File > Add Project Folder in atom and pick a directory to serve as the project's root directory.
In the folder, right-click the folder and select "New File," type "hello."py," and click "OK."
Now that you've made your adjustments, you can open the new file in the editor by clicking on it and then saving it.
Then, in the Print dialog box, type "hello, world!"
To execute the script, use CTRL+SHIFT+B. You may also use View > Toggle Command Palette and type Script: Run to execute a script.
You can also use your terminal to run the python file by navigating to the file directory containing your hello.py file and running this command
python hello.py
File editing is rather simple. You can use your mouse and keyboard to navigate and edit the content of the page. A separate editing mode or key commands are not provided. Take a look at the list of Atom packages if you prefer editors that have modes or more advanced key commands. Many programs are available that mimic popular design elements.
You may save a file by selecting File > Save from the menu bar or by pressing Ctrl+S. There are two ways to save the current material in your editor: by selecting File > Save As or using Ctrl+Shift+S. Finally, you can save all open files in Atom by selecting File > Save All.
The majority of your time will be spent working on projects with numerous files, not just single files. Take advantage of the File > Open Folder menu option and select an appropriate folder from the drop-down menu. File > Add Project Folder or hitting Ctrl+Shift+A can also be used to add other directories to your current Atom window.
The command line utility, atom, allows you to open unlimited number of directories by supplying their paths to it. The command atom./hopes./dreams, for example, can be used to simultaneously open the hopes and dreams directories.
An automated Tree View will be displayed on the side of Atom if one or more directories are open.
When you use the Tree View, it's a breeze to see the whole file and directory structure of your project. You can open, rename, and delete files, as well as create new ones, using this window.
In order to toggle between concealing and showing it, use Ctrl+, use the tree-view: toggle command from the Menu Bar, or press Alt+ to bring focus to it. The A, M, and Delete keys can be used to add, move, or remove files and directories in the Tree view. It's also possible to access these choices by right-clicking on a file or folder in the Tree view, as well as copying or pasting its path into your clipboard.
Unlike functional programming languages that used a single long list of instructions, Python uses code modules that may be switched out. Cpython is the default Python implementation. It is the most often used Python implementation.
Python does not translate its code into a form that hardware can understand, known as machine code. As a result, it turns it into byte code. Python does have a compiler, but it doesn't compile to a machine language. CPUs are unable to decode the byte code (.pyc or.pyo). We'll run the bytes through Python's virtual machine interpreter.
To convert a script into an executable, the Python source code follows these steps:
First, the python compiler reads a python source code or instruction from the command line. It ensures proper formatting of the instruction by inspecting the grammar of each line. The translation is immediately interrupted if an error is found, and an error message is presented.
Assuming there are no errors and the Python source code or instructions are properly formatted, the compiler proceeds to translate them into a form known as "Byte code," which is an intermediate language.
The Python interpreter is invoked by executing bytes of code in the Python Virtual Machine (PVM). PVM is a Python virtual machine (PVM) that turns bytecode into machine code. If there is a problem with the interpretation, the conversion will be interrupted and an error notice will be displayed.
Congratulations for completing your first program. Beginners who want to learn Python can benefit greatly from this guide. To get the most out of this lesson, you may want to play around with the Print function a little more and discover more features that were not covered.
The printed circuit board is a type of plastic where electrical and electronic components lie, laminated and fixed. In modern days, there has been increasing in the complexity of electronic components and devices and this has also led to high demand for more complex PCBs that can make this achievable. This exclusive board that has been introduced in the market includes HDI, rigid-flex, Aluminium clad, buried and blind or even a blend of all the listed types.
There is a list of so many PCB types that a designer can choose for any type of electronic project ranging from single layer PCB to other complex types like the multilayered PCBs. In general, the simplest type of PCB contains copper tracks and interconnection between the elements and components on one side of the board. These types of boards are classified as single-sided boards or one-layer side of boards. However, there are other types of boards that are complicated and will require complex methods to do their designs. These boards are probably double-layered or even multilayered.
Multilayered boards are such complex boards that will require advanced technology for their manufacturing. This is where HDI boards come into play. HDI stands for High-Density Interconnect Boards. When addressing high density interconnect boards, we are focused on higher wiring density, the smaller vias, the thinner spaces and the higher pad density that accompany this type of board. This type of board has a lot of advantages over the typical circuit boards.
HDI PCBs use vias and laser-drilled microvias to connect components between different multilayers. The microvias are the most preferred to offer the connections because they are much smaller and very effective when it comes to space utilization.
This can be either buried or blind vias which have a very important function of connecting circuits between different layers of the printed circuit board and in this case across three or more circuit layers as shown in the figure below;
They can either be blind or buried but they are conical in shape. They are vert small and they still do the function of connecting circuits between layers of the PCB as shown in the figure below.
When we have vias of a certain PCB layer connected without overlapping, they actually form a staggered via as shown in the figure below.
They are conical in shape but they are connected without overlapping hence forming a staggering structure as shown in the figure below;
This are vias that are connected to the pad where component is lied. They are very common in HDI PCBs.
There are mainly two structures that aren used in the manufacturing of the HDI;
This is the basic structure of the high-density interconnect PCB and uses the manual mechanical drilling as well as the laser drilling.
This is an advanced technology that is used in the manufacturing of the HDI PCBs. The method is highly preserved for the high-level interconnection use since we can make connection of any of the two layers of the PCB without any form of restrictions. This means that any-layer connection has a lot of flexibility when it comes to doing these connections.
This technology has found great importance in the smartphone and the tablet manufacturing. Apart from that, they have become of great use in the laptops and desktop computers. The following id the great benefits of the HDI PCBs;
These types of boards have found many areas of use in the modern world of technology. Let us have a look at a few areas where the high-density interconnect boards are used;
Due to the smaller size of the HDI boars, medical designers have found great interest in this type of board. The medicals equipment are compatible with HDI because they are very small and can fit into them for example in implants and also in the imaging equipment. The equipment play a very significant role in the treatment of the ailments and therefore smaller chips that require less intervention have to be used. Let us take an example of a heart pacemaker that is implanted in the heart to regulate the speed of the heart bit. The pacemaker should be very tiny and therefore the HDI has provided boards that can solve the size of the pacemaker issue. another good example is the colonoscopy which is passed through the colon of a human to carry out the colon examination. It is evident through research that so many people avoid the colonoscopy examination due to the painful experience but the availability of the HDI technology has drastically reduced the size of the camera and improved the visual quality of the same camera which has made the colonoscopy process less painful hence triggering the increased number of people searching for the service.
Military use strategic equipment such as the missile and some other defense communication devices. This equipment utilizes the HDI technology in their boards since it is the only efficient available method. there have been greater changes in the aerospace technology and HDI have always provide the need solution. Communication devices such as the wireless pones and trackers are becoming very tiny in size and this is due to the involvement of too many tiny layers of the HDI boards.
The car and other automotive manufacturers are falling in love with the HDI boards simply because with this type of board you are assured of greater discoveries and innovations. This boards allows the saving of more space in the vehicle and also have an increased performance of the same vehicle. To be specific, Tesla uses the HDI technology to run the electric car system where it helps in extending the battery life of the system. Other driver assistants such as cameras, tables etc fit on the dashboard without much problems.
Let us make a comparison of todays digital devices like the smartphone with what we had 10 years ago and you will make note that there is a very big improvement in size, thickness and weight. This has been made possible by the use of the HDI boards in this area. Thinner and more compatible smartwatches are also a product of the HDI boards.
Hi friends, today we are going to explore mathematical computations in ladder logic. Like in any programing language you should find logic and mathematic computations, here in PLC programming you often need to process the input data that is collected from reading analog devices like temperature, level, flow et cetera. Then you need to run some calculations on this data to derive some other variables for deciding to run or stop some device or even to determine analog output to output to analog device i.e. valve or actuators. In the following sections, we are going to explore the mathematical functions and their input operators and outputs as well. Then we will show how to utilize such functions in ladder logic with simple examples and as usual enjoy practicing them thanks to the PLC simulator.
You may find some minor changes in the set of mathematical functions from brand to brand of PLC controllers. However, you will find in most of them are common in every controller. For example, you will find the basic mathematical functions are available like addition, subtraction, multiplication, division, negation by applying two’s complement, modulus, increment and decrement, absolute, maximum, and minimum. In addition, trigonometric functions like sine, cosine, tangent are included. Let us go over these functions and explore their operators and output and how they can be utilized in PLC ladder logic programming.
For all these functions, they have input operators and one or more returned outputs. Most of them have two inputs like addition, subtraction, multiplication, and division. While some have only one input parameter like negating function, maximum, and minimum. And they all have only one input. Table 1 lists all these functions and their input operators and output.
Table 1: the functions’ input parameters and outputs
It is very important to be familiar with the type of data you are trying to process using these mathematical functions. So, simply you just need to know that the smallest size data type is a bool data type which is true or false or “1” or “0” and it uses only one single bit. Then character “char” or byte data type which is 8 bits while word data type is formed of 2 bytes or 16 bits and that is the word size in PLC. Also, there are doubleword data types that occupy 4 bytes or 32 bits. Moving to mathematical data types there are integer data types that can be stored in one word and the double integer “DINT” which can be stored in two words or 32 bit for holding numbers up to = 4294967296 for unsigned integers and half of that value for signed integers. Also, there is a real data type for holding numbers with floating-point. It needs 2 words or 32 bits and for a long real LREAL data type extends to 4 words or 64 bits.
In the TIA portal for siemens, there are two ways to add mathematical functions in a rung of ladder logic program. Figure 1 shows the first method which uses an empty box in the block interface and then you can select the function and its inputs and outputs parameters.
Fig. 1: Adding an empty box for including math functions
Figure 2 shows a list of functions from which you can choose the mathematical function you want to use.
Fig. 2: A list of math functions to select
Figure 3 shows another way to add a mathematical function by going to the basic instructions and then going over the math functions on the most right part of the window as shown and selecting the function you want to use.
Fig. 3: The second way to add a mathematical function
Figure 4 shows how to define the input and output parameters of the used mathematical function. For example, in figure two input parameters are defined as the function’s input operators which are literal number five and variable “x” which is predefined as an integer in the variable declaration section in the middle top section. Also, the Variable sum is defined as an integer. So the add function will add X to 5 and assign the result to variable Sum.
Fig. 4: Defining function parameters and outputs
In this example, we are going to show how mathematical functions can be used in a ladder logic program and also show the simulation results. As in fig. 5, we design a simple calculator that uses the mathematical functions and each function can be triggered by a switch on a contact that is connected in series to the enable line of the function box.
Figure 5 shows an additional example in ladder logic. It shows two operators A and B of integer data types. The variable A is located at address MW2 and variable B is located at address MW4 while the result is stored in variable RES which is located at address MW6. All of these variables are of type integer and size one word or 32 bits. The figure show simulation results on the PLC simulator and shows the RES variable holds summation of A and B.
Fig. 5: Addition function example
Figure 6 shows a subtraction example in ladder logic. It shows two operators A and B of integer data types. The variable A is located at address MW2 and variable B is located at address MW4 while the result is stored in variable RES which is located at address MW6. All of these variables are of type integer and size one word or 32 bits. The figure shows simulation results before triggering the subtraction function on the PLC simulator. So, the RES variable holds zero before enabling the function.
Fig. 6: Subtraction function example not triggered
Figure 7 shows the simulation results after enabling the subtraction by switch or the “SUB” command contact. The Res variable now reflects the results of subtraction.
Fig. 7: Subtraction function example in ladder logic programming
Similarly, Fig. 8 shows an example for performing the multiplication process. First, the “MUL” is selected and two input operators of multiplications are given and output. The simulation result shows the RES variable holds the result of multiplication of the input operators.
Fig. 8: Multiplication function example in ladder logic programming
Similarly, Fig. 9 shows an example for performing the Division process. The “DIV” is selected as an instruction to be executed and two input operators of division are provided and output. The simulation result shows the RES variable holds the result of the division of the input operators.
Fig. 9: Division function example after triggering
Similarly, Fig. 10 shows an example for performing the MOD function process. The MOD function determines the remainder of the division process, in this example we are dividing 25 by 10 which gives 2, and the remainder of 5. “MOD” function firstly is selected as an instruction to be executed and two input operators of MOD function are provided and output. The simulation result shows the RES variable holds the remainder of the division of the input operators.
Fig. 10: MOD function example in ladder logic programming
Now, one may ask how I need to do the calculation in form of an equation that has many processes? This is a very smart question! Many programming tools support this, fortunately. For example, in Siemens, there is a function called “calculate” which can take two inputs and perform mathematical equations on these two variables and return the result in an output variable as shown in Fig. 11. It shows the function which is called “CALCULATE” and it has two inputs “IN1” and “IN2” and one output “OUT”. I triggered the help to show you an example that states OUT can be determined from the equation in inputs and also shows all functions that can be used including logic and mathematical functions. So we can use this function, in general, to act like any mathematical or logical function separately or by combining two or more functions in one equation.
Fig. 11: Using equations in ladder logic
As you can see in the given example in fig. 12, the output variable can be determined based on multiplying the summation and subtraction of the input parameters as an equation. The result of the program is validated with a calculator.
Fig. 12: Using equations in ladder logic
There is another way to perform combine many mathematical functions as shown in fig. 13. As you can notice, the output variable “out” can be determined by multiplying the summation of input variables “in1” and “in2” by “in1”.
Fig. 13: Combination mathematical function in ladder logic
Negate function is one example of a single operator function in ladder logic programming. it reverses the sign of the input variable. For instance, fig. 14 shows an example of converting the sign of input variables “in1” to show the negative value reflected in the result in “res”.
Fig. 14: Single operator mathematical function in ladder logic programming
Figure 15 shows an example of getting the absolute of variable “RES” and saving it in variable “b”.
Fig. 15: Absolute function in ladder logic
Getting minimum and maximum is one of the most frequently used in the mathematical operation. Figure 16 shows an example for getting a minimum of two input variables “in1” and “in2” while fig. 17 shows an instance of getting the maximum of two input variables as well.
Fig. 16: Getting a minimum of two input variables in ladder logic programming
Fig. 17: Getting a maximum of two input variables in ladder logic programming
One of the most commonly used functions is incrementing and decrementing one variable. For example, the counter variable all the time gets incremented and decremented through the logic of the program. Figure 18 shows an example for decrementing and incrementing an input variable. First, the initial value of the variable was 15, and then after incrementing it. The variable became 6 and then by applying decrementing operation it return to 5. It is very crucial to notice that, the user variable in increment and decrement operation works as input and output at the same time. Therefore, you can see in the increment and decrement blocks, it is defined as input-output “input”.
Fig. 18: Increment and decrement operation in ladder logic
Now, let us use one of the very useful functions to secure a variable at specific limits. Figure 19 shows an example of limiting the value of one variable “in” to be sited between the specified minimum and maximum values. In that very example, the input variable has had a value of 5 and because it exceeds the set limit of maximum it is set to 4 which is the maximum allowed value to the variable thanks to the limit function.
Fig. 19: limiting variable in ladder logic programming
Also, trigonometric functions like sine and cosine and other related functions can be executed in ladder logic. Figure 20 shows one example of how to use a sine function in ladder logic. The first rung in the example shows how to convert the degree into rad thanks to mathematical functions multiply and division. Ultimately, the sin function block is used to determine the sine of the given angle in rad.
Fig. 20: Triogonometrical function in ladder logic programming
I am so happy that you be that patient to reach these points of tutorial and you know got familiar with most of the mathematical functions and how to use them flexibly through your program. The next round will go with the comparison operators and more deeply in mathematical logic flow using operators such as >,<,>=,<=, and ==. So please be ready for our next session of that ladder logic tutorial.