Introduction
This tutorial demonstrates how to create an automatic staircase lighting system using OpenPLC and a CONTROLLINO PLC. 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
Before you begin, ensure you have the following:
- OpenPLC software installed.
- A CONTROLLINO PLC (any model) or compatible PLC.
- A Passive Infrared (PIR) motion sensor.
- Two push buttons (for manual control).
- Basic knowledge of ladder logic programming.
Step-by-Step Guide
Step 1: Install and Configure OpenPLC
- Download OpenPLC:
- Visit the OpenPLC website and download the software.
- Follow the installation instructions for your operating system.
- Set Up the OpenPLC Environment:
- Open the OpenPLC Editor.
- Configure the environment for your CONTROLLINO PLC by selecting the correct model in Settings > Device.
- Assign the appropriate COM port for communication.
Step 2: Define System Inputs and Outputs
Configure the following inputs and outputs in your ladder logic program:
Name | Type | Description | Pin |
---|---|---|---|
stairs_pir_sensor | BOOL | Input from the PIR motion sensor. | %IX0.0 |
control_button_down | BOOL | Input from the downstairs push button. | %IX0.1 |
control_button_up | BOOL | Input from the upstairs push button. | %IX0.2 |
stairs_light | BOOL | Output to control the staircase light. | %QX0.0 |
Timers:
TOF0
(Off Delay Timer): Controls the light timeout after motion detection.- Duration:
T#20s
.
Step 3: Create the Ladder Logic Program
- Manual Light Control:
- When either
control_button_down
orcontrol_button_up
is pressed, thelights_buttons_state
toggles thestairs_light
. - This allows manual on/off control of the staircase light.
- Automatic Light Control:
- When the
stairs_pir_sensor
detects motion, it activates the timerTOF0
. - The light (
stairs_light
) remains on while the timer is active or as long as motion is detected.
- Light Timeout:
- When no motion is detected for 20 seconds, the
TOF0
timer deactivates. - The light turns off automatically unless toggled manually.
Step 4: Connect the Hardware
- Wiring:
- Connect the PIR sensor output to a digital input pin (e.g.,
DI0
). - Connect the downstairs push button to another input pin (e.g.,
DI1
). - Connect the upstairs push button to a separate input pin (e.g.,
DI2
). - Connect the staircase light to a digital output pin (e.g.,
DO0
).
- Pin Mapping:
- Assign the corresponding input and output variables in OpenPLC:
stairs_pir_sensor
→%IX0.0
control_button_down
→%IX0.1
control_button_up
→%IX0.2
stairs_light
→%QX0.0
Step 5: Load and Test the Program
- Upload the Program:
- Save your ladder logic project in the OpenPLC Editor.
- Connect your CONTROLLINO PLC to your computer and upload the program.
- Test Manual Light Control:
- Press the upstairs (
control_button_up
) or downstairs (control_button_down
) push button. - Confirm that the light toggles on and off with each press.
- Test Automatic Light Control:
- Walk near the PIR sensor to simulate motion detection.
- Observe the light turning on and staying active for 20 seconds after the motion stops.
- Ensure the light turns off automatically after the timer expires.
Ladder Logic Explanation (Detailed)
Manual Light Control
- Toggling the Light:
- Each button press (
control_button_up
orcontrol_button_down
) changes the state oflights_buttons_state
. - The state of
lights_buttons_state
determines whetherstairs_light
is turned on or off.
Automatic Light Control
- PIR Sensor Activation:
- When the
stairs_pir_sensor
detects motion, the timerTOF0
starts. - The
stairs_light
remains on while motion is detected or while the timer is active.
- Light Timeout:
- The
TOF0
timer turns off the light 20 seconds after the PIR sensor stops detecting motion.
Combining Manual and Automatic Control
- The light can be manually toggled on or off at any time using the push buttons.
- Automatic activation by the PIR sensor operates independently, ensuring flexibility.
Troubleshooting
- Verify Wiring:
- Ensure all sensors and buttons are correctly connected to the appropriate input pins.
- Confirm the light is connected to the correct output pin.
- Check Variable Assignments:
- Double-check that the input and output variables in OpenPLC match your physical connections.
- Debugging:
- Use the OpenPLC debugging tools to monitor the state of variables and timers.
Conclusion
Congratulations! You have successfully implemented an automatic staircase lighting system using OpenPLC and a CONTROLLINO PLC. This system combines manual and automatic control for optimal flexibility and convenience. Experiment with different timer durations or additional sensors to customize the system further.