How to Publish DHT11 Sensor Data from Arduino Uno to OPC-DA and Read it using Matrikon OPC-DA Explorer

 

How to Publish DHT11 Sensor Data from Arduino Uno to OPC-DA and Read it using Matrikon OPC-DA Explorer

Introduction

The DHT11 sensor is a popular temperature and humidity sensor that is commonly used in Arduino projects. One of the challenges that many people face is how to publish the data from the DHT11 sensor to a wider audience. In this blog post, we will explore how to publish DHT11 sensor data from an Arduino Uno to Arduino OPC-DA Server and read it using Matrikon OPC-DA Explorer software.

Setting up the Arduino Uno

First, we need to set up the Arduino Uno and connect the DHT11 sensor. Connect the data pin of the DHT11 sensor to pin 2 on the Arduino Uno. Then, connect the power pin of the DHT11 sensor to the 3.3V pin on the Arduino Uno, and the ground pin of the DHT11 sensor to the GND pin on the Arduino Uno.


Setting up OPC-DA

OPC-DA is a protocol that is used to transfer data between different devices. In order to publish DHT11 sensor data to Arduino OPC-DA, we need to set up an Arduino OPC-DA server on our computer.

Publishing the Data

Now that we have set up the Arduino Uno Connection with DHT11 Sensor, Now we can publish the data from the DHT11 sensor. But first, we need to write some code for the Arduino Uno that reads the data from the DHT11 sensor and sends it to the Arduino OPC-DA Server which is in our system.

Here is some sample code that you can use:

#include <OPC.h>
#include "DHT.h"
#define DHTPIN 2 
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE);

/* Declaring the OPC object */
OPCSerial aOPCSerial;

int Humidity(const char *itemID, const opcOperation opcOP, const int value){
  static int Humidity = 0;
  Humidity = dht.readHumidity();
  return Humidity;
}

int Temperature(const char *itemID, const opcOperation opcOP, const int value){
  static int Temperature = 0;
  Temperature = dht.readTemperature();
  return Temperature;
}

void setup() {
  Serial.begin(9600);
  Serial.println(F("DHT11 OPC-DA Test!"));
  dht.begin();
  
  /* OPC Object initialization */
  aOPCSerial.setup();
  
  /* A0 OPCItem declaration */
  aOPCSerial.addItem("Humidity",opc_read, opc_int, Humidity);
  aOPCSerial.addItem("Temperature",opc_read, opc_int, Temperature);
}

void loop() {
  /* OPC process commands */
  aOPCSerial.processOPCCommands();
}

This code reads the data from the DHT11 sensor and sends it to the Arduino OPC-DA Server in your system over Serial communication.

Reading the Data using Matrikon OPC-DA Client Software

Finally, we can use the Matrikon OPC-DA client software to read the data from the Arduino OPC-DA server. We need to connect to the server using the IP address of the computer where the OPC-DA server is running and the OPC server name. Once we are connected, we can browse the available data items and select the temperature and humidity data that we want to read.

Matrikon OPC-DA client software provides a graphical interface to view the data in real-time. We can also log the data to a file for further analysis.

Check out our YouTube video for a step-by-step tutorial:


Conclusion

In this blog post, we explored how to publish DHT11 sensor data from an Arduino UNO device to an Arduino OPC-DA server and read it using Matrikon OPC-DA Explorer software. The OPC protocol provides a standard interface for data exchange between devices and software applications in the industrial automation field. By using the Arduino and OPC libraries, we can easily set up a system to read sensor data and publish it to an OPC-DA server.

Comments