OpenPLC Staircase Light Control
OpenPLC Staircase Light Control
Introduction
This tutorial demonstrates how to create an automatic staircase lighting system using OpenPLC and a NEXTuino. The system uses two push buttons for manual control and a PIR sensor for automatic activation. The light toggles manually with button presses or turns on automatically when motion is detected, staying on for 20 seconds before turning off if no further motion occurs.
Prerequisites
- OpenPLC software installed
- A NEXTuino (any model)
- A Passive Infrared (PIR) motion sensor
- Two push buttons (for manual control)
- Basic knowledge of ladder logic programming
Step 1: Install and Configure OpenPLC
- Download OpenPLC from the OpenPLC website and install it.
- Open the OpenPLC Editor.
- Configure your NEXTuino model in Settings > Device.
- Assign the correct COM port for communication.
OpenPLC examples for NEXTuino: GitHub repository
Step 2: Define System Inputs and Outputs
| Name | Type | Description | Pin |
|---|---|---|---|
stairs_pir_sensor | BOOL | PIR motion sensor input | %IX0.0 |
control_button_down | BOOL | Downstairs push button | %IX0.1 |
control_button_up | BOOL | Upstairs push button | %IX0.2 |
stairs_light | BOOL | Staircase light output | %QX0.0 |
Timer: TOF0 (Off Delay Timer) — Duration: T#20s
Step 3: Create the Ladder Logic Program
Download the OpenPLC project from GitHub:
stairs_light_control
Manual Light Control
- When
control_button_downorcontrol_button_upis pressed,lights_buttons_statetoggles thestairs_lighton or off.
Automatic Light Control
- When
stairs_pir_sensordetects motion, it activates timerTOF0. stairs_lightremains on while the timer is active or motion is being detected.
Light Timeout
- When no motion is detected for 20 seconds,
TOF0deactivates and the light turns off automatically.
Step 4: Connect the Hardware
Connect the components to the NEXTuino digital I/O pins:
- PIR sensor output →
DI0(%IX0.0) - Downstairs push button →
DI1(%IX0.1) - Upstairs push button →
DI2(%IX0.2) - Staircase light →
DO0(%QX0.0)
Step 5: Upload and Test
- Save the ladder logic project and upload it to the NEXTuino via OpenPLC Editor.
- Test manual control: Press either push button and confirm the light toggles.
- Test automatic control: Trigger the PIR sensor and confirm the light turns on and stays on for 20 seconds after motion stops.
Troubleshooting
- Verify all sensors and buttons are connected to the correct input pins.
- Check that input/output variable assignments in OpenPLC match the physical wiring.
- Use OpenPLC debugging tools to monitor variable and timer states.