How to Build a Real-time SCADA System Using Python and Arduino | by M Khorasani | Towards Data Science

Those of us who have worked with SCADA (supervisory control and data acquisition) systems the likes of OSIsoft and Oracle know how invaluable the data they provide can be. Especially for many in the business of data and natural sciences, SCADA is a rich source of real-world data on demand. Yet such systems do not come cheap and the average individual would not be able to acquire their services readily. Luckily there is a way to create your own SCADA pipeline with simple and inexpensive equipment that is easily accessible. In this tutorial, I will show you how to set up an ambient temperature signal that will record and visualize data with a real-time dashboard on your computer.
To begin with, we will use an Arduino Uno board to read temperature values from the MLX9061 4infrared thermometer.
Once you have connected the infrared thermometer as shown above, proceed with uploading the following program to the Arduino.
If you have not already done so, first download and install the Adafruit_MLX90614 library using the Arduino IDE’s library manager in Tools > Manage Libraries.
To verify that the Arduino and thermometer are working as expected, open the serial monitor (Tools > Serial monitor) to ensure that a temperature recording is being printed every second as shown below.
Alternatively, you can also open the Arduino’s serial plotter (Tools > Serial plotter) to see a real-time plot of the ambient temperature as shown below.
Now that the Arduino and infrared thermometer are working and printing values to the serial port, we need to acquire the readings in Python to produce our SCADA dashboard. To interface our Python script with the Arduino through a serial USB connection, we will need to download and install Pyserial. Go ahead and fire up Anaconda or any other Python IDE of your choice and type the following command:
pip install pyserial
To produce a graphical user interface where we can interact with our dashboard we will use Streamlit. This highly versatile web framework allows you to quickly develop and deploy applications to a web server or alternatively run them locally on your browser. And to display a gauge of the current temperature reading as well as a chart of all previous temperature records, we will use Plotly. This is a Python binding for JavaScript’s highly interactive data visualization framework that allows you to render dazzling visuals at your fingertips.
Proceed by saving the following source code in your local directory:
The above code will initiate a connection to the Arduino and then will continuously read values from the serial port for the number of iterations specified. It will continuously render and update the gauge and chart. Finally, upon completion of the loop, the port will be closed and a CSV file with all the recordings will be saved in your local directory.
To run the above script type the following commands in Anaconda prompt:
cd C:/Users/.../local_directorystreamlit run temperature_dashboard.py
And there you have it your own real-time SCADA dashboard running on your local browser.
Now that you have created a SCADA system with real-time data visualization, you can further enhance the system by using an Arduino Uno WIFI that will enable you to extend the range of your signals. For further information please refer to Arduino Uno WIFI’s configuration guide. In addition, you can connect a whole variety of different third-party sensors and even actuators to the same Arduino for enhanced supervision and control.
If you want to learn more about data visualization and Python, then feel free to check out the following (affiliate linked) courses: