LabVIEW LINX and Arduino
LabVIEW LINX and Arduino
blog
LabVIEW LINX
and Arduino
LabVIEW + LabVIEW LINX Toolkit + Arduino
Hans-Petter Halvorsen
Contents
• This Tutorial shows how we can use Arduino in
combination with the LabVIEW Programming environment
• “LabVIEW LINX Toolkit” is an add-on for LabVIEW which
makes it possible to program the Arduino device using
LabVIEW
• In that way we can create Data Logging Applications, etc.
without the need of an expensive DAQ device
• If you don’t have “LabVIEW Professional” Software, you
may use the “LabVIEW Community Edition” (free for non-
commercial use). You then get a very low-cost
DAQ/Datalogging System!
Table of Contents
• Introduction to LabVIEW LINX
• DAQ System
• Input/Output Channels
– Digital I/O
• Digital Out/Write
• Digital In/Read
– Analog I/O
• Analog Out/Write -> PWM (Pulse Width Modulation)
• Analog In/Read
• Sensors
– TMP36 Temperature Sensor
– Thermistor Temperature Sensor
LabVIEW + LabVIEW LINX Toolkit
PC
Arduino UNO
LabVIEW Sensors
+
LabVIEW LINX Toolkit
U
S
B TMP36
Temperature
c Sensor
a
b
Hardware
• Arduino
• Breadboard
• Wires (Jumper Wires)
• Resistors (𝑅 = 270Ω, 𝑅 =
10𝑘Ω)
• LED, Push Button
• TMP36 Temperature Sensor
Arduino UNO
• Arduino is a Microcontroller
• Arduino is an open-source platform
with Input/Output Pins (Digital
In/Out, Analog In and PWM)
• Price about $20
• Arduino Starter Kit ~$40-80
with Cables, Wires, Resistors, Sensors, etc.
Arduino I/O Channels
Digital Inputs and Digital Outputs
You can choose from the
code if they are to be
inputs or outputs
Analog Inputs
LabVIEW
• LabVIEW is Graphical Software
• LabVIEW has powerful features for
simulation, control and DAQ
applications
Basic LabVIEW Example:
LabVIEW LINX Toolkit
• The LabVIEW LINX Toolkit adds
support for Arduino, Raspberry Pi,
and BeagleBone embedded
platforms
• We will use Arduino Uno in this
Tutorial
Installing LabVIEW LINX Toolkit
Use VI Package Manger
Note: Do not install this package if you are running LabVIEW 2020 Community Edition or later,
as the Community Edition already includes the LabVIEW LINX Toolkit
LabVIEW LINX
LINX Firmware Wizard
LabVIEW Palette
https://www.halvorsen.blog
DAQ System
Sensors Digital IO
(Analog/Digital
Interface) Data Acquisition PC
Hardware
We will use an Arduino Uno as the DAQ Hardware
I/O Module
Analog Signals
I/O Module
LabVIEW LINX
Arduino DAQ System
Hans-Petter Halvorsen Table of Contents
https://www.halvorsen.blog
Input/Output
Channels
Hans-Petter Halvorsen Table of Contents
Arduino I/O Channels
Digital Inputs and Digital Outputs
You can choose from the
code if they are to be
inputs or outputs
Analog Inputs
Input/Output Channels
• Digital
–Digital Out
–Digital In
• Analog
–Analog Out
–Analog In
https://www.halvorsen.blog
Digital I/O
LED
𝑅 = 270Ω
LabVIEW Example
Multiple Digital Out Channels
https://www.halvorsen.blog
Digital In (DI)
False/Low True/High
LabVIEW - Digital In
LabVIEW Digital Write - Read
We can test the Digital In (Read) by wiring a Digital
Out (Read) Channel to the Digital In (Read) Channel
LabVIEW Digital Write - Read
Push Button/Switch
• Pushbuttons or switches connect two
points in a circuit when you press them.
• You can use it to turn on a Light when
holding down the button, etc.
Light
+ Switch (On/Off)
Power Supply
-
Wiring (Pull-up Resistor)
Another Digital Channel Using external Pull-up Resistor
can of course be used
𝑅 = 10𝑘Ω
Pull-down/Pull-up Resistor
Why do we need a pull-up or pull-down resistor in the
circuit?
• If you disconnect the digital I/O pin from everything, it
will behave in an irregular way.
• This is because the input is "floating" - that is, it will
randomly return either HIGH or LOW.
• That's why you need a pull-up or pull-down resistor in
the circuit.
Pull-up Resistor
+5V • When the pushbutton is open
(unpressed) there is a connection
Resistor between 5V and the DI pin.
DI • This means the default state is
True
Switch
(High).
• When the button is closed
GND
(pressed), the state goes to False
Pull-up Resistor
True/High False/Low
+5V +5V
Resistor Resistor
DI DI
GND GND
Push Button (Pull-up Resistor)
Button is NOT Pushed => True/High
GND GND
Wiring (Pull-down Resistor)
Another Digital Channel Using external Pull-down Resistor
can of course be used
𝑅 = 10𝑘Ω
Push Button (Pull-down Resistor)
Button is NOT Pushed => False/Low
Analog I/O
Not Working!
PWM as “Analog Out”
The Arduino UNO has no
real Analog Out pins,
but we can use a PWM
pin.
https://www.electronicwings.com/raspberry-pi/raspberry-pi-pwm-generation-using-python-and-c
Wiring
LED
𝑅 = 270Ω
PWM Example
We will see the brightness of the LED
will increase.
Or you can use a Multimeter and see
the (average) voltage will increase
PWM Example
PWM Example
20% → 1V 1V
0-100% → 0-5V
https://www.halvorsen.blog
Analog In (AI)
LabVIEW LINX
Arduino
Temperature Sensors
Hans-Petter Halvorsen Table of Contents
https://www.halvorsen.blog
Sensor
s
Hans-Petter Halvorsen Table of Contents
Sensors
We will use 2 different types of Temperature
Sensors:
• TMP36 Temperature Sensor
• Thermistor Temperature Sensor
Sensors
TMP36
Temperature
Sensor
Hans-Petter Halvorsen Table of Contents
Hardware
• Arduino
• Breadboard
• TMP36 Temperature Sensor
• Wires (Jumper Wires)
TMP36 Temperature Sensor
• A Temperature sensor like TM36 use
a solid-state technique to determine
the temperature.
• They use the fact as temperature
increases, the voltage across a diode
increases at a known rate.
• It costs only about $1
https://learn.adafruit.com/tmp36-temperature-sensor
TMP36
TMP is a small, low-cost temperature sensor and cost about $1 (you can buy it “everywhere”)
Wiring
LabVIEW
LabVIEW LINX has a built-in SubVI for TMP3x Sensors
LabVIEW
Do it from
Scratch
• LabVIEW LINX has a built-in SubVI for
TMP3x Sensors (TMP3x.vi)
• Let's see how we can do it from
“Scratch”
• We use the Datasheet and the
ordinary “Analog Read.vi”
Output Voltage vs. Temperature
Datasheet
Linear Scaling
Convert form Voltage (V) to degrees Celsius
From the Datasheet we have:
(𝑥1 , 𝑦1 ) = (0.75𝑉,
25°𝐶) (𝑥2, 𝑦2) = (1𝑉,
50°𝐶)
𝑦 = 100𝑥 − 50
https://www.halvorsen.blog
Thermistor
Temperature Sensor
Hans-Petter Halvorsen Table of Contents
Thermistor
A thermistor is an electronic component that changes
resistance to temperature - so-called Resistance
Temperature Detectors (RTD). It is often used as a
temperature sensor.
Our Thermistor is a so-called NTC (Negative Temperature Coefficient).
In a NTC Thermistor, resistance decreases as the temperature rises.
There is a non-linear relationship between resistance and excitement. To find the
temperature we can use the following equation (Steinhart-Hart equation):
[Wikipedia]
where 𝐴, 𝐵, 𝐶 are constants given
1
𝑇 = 𝐴 + 𝐵 ln(𝑅) + 𝐶 ln(𝑅) 7 below
𝐴 = 0.001129148, 𝐵 = 0.000234125 𝑎𝑛𝑑 𝐶 = 8.76741𝐸 −
Hardware
• Arduino
• Breadboard
• Thermistor 10K (Temperature Sensor)
• Wires (Jumper Wires)
• Resistor 10 kΩ
Wiring
Thermistor
𝑅 = 10 𝑘Ω
Voltage Divider
The wiring is called a “Voltage divider”:
+5V
10𝑘 Thermistor
Analog In (AI)
𝑅 = 10𝑘Ω
GND
[https://en.wikipedia.org/wiki/Voltage_divider]
General Voltage Divider
We want to find 𝑉𝑜𝑢𝑡
𝑅1 Formula:
+
𝑅&
𝑉𝑜 𝑢 = 𝑉$𝑛
𝑉&𝑛
+
𝑅1 +
-
𝑅2 𝑉𝑜𝑢𝑡
-
𝑡
𝑅&
https://learn.sparkfun.com/tutorials/voltage-dividers/all
Voltage Divider for our System
Voltage Divider Equation:
+ 𝑅 ( = 10𝑘Ω
𝑅𝑡
𝑉𝑜𝑢 = 𝑉<𝑛 5𝑉 𝑉&𝑛 +
𝑡 𝑅> + - 𝑅𝑡 𝑉𝑜 𝑢 𝑡
-
We want to find 𝑅𝑡 : 𝑅𝑡
𝑅𝑡 - 10k Thermistor. This varies with
𝑅𝑡 = 𝑉 𝑜u𝑡 𝑅 $ temperature. From Datasheet we
𝑉 i 𝑛 $ 𝑉 𝑜 u𝑡 know that 𝑅𝑡 = 10𝑘Ω @25℃
Steps:
1. We wire the circuit on the Breadboard and connect it to the DAQ device
2. We measure 𝑉𝑜𝑢𝑡 using the DAQ device
3. We calculate 𝑅𝑡 using the Voltage Divider equation
4. Finally, we use Steinhart-Hart equation for finding the Temperature
Steinhart-Hart Equation
To find the Temperature we can use Steinhart-Hart Equation:
1
𝑇𝐾 = 𝐴 + 𝐵 ln(𝑅) + 𝐶 ln(𝑅)
*
This gives:
1
𝑇𝐾 = 7
𝐴 + 𝐵 ln 𝑅 + 𝐶 ln 𝑅
𝐴 = 0.001129148
Where the Temperature 𝑇𝐾 is in Kelvin
𝐵 = 0.000234125
𝐴, 𝐵 𝑎𝑛𝑑 𝐶 are constants 𝐶 = 0.0000000876741
The Temperature in degrees Celsius will then be:
𝑇𝐶 = 𝑇𝐾 − 273.15
Pseudo Code
1. Get 𝑉𝑜𝑢𝑡 from the DAQ device (Arduino UNO)
2. Calculate 𝑅𝑡 = 𝑉 𝑜u𝑡 𝑅 $
𝑉 i𝑛 – 𝑉 𝑜 u𝑡
R
3. Calculate 𝑇𝐾 = 3
𝐴T𝐵 𝑙𝑛 𝑅 𝑡 T𝐶 𝑙𝑛 𝑅 𝑡
4. Calculate 𝑇𝐶 = 𝑇𝐾 − 273.15
//Steinhart constants
float A = 0.001129148;
float B =
0.000234125;
float C =
0.0000000876741;
//Steinhart-Hart
Equation
LabVIEW
LabVIEW - Steinhart-Hart Equation
Alternative 1: Formula Node
E-mail: [email protected]
Web: https://www.halvorsen.blog