Help writing plc code for a system with 4 loadcells, 1 junction box, 1 motor

thewalkerist

Member
Join Date
May 2021
Location
Izmir
Posts
178
i am new to these things. I have no intention of using this in a commercial way whatsoever. I wanted to write a small plc programme for myself. We have a farm you see and i wanted to put stuff in to the bags without having to put it on the scale and putting more stuff into it to see if it fills up or not. I have designed a small system for myself.

i planned to use 4 loadcells and 1 junction box. With the junction box i've gotten rid of the need to connect all of the loadcells to the plc :D. I wanted to use a motor to pour stuff in when the loadcells values are lower than i expected.

i will buy a plc and a HMI soon but i am trying to figure out how will the coding work and what i need to do in order to connect my junction box to my plc.

I would really like the help.
 
First of all, are you connecting the 4 loadcells in parallel, I assume so, this is common practice for weighing, what sort of weights are you going to be measuring, this is reasonably important as to regards the loadcells for example it is common to use 500kg loadcells x 4 for a weight of 500kg of weight, this allows for over strain (i.e. drop loads) & the weight of the weigh platform, loadcells on their own will not interface into most PLC's directly, unless they have 0-10v 4-20ma etc. output so I assume you are going to use a loadcell amplifier, (4-20ma output directly you could not use them in parallel).
Really need to know what the load cells type are and how you intend to use them.
As for the code it will depend on the PLC you use, but assuming the loadcells are converted to a current or voltage output (or even communication) then you will need an analogue input card or possibly a built in analogue (available on some PLC's). or in the case of some communication protocol a coms card or spare port.
As for the code it is pretty simple assuming you are not using a variable speed drive.
Analogue value will be in either a raw value for example 4-20ma (0-500kg) could be 0-4000 raw digital value. this will then need to be scaled either in the set up of the card or by some maths in the PLC code. so for example dividing the raw by 8 would give you 0-500kg simple maths i.e. 500kg = 4000 raw, so 4000 div by 500 = 8.
You then do a compare of the scaled value with a set point entered by the operator & when equal or greater than stop the motor.
There are some other stages for example zero of the scales. this is often done on the loadcell amplifier to remove the offset of the weigh platform but could be done in the PLC.
Certainly more information is required before anyone could advise on actual code.
i.e.
Loadcells
Loadcell amplifier/controller (including the possible output i.e. 4-20ma 0-10v etc.)
PLC type & possibly HMI type
Description of the operation (however, this is probably what you use as the description of how you would code the logic).
This is how I see it working.
Pre- weigh: Operator enters the required weight
Stage 1: Operator presses start, the PLC will take a snapshot of the current weight & use this as the offset i.e. tare weight for example bag on weigher weighs 10kg so on the press of start the PLC subtracts this from the actual weight from the loadcells, thus giving you a zero reading.
Stage 2: the motor will start & product is added to the bag.
Stage 3: The added weight is constantly checked & when it reaches the set point (may use an offset i.e. in-flight so that the motor is stopped just before actual required weight).
I have done similar on many systems & would probably use Mitsubishi PLC's & HMI but that's just my preference.
 
OK i am sorry i kinda left it vague. I will try to explain right now.

so there will be 4 loadcells working for the same process(i thought 2 tons is right because i would usually require 1tons for my bags and motor and stainless steel parts i believe will make 500-600kg and according to the %70 rule of the loadcells i have to leave some free space on loadcells to make it more efficient.) for example this one looks fine https://www.esit.com.tr/en/load_cells/ssb__load_cell/urun/174

These 4 loadcells will be connected and act as the same one with a junction box. For example this will be one i believe https://www.esit.com.tr/en/indicators_and_control_devices/j_box_load_cell_connection_box/urun/338

Now i believe a loadcell transmitter or loadcell module will be required to change the values to analog values. output would be probably 4-20mA but that can change i have no exact idea about it rn (I could not find an example for this sorry).

I never bought any plcs before but i've watched some tutorials about the tia-portal and i believe siemens would be my beginning point and after i learned it from tia-portal i can amplify it to other plcs and their respective programmes.

And for the operation you were basicly right.

Pre-weigh: same but there will be a small adjustment. Calibration. i've seen some weighers with nothing on them giving a value and that kinda bothers me but i believe this can be solved with a simple move command in the plc. For example if loadcells show 4994grams we can round it to 5000.(still dont know how to do it but i can imagine a solution will not be that hard for there.)
Stage 1: same
Stage 2: same
Stage 3: same but that calibration method will be used here aswell. After the setpoint is reached i want it to re-calibrate itself to show me the 0 value again.

Currently i am mostly curious about the plc programming. i've downloaded tia-portal and now i am trying to simulate without any loadcells whatsoever just to see how to code it. How can i code it, what language should i need to use(LAD would be my go to but i have no idea which one is more useful). As you can see my biggest issue here is with programming. I can handle mechanic stuff very well, i was always a motorhead but this new programming stuff is weird and scary for me. I would love it if you can help me with the code .
 
Most loadcell amplifiers will have zero & span settings here is one I found but no idea of the specs
https://www.ato.com/load-cell-trans...and output short circuit protection functions.
Once the calibration is done i.e. set the zero with no weight on scales, adjust for 4-20ma, add load & adjust for 20ma for full load or some other value (you could add perhaps half load and adjust to 12 ma i.e. 20ma - 4ma =16 that is zero to full scale divide by 2 plus 4ma for zero so at half load you should get 12ma.
Siemens is a good system, however, I have not used the later hardware, I was a Siemens approved system builder some years ago on S5 & S7300/400 but it has changed a little since then, I believe there are standard scaling functions you call Not sure but when a block is called you set the parameters (maybe this is now set on the card most are going that way now) the parameters will be the PIW word of the raw analogue, the zero & span of the raw data & the expected scaled output zero & span i.e. 0-500kg
The one thing I always did was tare the empty scales, this was done in the PLC code as any slight changes i.e. temperature or even the bag being placed before being filled. so for example a bag is put on the scales so on press of a button providing the scales are reading less than +- say 10kg then you snapshot the gross weight and use this to subtract from the actual this is a sort of tare so then you get the actual weight of the product.
although I do not have TIA I will try to post some logic you could probably follow, however, there are a number of good coders here that could help you in Siemens
 
I will eagerly wait for your help mister. Thank you oh so much. :) . Maybe you can post the logic on your respective platform and i tell me the difference in tia portal and that? maybe i can follow with that?
 
See attached. This is a simple quick off the cuff to show you how you could control the batch weighing, it is just an idea and although this is not Siemens I think the functions are similar.
This is a no frills code & you will decide your own way to code it, the screenshots of the HMI are pretty crude but it was only used for testing.
You will notice rather than use bits to step through the sequence I have used a sequence word i.e. numbers, doing it this way it is easy to add extra steps (note: I increment them 10 at a time, this is so I can add extra steps), it is also useful if on a given operation you need to step back to a previous sequence.
The way this crude code works:
The operator places a bag on table presses the Start button on the HMI if the process is idle i.e. seq = 0 then it moves 10 into the seq. word, here it checks if the weigh table is within acceptable limits i.e. not more or less than +-2.5kg of zero (you can pick any value to allow for bag & any small error).
If it is greater then it steps onto 15, this sets an alarm banner on the screen to inform the operator it cannot tare the weight (the reason for the tare is because no matter how much you calibrate temperature changes, a film of water on the weigh platform etc. will mean it may not be exactly zero).
Once the error has been cleared, the operator presses return, this allows the operator to re-start. if the weight is within tare limits it tares the weigh table variable and starts the motor to fill the bag, when the weight reaches set point minus the in-flight, the motor stops, the weight is then stored in last batch variable & the sequence and last tare are set to zero, this makes the sequence idle & the actual scale weight is then the actual gross weight i.e. the weight of the scales plus the bag plus the product, this was why I stored the net weight for operator, you could put these net weights into a shift register so as to display a batch of bags as a history.
As I said, you can add features you require i.e. operator to confirm bag filled etc. I have used Data memories for the variables but I assume you will use a Datablock and configure it for variables i.e. integers, reals (floats) etc.
Ignore the logic in the block called sim, this was just to simulate it.

Batch complete.png Weight Running.png Weight HMI.png
 

Attachments

  • Batch Weigh logic.pdf
    92.8 KB · Views: 41
Oh wow. What a committed help :D. Really thank you for going to all this trouble to help me. But i had trouble understanding some parts of your logic.

My first problem was wrapping my head around the sequence_word values. Did you have to put it like 0,10,15,20,30,40 or can i change them and make them something like first step, second step etc.

My second problem is Lin_Scale blocks. I didnt get the memo behind them at all. What does Lin_Scale actually stand for? And why did we have to create those 8 steps of logic? What are those values (i.e. in_max,in_min,var_in,lin_grad,lin_con,lin_scale,out_min,out_max) actually stand for? I am really sorry i really am a boomer when it comes to these things. I know that these steps cleared the way for Analog Scale(lin_scale) but i am really confuzzled about that. Do i have to do exact same as the Last page?



My third and probably biggest problem is how does all of these codes actually gets sent to the cables? how will i make the connection between for example the motor and the code Fill_Motor. The conditions are met, yes we have now in 3rd sequence but now how does that go to the actual motor and start the filling process?

BTW i would really like to thank you for helping me again. You are unlike any person i've met so far. Everywhere i've searched on and everyone i talked to kinda said "meh, just figure it out" and than gave no actual pointers but you are something different ill say. I mean if you want i can even consider paying you for tutoring me :D
 
Last edited:
The sequence is just think about what you need to do for example
Process is idle i.e. the sequence variable is zero
Step 1: Operator presses the start button (or you may call it the Batch start).
This puts a value i.e. 10 into the sequence variable, the next bit of logic compares the sequence variable against 10 and if it equals (True) then you do a particular operation, i.e. check the gross weight of the weigh pan and depend on the result either move a value of 20 into the seq. variable to bypass the error reporting or put in 15 to do the error. when this is done.
Example:
Step 1: (0) its in idle mode, sequence variable is 0, operator presses button this puts 10 into seq. variable,
Step 2: (10) if equal to 10 then check the gross weight of weigher is not too far out, if it is then put 15 into seq. var or if within limits put 20 into seq. var.

Step 3 (15) alarm warn operator of weigh pan error operator corrects error & presses return button, this puts 0 into seq. var ready to start again.
Step 4 (20) Tare off the gross weight of the weigh pan so we only measure net addition, move 30 into seq. var.
Step 5 (30) Here we do two things we turn on the motor so the motor will run when the seq. variable equals 30 we also do another compare for 30 to check when the net weight reaches the required, when it does the logic puts 40 into the seq. var, therefore the motor turns off,
Step 6 (40), Here the weight is stored for the operator to check it is ok and also removes the tare so the scales show the correct gross weight i.e. the original offset the bag and the product, as this is done in one scan it also sets the Seq. var back to zero ready for the next start.
The linear scale block is just a standard function in most PLC's you select it from a list (it may be called something else in Siemens) you then put the variables on the pins i.e. the raw data from the analogue card probably called PIW (peripheral input word) example is PIW128 onto the input, the in min & in max are the raw dat limits you would expect from 4-20ma i.e. 0-32767, this will depend on the type of card PLC analogues vary so you will need to read the documentation on the card.
The out min & out max are the engineering units for example the loadcells go from 0 to 500.0 kg (4-20ma) the block the scales the raw data into the kg units as this is a real number could have a resolution of perhaps 10gram.
The codes do not get sent to the cables as such a plc consists of a bunch of inputs for example I0.0 to I 0.7 and I 1.0 to I 1.7 (16 inputs) the outputs could be Q2.0 to Q2.7 and Q3.0 to Q3.7 so these are either contacts used in the program or output coils ------| |----- is a input -----( )---- is an output. but these symbols can be real inputs/outputs or internal relays for control.
Use google & type in PLC connections then select images & you will see loads of drawings of possible connections.
If you could post exactly the PLC you are going to use and the analogue card unless it has one already built in I could possibly work out some of the connections.
 
Last edited:
@walkerist:

Lin_Scale Block

Lin_Scale is an abbreviation for Linear Scale. The idea is that the load cell and its transducer sends out an electrical signal depending on the weight on the load cell. For example, it may send out

  • 4mA when the weight is 0t (minimum weight)
  • 20mA when the weight is 2t (maximum weight)
  • And the electrical signal behaves in a linear fashion between weights of 0t and 2t
    • E.g. the signal is 12mA (signal half-scale = (4mA+20mA)/2) at 1t (weight half-scale = (0t+2t)/2).
Note: those are only example values; your scale will behave similarly - linearly - even if the numbers are different.

That 4-20mA signal is converted to an integral digital number (DN), also called (raw) counts, across the PLC analog input. As @parky noted, you will have to configure and wire the physical side of the analog input per the PLC user manual(s). On the digital "side" of the input i.e. inside the PLC, the analog input value available to the PLC program will be the raw counts value, typically something like

  • 0 counts when the electrical signal is 4mA and the weight is 0t
  • 32767 counts when the electrical signal is 20mA and the weight is 2t
  • And the counts value behaves in a linear fashion between signals of 4mA and 20mA and between weights of 0t and 2t
    • E.g. the counts value is 16383 (counts half-scale = (0count+32767count)/2) when the signal is at 12mA (half-scale) and the weight is at 1t (half-scale).
The "Linear" descriptor of the Lin_Scale Block refers to the line that represents this relationship in a plot:

Scaling.png


PLCs cannot interpret plots, but the equation of that lineis

Code:
([B][COLOR=blue]Var_In [/COLOR][/B]- In_Min)     ([COLOR=Red][B]Lin_Scale[/B][/COLOR] - Out_Min)
-----------------  =  --------------------
(In_Max - In_Min)     (Out_Max   - Out_Min)
The Lin_Scale Block solves for the weight, Lin_Scale, in that equation each time the analog input value, Var_In (0-32767counts) is measured.

Those quantities are the inputs and output of the Lin_Scale block.

  • Var_In = the raw count integer measurement of the analog input; this varies with the amount of material on the scale
  • In_Min = 0count, the count value of the analog input at minimum weight of 0t (Out_min); this is a constant set via calibration.
  • In_Max = 32767count, the count value at maximum weight of 2t (Out_Max); this is a constant set via calibration.
  • Out_Min = 0t, the weight value at 0count (In_Min); this is a constant set via calibration.
  • Out_max = 2t, the weight value at 32767count (In_Max); this is a constant set via calibration.
  • Lin_Scale = the output weight value corresponding to the Var_In input measurement; this will vary linearly with the Var_In input value.
The actual system may be different: the max values may be 16383count and 500kg; the electrical signal may be 0-10V instead of 4-20mA; after a calibration, you may determine that non-zero values are best values for In_Min and/or Out_Min. However, the general approach described here applies. If you look at your load cell and PLC documentation, there will be a specification of the linearity of the load cell and of the PLC analog input, usually as a percentage of full range; that will tell you the accuracy you can expect from assuming (modeling) the behavior as linear via the Lin_Scale Block.

Background

All computer programs are models of something in the real world. The first design choice for a program is selecting the level of fidelity: which parts of the world are modeled, and how accurately are any of those parts of the world modeled? All other design choices flow from that fidelity choice.

PLCs are special-purpose computers that continuously do three actions:

  • read external inputs;
  • make calculations of what outputs should be based on a model comprising
    • the inputs,
    • any state information about the model stored internal to the PLC,
    • and the outputs;
  • write external outputs.
That description is an extreme oversimplification of what PLCs do, but it is adequate for almost all tasks, and certainly for the present task*.

Below is a sketch of the entire process. Every line in that image that is crossed by some sort of information is an interface you will need to understand and configure. Fortunately, each can be handled mostly independently of the others, so you can break down the entire problem into a series of smaller problems and only have to consider a small part of the process at any one time.


plc_weigh_filler.png

* The weakest point of that description is the word continuously: it would be better stated that PLCs continuously repeat those three actions: some PLCs do them synchronously i.e. in a set sequence e.g. read, calculate, write, read, calculate, write, etc.; some PLCs do them asynchronously, so reading of inputs could happen while, and interrupt, calculating. However, because all three action happen so quickly, the PLC can be thought of as a continuous device for all but the most demanding applications (e.g. motion control).

Sidebar

@parky you probably already noticed: Rung 4 does not need the [ANDE>] OR [ANDE<] logic in the middle, because if the previous Rung 3 has not set the step to 20, then one of those ANDE>/ANDE< paths must already be true. So Rung 4 can be just two instructions: [EQ Sequence_word 10] and [MOV 15 Sequence_word].

I'm not intending to be snarky here, rather trying to contribute to make it easier for OP to understand the code.
 
Last edited:
@DR, I'm aware of the no need as I found out later, however, I did leave it in to show the OP (or at least try to) about using compares he certainly has little experience and still struggles with how the logic works, I tried to explain that this was just a quick & dirty sequence & he may decide to add extra steps for example, maybe an operator confirmation of batch complete, perhaps extra error handling in case of fail to fill etc. but that is a bit far off from now, Siemens 1200 has blocks for analogue scaling that's why I did not show my own code i.e. add my function to the printout, this may have confused him even more, rather I gave him some links on how to use the standard blocks, and also a link to the typical wiring I think the OP needs to grasp the basics of how a PLC works before he commits to a project.
 
@DR, I'm aware of the no need as I found out later, however, I did leave it in to show the OP (or at least try to) about using compares...


I hear you. Actually I am not sure if it's clearer with or without the compares, because without the order of the rungs is important. Plus with the compares it's an nice little DeMorgan demo.


I was not trying to criticize, only improve.
 
Wow thank you guys, so so much

@parky you've helped me since the beginning and kept really kept it "boomer friendly". You are amazing pal. You really need a medal or smthng for helping me all this time :D. I really appreciate your help and if we manage to do this i will be owing you my life because this plc coding will do my daily job and i would love to do something like this to work.

and @drbitboy i would like to thank you aswell because after reading parky's message on lin_scale stuff yours gave me the details i needed but also kept that "boomer friendliness". From the bottom of my heart thank you kind sir.

I will be buying the plc and the loadcells in 2 to 3 days and after that the real fun will begin.

I am thinking of buying s7-1200 but im kinda curious. Will it be enough for my loadcells? i mean i will connect my loadcells with a junction box and then will connect it to my plc but i really dont know.

https://www.esit.com.tr/en/load_cells/ssb__load_cell/urun/174
i am thinking of buying 4 of these(2tons) but will my plc give any problems? is it powerful enough? Really dont know :D
 

Similar Topics

Hello, i am currently trying to create a plc programme from my Tia portal v16 for a package filling machine. But i am kinda new to the plc stuff...
Replies
48
Views
17,199
Hi, I have very limited knowledge in PLC. I uploaded the updated version of the software from our supplier on Omron PLC CP1H. It was also UM...
Replies
8
Views
13,797
Hi friends I am doing my major project and I need your help in writing a Ladder logic plc program. My project is to detect the edges of a block...
Replies
1
Views
4,801
Hi, every body! I have a small project. I wrote programmer control two pump motors by plc s7-300. Now I want to write programmer connect PLC to PC...
Replies
2
Views
4,572
Hello, First, let me start by letting you know that i am not a PLC programmer, nor am i a PLC user, in fact the first time i even heard of their...
Replies
18
Views
10,528
Back
Top Bottom