Arduino with LabVIEW: Getting Arduino Data through Serial Communication in LabVIEW

Hi everyone! We hope you are well and doing great in your life. Today, we are going to start a series of tutorials on Arduino interfacing with LabVIEW. We have already posted a project on LabVIEW with Arduino for obtaining data from different sensors. This project is called a remote monitoring system using LabVIEW and Zigbee. You can find more details about this project by clicking on this link: Remote monitoring system using Arduino and Xbee.

In this tutorial, we will learn how to interface Arduino with LabVIEW, or in simple words, how to receive Arduino data through serial communication on the LabVIEW graphical user interface. It is recommended to have basic knowledge of LabVIEW software prior to starting this project. Let’s proceed with the tutorial.

Arduino with labview

Serial Communication with Arduino and LabVIEW

Nowadays, we have seen that many people are interested in serial communication between Arduino and LabVIEW, so we decided to write this article. LabVIEW provides a tool for Arduino, which we can use to program Arduino directly from LabVIEW. We just need to install the Arduino interface with LabVIEW’s tool in the software. We will also write an article on it, but for now, let’s see how to get Arduino data on LabVIEW without using the LabVIEW tool for Arduino. It has many uses in industrial applications. For example, it can be used in data acquisition systems, real-time monitoring systems, home automation systems, etc.

Getting Started: Arduino with LabVIEW

First of all, we need to have any version of LabVIEW installed on our PC. If you do not have it, you can download and install this software from this link: Download LabVIEW This software is not free. But we can still use the demo version for 45 days, or we can get it from other sources. To get data serially on LabVIEW, we need one more driver. This driver helps with serial communication between Arduino and LabVIEW VI. We will not be able to get data on LabVIEW’s VI without installing the driver. LabVIEW also provides other drivers, for example, LabVIEW server drivers and LabVIEW web services, which send LabVIEW data to web servers.

Programming with LabVIEW

For serial communication between Arduino and LabVIEW, follow these steps:

  • First of all, we need to download NI VISA driver.
  • After the download is complete, install this driver.
  • Once done with the installation, the NISA driver will automatically create a tool with the name of the COM port as shown in VI below.
  • After the installation of the NISA driver, when we run LabVIEW, this tool will automatically start appearing in the LabVIEW components window.
  • Now, simply run LabVIEW, and the following window will appear:
Labview running
LabVIEW 2015

Creating a LabVIEW VI

First, we need to design VI in Labview. To make VI, click on “Create Project”. The following window will appear:

Labview create project
Creating a Black VI

Now select Blank VI and click on Finish. After this, a new VI will open, which we can use to create our project.

LabVIEW has two types of consoles: one is a block diagram where we place all components, and the other is the front window. The front window is used as a graphical user interface, and it is where users get their data and make changes to it. A block diagram and front panel are shown below:

Front panel and block diagram
Front Panel and Block Diagram

LabVIEW Block Diagram

Once the VI opens, we can design it. In this VI, we will use a VISA resource to get data in serial mode. Arduino connects to the computer’s serial port, and LabVIEW’s VI receives data from the Arduino and displays it in the response window.

For this, we have designed a VI, which is shown below.

Labview VI for getting data serailly from Arduino
VI block diagram design

This VI includes a “While Loop” structure to get data continuously from Arduino. The response component is used to display data. The front panel of VI is shown below.

block diagram of Labview VI
Front Panel of project
  • We need to select the COM port to which our Arduino is connected. In our case, it is connected to the COM4 port. So we selected the COM4 port.
  • Lastly, click on Start Reading button, and we will get data in the response window.
  • To stop simulation, just click on stop simulation, and you will stop getting data in the response window.

Serial Data Output

Arduino with LabVIEW to get data serially

simulation results
Serial data via Arduino communication with LabVIEW

So we have explained all the things above to get data in LabVIEW from the serial port. Now we just need to send data from LabVIEW through the serial port. Connect the Arduino board to the computer and check the COM port to which it is connected. We can check it through the device manager on our computer. We can send any serial data we want.

Now, consider the scenario where we have four sensors. We want to measure the values of these sensors using Arduino and send the values to LabVIEW. For example, we have connected a temperature, humidity, light, and heartbeat sensor with an Arduino. It will measure these sensor values and send data to LabVIEW using serial communication. We have provided this example to send values of temperature, humidity, and light to the Arduino, and the Arduino sends these values to LabVIEW. We have provided the code below; you can use this code for testing purposes.

Arduino Code to Send Data to LabVIEW

In this section, we have provided the code used in this example.

#include <dht.h> // you should include DHT11 library
#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#define dht_dpin 12
dht DHT;

unsigned int AnalogValue;
unsigned int light;

