OpenPLC Light Intensity Control
OpenPLC Light Intensity Control
Introduction
This tutorial explains how to create a PWM-based light intensity control system using OpenPLC and a NEXTuino BASE PLC. The system adjusts light brightness through a single push button using a digital output. Each button press decreases the brightness until it cycles back to full intensity.
Prerequisites
- OpenPLC software installed
- A NEXTuino BASE PLC
- Basic knowledge of ladder logic and PWM
- A push button and a PWM-capable light output connected
Step 1: Install and Configure OpenPLC
- Download OpenPLC from the OpenPLC website and install it.
- Open the OpenPLC Editor.
- Navigate to Settings > Device and select “NEXTuino Micro”.
- Ensure the correct COM port is selected.
OpenPLC examples for NEXTuino: GitHub repository
Step 2: Define Variables
| Name | Type | Description |
|---|---|---|
Control_button | BOOL | Push button input to control brightness cycling |
Light_output | BOOL | PWM output controlling 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 brightness to maximum |
Flag_cicle | BOOL | Controls PWM signal cycling |
Full_bright | BOOL | Indicates the full brightness state |
Step 3: Create the Ladder Logic Program
Download the OpenPLC project from GitHub:
Dimmer_light_control
Button Press and Brightness Cycling
- Counter (CTU0): Each button press increments the counter, cycling
Light_brightthrough levels (0, 1, 2, 3) and resetting to 0 at maximum. - Brightness Comparators: Use
EQandGTcomparators to mapLight_brightto a PWM duty cycle. - PWM Signal Generation: Timers
TP0andTOF0control the on/off duration ofLight_outputfor PWM modulation. - Reset: When brightness reaches the lowest level,
Reset_stateresets the system to full brightness.
Step 4: Connect the Hardware
- Push button → digital input pin (e.g.,
NEXTuino_D0) →%IX0.0 - Light → PWM-capable output pin (e.g.,
NEXTuino_Q0) →%QX0.0
Assign Control_button to the input pin and Light_output to the output pin in the OpenPLC variable table.
Step 5: Upload and Test
- Save the ladder logic project and upload it to the NEXTuino BASE via OpenPLC Editor.
- Power on the NEXTuino BASE.
- Press the push button repeatedly and observe the light cycling through brightness levels.
Troubleshooting
- Verify wiring between the push button, light, and NEXTuino.
- Ensure the correct input and output pins are assigned to the variables.
- Use the OpenPLC debugger to check for errors in the ladder logic program.