Build Mini SCADA System Using Raspberry Pi: Step-by-Step Guide
To build a mini SCADA system using
Raspberry Pi, connect sensors and actuators to the Pi's GPIO pins, use Python scripts to read and control devices, and deploy a lightweight SCADA software like Node-RED or OpenPLC for monitoring and control. This setup allows real-time data collection and control through a web interface.Syntax
Building a mini SCADA system on Raspberry Pi involves these parts:
- Hardware setup: Connect sensors (temperature, humidity, etc.) and actuators (relays, motors) to Raspberry Pi GPIO pins.
- Software scripts: Use Python to read sensor data and control actuators.
- SCADA platform: Use tools like Node-RED or OpenPLC to visualize and control data via web interface.
python
import RPi.GPIO as GPIO import time # Setup GPIO mode GPIO.setmode(GPIO.BCM) # Define pin for sensor input and actuator output sensor_pin = 17 actuator_pin = 27 # Setup pins GPIO.setup(sensor_pin, GPIO.IN) GPIO.setup(actuator_pin, GPIO.OUT) try: while True: sensor_value = GPIO.input(sensor_pin) if sensor_value == GPIO.HIGH: GPIO.output(actuator_pin, GPIO.HIGH) # Turn actuator ON else: GPIO.output(actuator_pin, GPIO.LOW) # Turn actuator OFF time.sleep(1) except KeyboardInterrupt: GPIO.cleanup()
Example
This example shows a simple Python script that reads a digital sensor connected to GPIO 17 and controls an actuator (like an LED or relay) on GPIO 27. It turns the actuator ON when the sensor is HIGH and OFF otherwise.
Use this script on Raspberry Pi with connected hardware to see real-time control.
python
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) sensor_pin = 17 actuator_pin = 27 GPIO.setup(sensor_pin, GPIO.IN) GPIO.setup(actuator_pin, GPIO.OUT) try: while True: sensor_value = GPIO.input(sensor_pin) if sensor_value == GPIO.HIGH: print("Sensor HIGH: Turning actuator ON") GPIO.output(actuator_pin, GPIO.HIGH) else: print("Sensor LOW: Turning actuator OFF") GPIO.output(actuator_pin, GPIO.LOW) time.sleep(1) except KeyboardInterrupt: GPIO.cleanup()
Output
Sensor HIGH: Turning actuator ON
Sensor LOW: Turning actuator OFF
Sensor HIGH: Turning actuator ON
... (repeats every second)
Common Pitfalls
Common mistakes when building a mini SCADA system on Raspberry Pi include:
- Not setting GPIO mode correctly (use
GPIO.setmode(GPIO.BCM)orGPIO.setmode(GPIO.BOARD)consistently). - Forgetting to clean up GPIO pins after the program ends, which can cause warnings or errors on next run.
- Using incorrect pin numbers or wiring sensors/actuators wrongly.
- Not installing required libraries like
RPi.GPIOor SCADA software dependencies. - Ignoring power requirements for actuators, which may damage the Pi.
Example of wrong and right GPIO setup:
python
# Wrong way (missing GPIO mode setup) import RPi.GPIO as GPIO GPIO.setup(17, GPIO.IN) # This will cause error # Right way import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN)
Quick Reference
| Step | Description |
|---|---|
| 1 | Connect sensors and actuators to Raspberry Pi GPIO pins. |
| 2 | Install Python and RPi.GPIO library. |
| 3 | Write Python scripts to read sensors and control actuators. |
| 4 | Install lightweight SCADA software like Node-RED or OpenPLC. |
| 5 | Configure SCADA software to visualize and control devices via web. |
| 6 | Test system and ensure safe power supply for actuators. |
Key Takeaways
Use Raspberry Pi GPIO pins to connect sensors and actuators for SCADA control.
Write Python scripts with proper GPIO setup and cleanup to read and control devices.
Deploy lightweight SCADA platforms like Node-RED for easy monitoring and control.
Always verify wiring and power requirements to avoid hardware damage.
Test your system step-by-step to ensure reliable real-time operation.