saifalikabi
Published © MIT

Arduino, PLC based SCADA for water treatment plant

Collect analog date by the Arduino send then through Modbus rs485 to PLC and show them on SCADA through Modbus rs232

AdvancedFull instructions provided504
Arduino, PLC based SCADA for water treatment plant

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
TIA Portal (WinCC) SCADA software
×1
XGB Ls PLC
×1
XG5000 Ls PLC software
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Liquid Crystal Display
×1
MAX485 TTL RS485
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1
RS-232 to USB
×1

Hand tools and fabrication machines

Modbus Master Data Scanner
Arduino IDE
USB Mini

Story

Read more

Schematics

The wiring of the PLC I/O

The mapping of the RS-485 (PLC-Arduino)

The mapping of the RS-232 (PLC-SCADA)

Arduino Board Wiring (as RS485 slave)

Code

ArduinoCode.ino

C/C++
#include <LiquidCrystal.h>
#include <ModbusMaster.h>
#include "dht.h"

#define dht_apin A0 
dht DHT;

#define MAX485_DE      3
#define MAX485_RE_NEG  2
ModbusMaster node;

void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}

#define trigPin1 9
#define echoPin1 8 

#define trigPin2 A4
#define echoPin2 A5


int duration, distance, UltraSensor1, UltraSensor2;

const int rs = 12, en = 11, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
const int tank_level = 24;   //cm
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{
   lcd.begin(16, 2);
   lcd.clear();

pinMode(echoPin1, INPUT);
pinMode(echoPin2, INPUT);

pinMode(trigPin1, OUTPUT);
pinMode(trigPin2, OUTPUT);
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);

digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);

Serial.begin(9600);

node.begin(1, Serial);

  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}
bool state = true;

void loop() 
{
uint8_t result1 = UltraSensor1;
uint8_t result2 = UltraSensor2;
uint8_t result3 = DHT.temperature;

DHT.read11(dht_apin);

SonarSensor(trigPin1, echoPin1);
UltraSensor1 = distance;
SonarSensor(trigPin2,echoPin2);
UltraSensor2 = distance;

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("L1 ");
  
  lcd.setCursor(3, 0);
  lcd.print(UltraSensor1);

  lcd.setCursor(7, 0);
  lcd.print("L2 ");

  lcd.setCursor(10, 0);
  lcd.print(UltraSensor2);

  lcd.setCursor(0, 1);
  lcd.print("T ");

  lcd.setCursor(2, 1);
  lcd.print(DHT.temperature);

  lcd.setCursor(10, 1);
  lcd.print("RS-485");


result1 = node.writeSingleRegister(0x0000, UltraSensor1);
result2 = node.writeSingleRegister(0x0002, UltraSensor2);
result3 = node.writeSingleRegister(0x0004, DHT.temperature);

delay (50);
}

void SonarSensor(int trigPinSensor,int echoPinSensor)
{
digitalWrite(trigPinSensor, LOW);
delayMicroseconds(2);
digitalWrite(trigPinSensor, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinSensor, LOW);

duration = pulseIn(echoPinSensor, HIGH);
distance= tank_level -((duration * .0343) / 2);


}

TIA Portal SCADA

ActionScript
No preview (download only).

XGB PLC program

ActionScript
No preview (download only).

PLC Logic.docx

BatchFile
No preview (download only).

Arduino Code

C/C++
#include <LiquidCrystal.h>
#include <ModbusMaster.h>
#include "dht.h"
#define dht_apin A0 
dht DHT;
#define MAX485_DE      3
#define MAX485_RE_NEG  2
ModbusMaster node;
void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}
#define trigPin1 9
#define echoPin1 8 
#define trigPin2 A4
#define echoPin2 A5
int duration, distance, UltraSensor1, UltraSensor2;
const int rs = 12, en = 11, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
const int tank_level = 24;   //cm
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
   lcd.begin(16, 2);
   lcd.clear();
pinMode(echoPin1, INPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin1, OUTPUT);
pinMode(trigPin2, OUTPUT);
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial.begin(9600);
node.begin(1, Serial);
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}
bool state = true;
void loop() 
{
uint8_t result1 = UltraSensor1;
uint8_t result2 = UltraSensor2;
uint8_t result3 = DHT.temperature;
DHT.read11(dht_apin);
SonarSensor(trigPin1, echoPin1);
UltraSensor1 = distance;
SonarSensor(trigPin2,echoPin2);
UltraSensor2 = distance;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("L1 ");
  lcd.setCursor(3, 0);
  lcd.print(UltraSensor1);
  lcd.setCursor(7, 0);
  lcd.print("L2 ");
  lcd.setCursor(10, 0);
  lcd.print(UltraSensor2);
  lcd.setCursor(0, 1);
  lcd.print("T ");
  lcd.setCursor(2, 1);
  lcd.print(DHT.temperature);
  lcd.setCursor(10, 1);
  lcd.print("RS-485");
result1 = node.writeSingleRegister(0x0000, UltraSensor1);
result2 = node.writeSingleRegister(0x0002, UltraSensor2);
result3 = node.writeSingleRegister(0x0004, DHT.temperature);
delay (50);
}
void SonarSensor(int trigPinSensor,int echoPinSensor)
{
digitalWrite(trigPinSensor, LOW);
delayMicroseconds(2);
digitalWrite(trigPinSensor, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinSensor, LOW);
duration = pulseIn(echoPinSensor, HIGH);
distance= tank_level -((duration * .0343) / 2);}

Credits

saifalikabi

saifalikabi

0 projects • 32 followers

Comments