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

  1. Download OpenPLC from the OpenPLC website and install it.
  2. Open the OpenPLC Editor.
  3. Configure your NEXTuino model in Settings > Device.
  4. Assign the correct COM port for communication.

OpenPLC examples for NEXTuino: GitHub repository

Step 2: Define System Inputs and Outputs

NameTypeDescriptionPin
stairs_pir_sensorBOOLPIR motion sensor input%IX0.0
control_button_downBOOLDownstairs push button%IX0.1
control_button_upBOOLUpstairs push button%IX0.2
stairs_lightBOOLStaircase 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_down or control_button_up is pressed, lights_buttons_state toggles the stairs_light on or off.

Automatic Light Control

  • When stairs_pir_sensor detects motion, it activates timer TOF0.
  • stairs_light remains on while the timer is active or motion is being detected.

Light Timeout

  • When no motion is detected for 20 seconds, TOF0 deactivates 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

  1. Save the ladder logic project and upload it to the NEXTuino via OpenPLC Editor.
  2. Test manual control: Press either push button and confirm the light toggles.
  3. 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.