Programmable Logic Controller (PLC) application about distance measurement using ultrasonic sensor. Ultrasonic sensor connect to the Arduino, And then Arduino connect to the PLC using serial port and ModBus communication protocol.
Distance measurement application used for example: Liquid / Water Level Sensor non contact (probe), Object Detection Sensor, Object Distance Sensor, Check the amount of products (Products Checker), and etc.
A. Example PLC Application: Products Checker
B. Hardware
1. Ultrasonic sensor HC-SR04
2. Arduino Uno
3.TTL to RS232 male
4.RS232 PLC Cable
5.PLC with Modbus Support (Modbus Slave)
6. Resistor
7. Seven Segment Common Anode
8. Adaptor for Arduino
C. Wiring
For about display seven segment with PLC, check the link:
http://program-plc.blogspot.com/2010/05/display-seven-segment-with-plc.html
D. Software
Download Project File:
1. Arduino SimpleModbusMaster Library (Copy-Paste into Folder C:\Program Files (x86)\Arduino\libraries), click here
2. Arduino Project, click here
3.Ladder Programming for Siemens PLC S7-200, click here
E. See The test result:
F. Set the distance ranges in PLC ladder programming
G. Arduino Code
#includeSimpleModbusMaster.h
//Arduino Serial Port Connect to Port 0 of Siemens PLC S7 200
#define slaveAddr 1
#define baud 9600
#define timeout 1000
#define polling 200
#define retry_count 0
#define TxEnablePin 2
enum
{
PACKET1,
TOTAL_NO_OF_PACKETS
};
Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
unsigned int writeRegs[2];
#define Trig 13
#define Echo 12
const float CmFactor = 29.0;
const float InFactor = 73.746;
void setup() {
modbus_construct(packet1, slaveAddr, PRESET_MULTIPLE_REGISTERS, 0, 2, writeRegs);
modbus_configure(&Serial, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
}
void loop() {
long durationMicroseconds, distanceCentimeters,distanceInches;
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
durationMicroseconds = pulseIn(Echo, HIGH);
distanceCentimeters = (durationMicroseconds/2) / CmFactor;
distanceInches = (durationMicroseconds/2) / InFactor;
writeRegs[0] = (word) distanceCentimeters;
writeRegs[1] = (word) distanceInches;
modbus_update();
delay(100);
}
Distance measurement application used for example: Liquid / Water Level Sensor non contact (probe), Object Detection Sensor, Object Distance Sensor, Check the amount of products (Products Checker), and etc.
A. Example PLC Application: Products Checker
B. Hardware
1. Ultrasonic sensor HC-SR04
2. Arduino Uno
3.TTL to RS232 male
4.RS232 PLC Cable
5.PLC with Modbus Support (Modbus Slave)
6. Resistor
7. Seven Segment Common Anode
8. Adaptor for Arduino
C. Wiring
For about display seven segment with PLC, check the link:
http://program-plc.blogspot.com/2010/05/display-seven-segment-with-plc.html
D. Software
Download Project File:
1. Arduino SimpleModbusMaster Library (Copy-Paste into Folder C:\Program Files (x86)\Arduino\libraries), click here
2. Arduino Project, click here
3.Ladder Programming for Siemens PLC S7-200, click here
E. See The test result:
F. Set the distance ranges in PLC ladder programming
G. Arduino Code
#include
//Arduino Serial Port Connect to Port 0 of Siemens PLC S7 200
#define slaveAddr 1
#define baud 9600
#define timeout 1000
#define polling 200
#define retry_count 0
#define TxEnablePin 2
enum
{
PACKET1,
TOTAL_NO_OF_PACKETS
};
Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
unsigned int writeRegs[2];
#define Trig 13
#define Echo 12
const float CmFactor = 29.0;
const float InFactor = 73.746;
void setup() {
modbus_construct(packet1, slaveAddr, PRESET_MULTIPLE_REGISTERS, 0, 2, writeRegs);
modbus_configure(&Serial, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
}
void loop() {
long durationMicroseconds, distanceCentimeters,distanceInches;
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
durationMicroseconds = pulseIn(Echo, HIGH);
distanceCentimeters = (durationMicroseconds/2) / CmFactor;
distanceInches = (durationMicroseconds/2) / InFactor;
writeRegs[0] = (word) distanceCentimeters;
writeRegs[1] = (word) distanceInches;
modbus_update();
delay(100);
}
Labels:
Arduino
Arduino Microcontroller
PLC
PLC and Arduino
PLC Application
Programmable Logic Controller
Sensor
Ultrasonic Sensor
Arduino
Arduino Microcontroller
PLC
PLC and Arduino
PLC Application
Programmable Logic Controller
Sensor
Ultrasonic Sensor