OpenPLC Light Intensity Control

Categories: , , , , ,

Introduction

This tutorial explains how to create a PWM-based light intensity control system using OpenPLC software and a CONTROLLINO Micro PLC. The system adjusts the brightness of a light through a single push button, using a digital output. Each button press decreases the brightness until it cycles back to full intensity. This project showcases ladder logic programming to control light intensity using PWM.

Prerequisites

Before you begin, ensure you have the following:

  • OpenPLC software installed.
  • A CONTROLLINO Micro PLC.
  • Basic knowledge of ladder logic and PWM.
  • Hardware setup ready, including a connected push button and light output.

Step-by-Step Guide

Step 1: Install and Configure OpenPLC

  1. Download OpenPLC from the official OpenPLC website.
  2. Install the software on your computer.
  3. Open the OpenPLC Editor and configure the environment for your CONTROLLINO Micro PLC:
  • Navigate to Settings > Device and select “CONTROLLINO Micro” from the list.
  • Ensure the correct COM port is selected.

Step 2: Create the Ladder Logic Program

  1. Define Variables:
    Open the OpenPLC editor and define the variables listed below: Name Type Description Control_button BOOL Push button input to control brightness cycling. Light_output BOOL PWM output controlling the light intensity. Light_bright INT Tracks the current brightness level. Pulse_regulator TIME Timing variable for PWM modulation. Light_on_state BOOL Indicates whether the light is currently on. Reset_state BOOL Resets the brightness level to maximum. Flag_cicle BOOL Controls PWM signal cycling. Full_bright BOOL Indicates the full brightness state.
  1. Draw the Ladder Diagram:
  • Implement the logic as described in the Ladder Logic Explanation section below.
  • Use counters (CTU), timers (TP and TOF), and comparators (EQ, GT) to create the control logic.

Step 3: Understanding the Ladder Logic

Button Press and Brightness Cycling

  1. Counter (CTU0):
  • Each button press increments the counter.
  • The counter cycles through brightness levels (0, 1, 2, 3) and resets to 0 after reaching the maximum level.
  1. Brightness Level Comparison:
  • Use comparators to determine the brightness level (Light_bright) and adjust the PWM pulse width accordingly.
  1. PWM Signal Generation:
  • Use timers to control the on/off duration of the PWM signal based on the current brightness level.
  1. Light Output Control:
  • The variable Pulse_regulator adjusts the Light_output signal to modulate light intensity.

Step 4: Connect the Hardware

  1. Wiring:
  • Connect the push button to a digital input pin (e.g., CONTROLLINO_D0).
  • Connect the light output to a PWM-capable pin (e.g., CONTROLLINO_Q0).
  1. Pin Mapping:
  • Assign the Control_button variable to the input pin connected to the push button.
  • Assign the Light_output variable to the output pin connected to the light.

Step 5: Load and Run the Program

  1. Upload the Program:
  • Save your ladder logic project.
  • Use the OpenPLC Editor to upload the program to your CONTROLLINO Micro.
  1. Test the System:
  • Power on the CONTROLLINO Micro.
  • Press the push button and observe the light cycling through brightness levels.

Ladder Logic Explanation (Detailed)

Counter (CTU0):

  • Tracks the number of button presses and increments the Light_bright variable.
  • Resets to 0 after reaching the maximum brightness level.

Reset and Cycling:

  • When the brightness reaches the lowest level, the Reset_state variable resets the system to the maximum brightness level.

Brightness Control:

  • Use comparators (EQ, GT) to map the brightness level to a PWM duty cycle.
  • Timers (TP0, TOF0) generate the PWM signal by controlling the on/off duration of Light_output.

Troubleshooting

  1. Verify the wiring between the push button, light, and CONTROLLINO.
  2. Ensure that the correct input and output pins are assigned to the variables.
  3. Check for errors in the ladder logic program using the OpenPLC debugger.

Conclusion

You have successfully implemented a PWM-based light intensity control system using a CONTROLLINO Micro and OpenPLC. By integrating ladder logic and PWM, this project demonstrates an efficient way to control light brightness with a single push button. Experiment with the timing variables and additional functionality to customize the system further.

Share This Post

More Tutorials to explore

OpenPLC Editor for CONTROLLINO

Introduction In the world of industrial automation, having an intuitive and powerful programming environment is key. OpenPLC Editor, combined with CONTROLLINO, brings a seamless IEC