byte degree[8] = {
  0b00011,
  0b00011,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

void setup() {
  lcd.begin(20, 4);
  Serial.begin(9600);
  lcd.createChar(1, degree);
  lcd.clear();
  lcd.print(" RMS system ");
  delay(2000);
}

void loop() {
  DHT.read11(dht_dpin);
  lcd.setCursor(0, 0);
  lcd.print("Humidity:");
  lcd.print(DHT.humidity); // printing Humidity on LCD
  lcd.print(" %");
  
  lcd.setCursor(0, 1);
  lcd.print("Temperature:");
  lcd.print(DHT.temperature); // Printing temperature on LCD
  lcd.write(1);
  lcd.print("C");

  AnalogValue = analogRead(A0) / 10.24;
  light = 100 - AnalogValue;  
  lcd.setCursor(0, 2);
  lcd.print("light=");
  lcd.print(light);
  lcd.print("%");
  
  delay(1000);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  
  Serial.print("temperature = ");
  Serial.println(DHT.temperature);
  
  Serial.print("light intensity = ");
  Serial.println(light);
}

Code Explanation

The workings of the code is as follows:

#include <dht.h> // you should include DHT11 library
#include <LiquidCrystal.h>

LiquidCrystal_lcd(2, 3, 4, 5, 6, 7);
#define dht_dpin 12
dht DHT;

First, we include two header tags: <dht.h> (for humidity and temperature sensors) and <LiquidCrystal.h> (for LCD displays). After this, we declare the Arduino pins for RS, EN, D4, D5, D6, and D7 pins of the LCD using the LiquidCrystal_lcd function. Finally, we declare the DHT sensor pin as pin 12 of the Arduino.

unsigned int AnalogValue;
unsigned int light;

byte degree[8] = {
  0b00011,
  0b00011,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

Next, we declare two unsigned integers as AnalogValue and light. We also define an array for a custom character for the degree symbol.

void setup() {
  lcd.begin(20, 4);
  Serial.begin(9600);
  lcd.createChar(1, degree);
  lcd.clear();
  lcd.print(" RMS system ");
  delay(2000);
}

In the void setup() function, we first initialize the LCD using the lcd.begin function. Then we set the baud rate to 9600 for serial communication. After this, we create a custom character for the degree symbol using the degree array. Lastly, we clear the screen and display the “RMS system” message for 2 seconds on the LCD display.

void loop() {
  DHT.read11(dht_dpin);
  lcd.setCursor(0, 0);
  lcd.print("Humidity:");
  lcd.print(DHT.humidity); // printing Humidity on LCD
  lcd.print(" %");

We read the DHT sensor value using pin 12 of the Arduino, then set the position of the cursor to the first row and first column. We print the characters Humidity: and the value of the humidity sensor with a percentage sign.

  lcd.setCursor(0, 1);
  lcd.print("Temperature:");
  lcd.print(DHT.temperature); // Printing temperature on LCD
  lcd.write(1);
  lcd.print("C");

Next, we set the cursor to column 0 and row 2 of the LCD display. After this, we print the Temperature: with the value of the temperature from the DHT sensor, the degree symbol, and the Celsius character.

  AnalogValue = analogRead(A0) / 10.24;
  light = 100 - AnalogValue;  
  lcd.setCursor(0, 2);
  lcd.print("light=");
  lcd.print(light);
  lcd.print("%");

For the light sensor, we read the value at pin A0 of the Arduino. Calculate the value of light using the formula. Then set the cursor to Column 0 and the 3rd row to print “light=” with the value of the light sensor and percentage symbol.

  delay(1000);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  
  Serial.print("temperature = ");
  Serial.println(DHT.temperature);
  
  Serial.print("light intensity = ");
  Serial.println(light);
}

Lastly, we print all these on the serial monitor with a delay of 1 second.

Video Demonstration

Conclusion

In this tutorial, we have discussed the following topics

  • Introduction of serial communication between Arduino and LabVIEW.
  • Getting started with Arduino and LabVIEW.
  • Programming with LabVIEW.
  • Code with Explanation

Related Articles

You may also like to read:

16 thoughts on “Arduino with LabVIEW: Getting Arduino Data through Serial Communication in LabVIEW”

  1. Hi,

    Thanks for your tutorial.

    I’m a beginner in labview.
    Could you add a link for labview code or would it be possible to transmit it by email ?

    Regards

    Reply
  2. Dear Bilal,
    thank for this useful tutorial. Is there is a way to use the Tx and Rx pins of the Arduino to pass serial data through Labview? What I mean is the opposite of what you did, instead of reading the COM port, I want to write to it. Thank you for your help.

    Reply
  3. Hi, thank you so much for tutorial.
    I need to monitor dates from measuring the pressure sensors that send the date with wifi from Arduino to receiver. Can you tell me, I need extra setup for Labview or not and what is the Arduino code to send dates to Labview?!

    Reply
  4. Hello,

    I am beginner and try to get data from my mini-spectrometer (by using arduino). Can you send me block diagram part to me if it is OK for you. Because I could not construct the structure by only looking to picture. You can send me via e-mail.

    Reply
  5. Hi sir,
    Thanks for your tutorial.

    I’m a beginner in labview.
    Could you mail me the vi for labview ?It is big help for me .

    Regards

    Reply
  6. Hello.
    I loaded a program with an ultrasonic sensor to test with the tutorial and it doesn’t work, it gives me error 1073807246. Any advice?

    Reply
  7. Hi sir,
    Thanks for your useful tutorial.
    Could you mail me the labview code? I am a labview beginner and need it for a university project.

    Reply
  8. Hello, I tried uploading the Arduino code, but I get the message:
    error: dht does not name a type

    I understand what this means and it looks like the DHT class is not loaded.
    However, I have installed the DHT and LiquidCrystal libraries – but there seem to be several choices. The one I picked also needed DHT_U.h. It is the DHT library by Adafruit. Looking at the DHT.h file, it seems there is a class called DHT – so not sure what is going on right now.
    Thanks in advance
    Chris

    Reply

Leave a Comment