Practical Guide to Button Control Output in PLC

Practical Guide to Button Control Output in PLC

Button Control PLC Output, Super Easy!

Hey, buddies! Today, let’s talk about the most basic and practical project in Siemens PLC programming — controlling PLC output with a button. This is a must-learn for beginners, and once you master it, you can easily handle more complex projects later. Don’t worry, follow me step by step, and I guarantee you’ll understand it at a glance!

Practical Project: Button Control PLC Output

First, let’s talk about what this project is for. In industrial sites, many devices need to be manually started or stopped, such as motors, pumps, and conveyors. This is where button control comes in handy. You press the button, and the device starts; you release the button, and the device stops. Sounds simple, right? However, in actual operation, you may encounter some minor issues, such as button bouncing and unstable output. Don’t worry, I’ll give you some tips and teach you how to write code to ensure this function runs smoothly.

Problems Encountered and Optimization Solutions

Let’s first talk about the issue of button bouncing. Sometimes when you press the button, the PLC may receive multiple signals, which is called bouncing. The solution is simple: just use a “debounce” program. The principle is to make the PLC wait for a short while to confirm that the button is genuinely pressed before executing actions. This way, the output becomes stable.

There is also the problem of unstable output. This may be due to issues in the program logic or poor hardware connections. Check the wiring and see if there are any loopholes in the program logic. If the logic is messed up, the output will definitely be unstable. Don’t worry, the code tutorial below will help you solve these issues.

Code Tutorial: Button Control Output

Alright, next is the main event the code! We will use Siemens S7-1200 PLC to write this program, and the instructions used are super simple, so beginners can easily get started.

Hardware Wiring

First, let’s talk about wiring. Connect the button to the PLC’s input terminal, for example, I0.0, and then connect the output terminal to an indicator light or motor, for example, Q0.0. Once the wiring is done, you can start writing the program.

Program Logic

The program logic is also very simple. When the button is pressed, the output terminal is powered on; when the button is released, the output terminal is powered off. To prevent bouncing, we add a debounce logic. The specific code is as follows:

plc code// Define VariablesVARInputButton : BOOL; // Button InputOutputSignal : BOOL; // Output SignalDebounceTimer : TON; // Debounce TimerEND_VAR

// Button InputInputButton := I0.0;

// Debounce LogicIF InputButton THENDebounceTimer(IN := TRUE, PT := T#100ms); // Button pressed, timer starts, delay 100msIF DebounceTimer.Q THENOutputSignal := TRUE; // Confirm button pressed, output signalEND_IF;ELSEDebounceTimer(IN := FALSE); // Button released, timer resetOutputSignal := FALSE; // Output signal offEND_IF;

// Output ControlQ0.0 := OutputSignal;In this code, DebounceTimer is a timer used for debouncing. After pressing the button, it will wait for 100 milliseconds to confirm that the button is genuinely pressed before allowing the output signal to be powered on. When the button is released, the output signal is powered off. This way, the output becomes stable!

Tips for PracticeAfter writing the code, upload it to the PLC and see how it works. If the output is still unstable, check if the button has poor contact, or if there are any missing parts in the program. Try it a few times, and you will definitely solve it. If you encounter other issues, don’t panic, just troubleshoot slowly. Programming is a process of trial and error. Don’t be afraid of problems; think more, try more, and you will surely find solutions.

Conclusion

Alright, that’s it for today’s sharing! Is button control of PLC output super easy? If you have any questions, leave a message for me, and let’s chat!

Leave a Comment