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

  1. Download OpenPLC from the OpenPLC website and install it.
  2. Open the OpenPLC Editor.
  3. Navigate to Settings > Device and select “NEXTuino Micro”.
  4. Ensure the correct COM port is selected.

OpenPLC examples for NEXTuino: GitHub repository

Step 2: Define Variables

NameTypeDescription
Control_buttonBOOLPush button input to control brightness cycling
Light_outputBOOLPWM output controlling light intensity
Light_brightINTTracks the current brightness level
Pulse_regulatorTIMETiming variable for PWM modulation
Light_on_stateBOOLIndicates whether the light is currently on
Reset_stateBOOLResets brightness to maximum
Flag_cicleBOOLControls PWM signal cycling
Full_brightBOOLIndicates 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_bright through levels (0, 1, 2, 3) and resetting to 0 at maximum.
  • Brightness Comparators: Use EQ and GT comparators to map Light_bright to a PWM duty cycle.
  • PWM Signal Generation: Timers TP0 and TOF0 control the on/off duration of Light_output for PWM modulation.
  • Reset: When brightness reaches the lowest level, Reset_state resets 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

  1. Save the ladder logic project and upload it to the NEXTuino BASE via OpenPLC Editor.
  2. Power on the NEXTuino BASE.
  3. 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.