This application about how to read data from Multiple DS18B20 Digital Temperature Sensor to PLC (Programmable Logic Controller), and to bridge between Multiple DS18B20 and PLC, I use Arduino.
Communication between Arduino and Multiple DS18B20 use One Wire Communication, and Communication between Arduino and PLC use Modbus Communication.
Operating temperature range of DS18B20 between -55°C to +125°C -67°F to +257°F) and suitable for applications : HVAC (Heating, Ventilation, and Air Conditioning) environmental controls, sensing temperatures equipment or machinery , process monitoring and control, sensing temperatures inside buildings , and etc.
How to Read Data from Multiple DS18B20 to PLC ?
Let's read this article and let's go watch the video demonstration:
for communication use RS485 Modbus communication
Communication between Arduino and Multiple DS18B20 use One Wire Communication, and Communication between Arduino and PLC use Modbus Communication.
Operating temperature range of DS18B20 between -55°C to +125°C -67°F to +257°F) and suitable for applications : HVAC (Heating, Ventilation, and Air Conditioning) environmental controls, sensing temperatures equipment or machinery , process monitoring and control, sensing temperatures inside buildings , and etc.
How to Read Data from Multiple DS18B20 to PLC ?
Let's read this article and let's go watch the video demonstration:
Multiple DS18B20 Digital Temperature Sensor to PLC using Arduino, One Wire and Modbus Communication
Hardware
- Arduino UNO
- 2 Pieces DS18B20 Digital Temperature Sensor, I use Waterproof with 3 cable:
- 1 piece with cable : Red (VCC), Yellow(DATA), Black(GND)
- 1 piece with cable : Red (VCC), Yellow(DATA), Grey(GND)
- 1 Piece Resistor 4.7K ohm / 4700 ohm
- RS485 Transceiver Module
- Siemens S7-200 PLC
- 1 Piece Resistor 220 ohm
- 2 Pieces Resistors 330 ohm
- Power supply for Arduino UNO
- DB9 Male Connector
DS18B20 Digital Temperature Sensor |
Hardware Connections
1. Connections between Arduino, RS485 Module and PLC
Hardware connection can be read in the article : http://program-plc.blogspot.com/2015/11/plc-modbus-master-arduino-modbus-slave.html2. Connections between Arduino and Multiple DS18B20 Digital Temperature Sensor
Software
- Arduino Software : https://www.arduino.cc/en/Main/Software and I use HOURLY BUILDS version 1.6.6
- Arduino library : click here Unzip and Copy Paste to folder C:\arduino-nightly\libraries
Only Folder : DallasTemperature, OneWire and ModbusMasterRS485
Project File
- for Upload to Arduino : click here
- for Download to Siemens S7-200 PLC : click here
Modbus Communication between Arduino Modbus Master and PLC Modbus Slave
- Arduino UNO such as Modbus Master
- PLC such as Modbus Slave with Slave Address 1
- DS18B20 to Arduino use One Wire Communication
Response/Actual Time from DS18B20 Digital Temperature Sensor to PLC
1. DS18B20 Max Conversion Time per Sensor
Thermometer Resolution
|
Max Conversion Time
|
9 bit
|
94 ms
|
10 bit
|
188 ms
|
11 bit
|
375 ms
|
12 bit
|
750 ms
|
2. Actual Time for two Sensors
I use two sensor and with Thermometer Resolution = 9 and Actual Time from Read two DS28B20 to Write PLC Memory between 2 - 2.5 Secondsfor communication use RS485 Modbus communication
Arduino Code for Application of DS18B20 , RS485 and PLC
#include <OneWire.h> #include <DallasTemperature.h> #include <SimpleModbusMaster.h> #define slaveAddr 1 #define baud 9600 #define timeout 1000 #define polling 1 #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[3]; //Red cable to +5V and Black/Grey cable to GND //Yellow/Blue Cable is plugged into D3/Pin 3 on Arduino Proto Screw #define One_Wire_Pin 3 //Thermometer resolution is programmable from 9 to 12 bits #define Thermometer1_Resolution 9 #define Thermometer2_Resolution 9 //Setup a one wire communication OneWire One_Wire(One_Wire_Pin); //Pass our oneWire reference to Dallas Temperature. DallasTemperature Temperature_Sensor(&One_Wire); //Setup Temperature Sensor Address DeviceAddress Temperature_Sensor1_Address = {0x28, 0xFF, 0x12, 0x77, 0x52, 0x15, 0x01, 0xE0}; DeviceAddress Temperature_Sensor2_Address = {0x28, 0xFF, 0xCB, 0x29, 0x15, 0x15, 0x01, 0xCB}; void setup(void) { //Modbus Slave Setup modbus_construct(packet1, slaveAddr, PRESET_MULTIPLE_REGISTERS, 0, 3, writeRegs); modbus_configure(&Serial, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS); //Temperature Sensor Setup Temperature_Sensor.begin(); Temperature_Sensor.setResolution(Temperature_Sensor1_Address, Thermometer1_Resolution); Temperature_Sensor.setResolution(Temperature_Sensor2_Address, Thermometer2_Resolution); if(!Temperature_Sensor.getResolution(Temperature_Sensor1_Address) || !Temperature_Sensor.getResolution(Temperature_Sensor2_Address)) { //Get Temperature Sensor Address int numberOfDevices = Temperature_Sensor.getDeviceCount(); Serial.print("Locating devices..."); Serial.print("Found "); Serial.print(numberOfDevices, DEC); Serial.println(" devices."); if(numberOfDevices>0)Serial.println("Please Setup Address with : "); DeviceAddress tempDeviceAddress; for(int i=0;i<numberOfDevices; i++) { if(Temperature_Sensor.getAddress(tempDeviceAddress, i)) { Serial.print("DeviceAddress Temperature_Sensor"); Serial.print(i+1, DEC); Serial.print("_Address = "); printAddress(tempDeviceAddress); Serial.println(); }else{ Serial.print("Found ghost device at "); Serial.print(i, DEC); Serial.println(" but could not detect address. Check power and cabling"); } } while(1){}; } } void loop(void) { Temperature_Sensor.requestTemperatures(); //Resolution=9 delay time 94ms per sensor //Resolution=10 delay time 188ms per sensor //Resolution=11 delay time 375ms per sensor //Resolution=12 delay time 750ms per sensor //Error -127.00 float Temperature1_Celsius = 100 * Temperature_Sensor.getTempC(Temperature_Sensor1_Address); float Temperature2_Celsius = 100 * Temperature_Sensor.getTempC(Temperature_Sensor2_Address); writeRegs[0]=(word)random(1000); writeRegs[1]=(word)Temperature1_Celsius; writeRegs[2]=(word)Temperature2_Celsius; modbus_update(); } void printAddress(DeviceAddress deviceAddress) { Serial.print("{"); for (uint8_t i = 0; i < 8; i++) { Serial.print("0x"); if (deviceAddress[i] < 16) Serial.print("0"); Serial.print(deviceAddress[i], HEX); if(i<7)Serial.print(", "); } Serial.print("};"); }