LabVIEW Experiment 1
LabVIEW Experiment 1
LabVIEW Experiment 1
Light Sensor Calibration Using Arduino Data Acquisition
(Arduino DAQ)
Experiment Objectives
Experience LabVIEW capabilities through learning exercises that design and
implement several Virtual Instruments (VIs) to meet specified requirements.
Utilize and implement a data acquisition system to collect data from several
different light sensors; to understand their differences and how they could be
used to accurately measure light intensity.
Design your own experimental procedures and conduct experiments to gather
and analyze data according to a given set of experimental objectives.
Analyze light sensor data and present calibration plots using Excel to relate
measured data to light intensity.
Understand and use the Arduino_Communication_SubVI to communicate
between LabVIEW and the Arduino DAQ.
Continue to develop your abilities to function on teams, act cooperatively and
honor individual commitments to team members and the team project.
Continue to develop your abilities to generate good technical reports.
Experiment Overview
LabVIEW will be programmed using several different front panel designs to collect
data from three light sensors measuring varying intensities of light. A test setup housing
the light source and sensors will be provided. Data calibration plots (sensor output vs.
light intensity) using Excel will be generated for each sensor over a full range of
intensities, and a study of how light intensity varies with distance will be conducted.
Design requirements for a baseline and three enhanced LabVIEW front panels will
be provided. The baseline front panel will form the basis upon which the enhanced
panels will be built. A step-by-step programming procedure will be provided for the
baseline panel, and everyone will walk through this procedure simultaneously with your
instructor to become familiar with using the LabVIEW interface. Each student on a team
will then be assigned one of the three enhanced panels. Each student will develop
their own Virtual Instruments (VI) according to the design requirements given
them. Guidance will be provided suggesting which LabVIEW functions could be used
to satisfy those requirements, however, a step-by-step programming procedure will not
be provided. Requirements for data collection, analysis and presentation will also be
provided, however, a step by step procedure will not be provided. You must develop
and document your own experimental procedure. A written lab report (team effort)
will be due on the date specified by your instructor.
Page 1 of 13
Of the three light sensors under test, two will be the same Cadmium Sulfide (CdS) type
used in the Design I course on the robot project. The third sensor will be a new solid
state device. All three will be connected to different analog input channels on the
Arduino DAQ. LabVIEW will communicate and request data from the Arduino DAQ via
a serial communication link established between your laptop and the Arduino. A
communication protocol implemented by a predefined sub Virtual Instrument (SubVI)
will be called in LabVIEW to communicate with the Arduino. A SubVI is analogous to
a subroutine in a text based programming language, such as C or BASIC. You will
learn how to use this SubVI, named the Arduino_Communication_SubVI. The Arduino
DAQ will be preloaded with a program that recognizes and responds to data requests
from LabVIEW. No programming of the Arduino will be required for this experiment.
The experiment will be conducted in a four foot long wooden enclosure designed to
block out ambient light. A white LED light source will be located at the end of the
enclosure. The intensity of the LED can be varied by turning a knob (a potentiometer)
on the controlling circuit board. The Arduino microcontroller with attached sensors will
be placed into the open end of the chamber where it can be moved closer to, or further
from the light source.
The experimental setup is for the most part intuitive and builds upon the knowledge you
have gained in Design I (E121) relative to operation and connectivity of sensors to the
Arduino microcontroller. The Arduino is now functioning as a Data Acquisition module
(Arduino DAQ). All required hardware will be provided, one setup per group. Following
is specific guidance.
The light source, a white LED, and controlling circuitry are pre-mounted on one side of
the light chamber. They get power from a 5VDC wall adapter that must be plugged into
an available outlet on your workbench. The circuitry associated with the LED is a
constant current source power supply. It monitors the current flowing into the LED and
automatically makes adjustments when necessary to keep the current at a constant
level. This in turn keeps the LED brightness constant. This circuitry is necessary to
offset the dynamically changing electrical characteristics of the LED as it naturally heats
up when generating light. Without it, intensities would vary and you could not take
consistent light readings. The constant current source can be set to different levels
(intensities) using a rotary knob. The knob is connected to a potentiometer (variable
resistor) that changes the amount of current being delivered to the LED.
1. Power Different from Design I, the Arduino DAQ will get power through the
USB port connected by a USB cable to your computer. For this experiment the
position of the power switches does not matter. Once the USB cable is
connected to your laptop power is supplied to the Arduino DAQ.
Page 2 of 13
2. Communications -Your laptop must be connected to the Arduino microcontroller
via the provided USB cable. The Arduino_Communication_SubVI will allow you
to select which COM port on your laptop to use for the serial link. The serial link
parameters (baud rate, parity, number of stop bits, etc.) will automatically be set
by the SubVI to be compatible to those set in the Arduino DAQ.
3. Light Sensors Under Test - Three light sensors mounted in the experimental
setup must be connected to the Arduino DAQ. The light sensor analog output
signals will be read by the Arduinos analog input circuitry. Remembering the
configuration of the Arduino module from last semester, there are six easily
accessible analog input connections. It is up to you to select and remember how
you have connected the devices. See Interfacing to the Arduino Microcontroller
under Arduino Resources if you do not remember where/how to connect to the
analog input channels.
Before connecting the light sensors, you must configure the associated
analog input jumper blocks, i.e., the red push-on shorting clips located
next to each of the six analog input terminals. The Arduino DAQ was
designed to accommodate two different types of analog sensor input sources:
The first was specifically for a variable resistor, such as our Design I light
sensors. This is called a passive sensor. Its called passive because it
does not require its own power supply and it will not produce its own
signal output. Rather it must be used in some external circuit capable of
detecting its changing characteristic (i.e. resistance). The external circuit
used is a voltage divider that is located on the Arduino DAQ. (See Light
Sensor Theory of Operation under E121 Robot Project Resources). To
configure the Arduino board for this type of sensor the jumper block next
to the associated analog input channel must connect the center pin
(either A0-A5) to the 5V pin. These designations can be found printed on
the circuit board. Our experimental setup will use two of these type
sensors.
The second was for any analog sensor directly providing an output
voltage in the range of 0-5 volts DC. This is called an active sensor. Its
active because it receives its own power source, and then on its own it
detects the parameter being measured and generates an output voltage
proportional to the magnitude of the measured parameter. To configure
the Arduino DAQ for this type of sensor the jumper block next to the
associated analog input channel must be completely removed from the
board. In our experimental setup we will have one active type light
sensor.
When connecting the passive CdS light sensors, the two same colored wires can
be connected in any order to the selected input screw terminal (A0-A5) and the
other to any GND screw terminal.
Page 3 of 13
When connecting the active solid state light sensor, there are three wires. Since
this device is an active type, it must get power via the red and black wires. The
red wire must connect to 5 volts on the Arduino DAQ (screw terminal labeled
VCC) and the black wire must connect to any GND screw terminal. The sensor
output signal will be a voltage that will vary with light intensity. The output signal
is on the yellow wire and it must connect to the selected Arduino analog input
terminal (A0-A5). Remember to remove the jumper block for this active sensor.
Experiment Requirements
Light sensor data from each of the three light sensors shall be recorded as the
light source is gradually increased from off to full intensity.
During this procedure, the light sensors shall be located in the light tunnel at a
point furthest from the light source, where readings can be taken.
The number of data points collected shall be sufficient to get a smooth data plot
over the full range of intensity control.
Measures shall be taken to minimize the intrusion of ambient light into the
experimental setup.
Procedure 2 shall be run three times using three different light intensities. Three
data sets shall result.
The three different intensities shall be selected to get varying sensor data over
the distance moved, i.e. avoid early saturation of the sensor data due to bight
intensity. (Prior to taking data, determine the best three intensities to use
experimentally by observing output data as the sensors move through the tunnel.
Note the position of the intensity knob.)
Page 4 of 13
At each of the three intensities selected:
- Record data from each light sensor as the sensors are moved through the
light tunnel towards the light source.
- The sensors shall be moved through the full length of the light tunnel.
- The number of data points collected shall be sufficient to get a smooth
data plot over the full range of motion.
- At each data collection point, the distance between the light source and
the light sensors shall be recorded in inches (not in fractions of the light
tunnel length).
Measures shall be taken to minimize the intrusion of ambient light into the
experimental setup.
Three different front panels shall be designed. Any of the three panels can be used to
collect data, however data collection cannot begin until all three front panels have
successfully been designed to stated requirements, and your instructor has
verified their operation and assigned you credit for the accomplishment. The front
panels have some common requirements as stated below. These common
requirements form the baseline design. The baseline design will be demonstrated as a
group class activity on the overhead projector by your instructor. Your instructor will also
explain how to use the Arduino Communication SubVI during this exercise. Each team
member must follow along with the instructor by constructing the design so that the
baseline design will be available on every laptop computer.
The baseline design is the starting point for each of the three final or
enhanced designs. It is required that each person on the team design and
implement one of the enhanced designs. It is up to the team to decide on how the
design assignments will be distributed. Collaboration during the design efforts is
allowed and recommended, however each person on the team must be
responsible for completing their assigned front panel using their own laptop.
Once a front panel design is complete and working, it must be demonstrated to
your instructor, as well as included in your project report. Your instructor and T/A
will help you accomplish your designs; however, you should also rely on the LabVIEW
help feature to understand the operation of a particular function. Right clicking on a
function when viewing the Block Diagram will bring up a Help and/or Properties
Page 5 of 13
option that will provide a description of that function and show how to use/configure it.
The help feature is extremely important and useful. Use it!
The design requirements for the baseline and three enhanced front panels are present
below. In general, required front panel control and indicator names are shown in bold
type.
This baseline panel is a step above the SubVI. It provides a user friendly means for
getting data from the Arduino DAQ. Using this panel, the person running the
experiment would only need to know which analog channel to read. He/she would not
have to know the technical details of the protocol (language) between LabVIEW and the
Arduino DAQ. These details will be programmed into LabVIEW, and thus transparent to
the user.
1. As an input entitled Arduino Connection, the laptop COM port to use for
connection to Arduino DAQ shall be selectable via a drop down menu.
2. As an input entitled Arduino Analog Channel, the analog channel to read from
the Arduino shall be input as a number in the range of 0-5.
3. As an output entitled Communications Error, a red LED shall illuminate if the
Arduino_Communication_SubVI returns a Hardware Error status. Otherwise
the LED shall be off.
4. As an output entitled Data Entry Error, a red LED shall illuminate if the
Arduino_Communication_SubVI returns a Data Input Error status. Otherwise,
the LED shall be off.
5. As an output entitled Sensor Data, VDC, the numerical value of the raw data
returned from the Arduino DAQ shall be displayed in DC Volts. The data shall be
scaled to display output data in the following format- X.XXXX VDC.
To start a new front panel design, the basic procedure is to open a blank VI in
LabVIEW. A new blank VI will always display two screens, the Front Panel, and the
Block Diagram. On the Front Panel, right clicking will display the Controls palette.
From the Controls palette you will select the various input and output controls needed to
satisfy requirements and place them on the front panel. In selecting the input and
output controls, there is not always one right answer. If the requirements are not
specific, you can use your creativity in designing the Front Panel. For example the size,
shape, color, and location of a LED indicator are up to you (unless otherwise specified).
Once the required controls and indicators are situated and configured on the Front
Panel, you will then go into the Block Diagram and wire the data paths between inputs
and outputs to achieve program objectives. Wiring the data paths on the block diagram
may require data conversions, such as converting string data to numeric data, or other
Page 6 of 13
data manipulations, such as arithmetic operations, or data comparisons. These data
manipulations are represented by icons that are placed on the block diagram by
grabbing them from the Functions palette made visible by right clicking on the Block
Diagram.
Once the Front Panel and Block Diagram designs are complete, run LabVIEW to see
how the program operates, and to see if any runtime errors exist.
Your instructor will go through the following step-by-step baseline front panel design
with you.
To implement the baseline front panel design (do this for homework):
Open LabVIEW on your laptop and from the Files menu, open "New VI to start a
new program.
Address requirement 1. On the front panel, right click to show the Controls
palette. Select the Modern, I/O, VISA Resource icon and place it on the front
panel. (VISA is LabVIEWs standard application programming interface used to
control your computers USB serial port.) Double click on the text VISA resource
name and change it to Arduino Connection
Address requirement 2. On the front panel Controls palette, select the Modern,
Numeric, Numeric Control icon and place it on the front panel. Right click on the
text Numeric and make sure the Size to Text option is checked. (You should
do this for all icons placed on the front panel.) Then double click on the text
Numeric and change it to Arduino Analog Channel. Further configure this
numeric control by right clicking on it (not the text box) and selecting Properties.
In the Properties display, select Data Type. Left click on the representation icon,
and Select U8. (This means data entered will be in unsigned integer format,
and will have a length of 8 bits, the smallest possible.) Furthermore, select the
Data Entry tab and unclick Use default limits, and set the minimum value to 0,
the maximum value to 5, and the increment to 1. (This will limit data entry to
only the valid range as required, i.e., as a 0, 1, 2, 3, 4 or 5.)
Address requirement 3. On the front panel Controls palette, select the Modern,
Boolean, Round LED icon and place it on the front panel. Change the text to
Communications Error. Using Properties change the On color of the LED
to red.
Address requirement 4. On the front panel Controls palette, select the Modern,
Boolean, Round LED icon and place it on the front panel. Change the text to
Data Entry Error. Using Properties change the On color of the LED to red.
Address requirement 5. On the front panel Controls palette, select the Modern,
Numeric, Numeric Indicator and place it on the front panel. Change the text to
Sensor Data, VDC. Using Properties, select Display Format, set the
number of significant digits to 5, and uncheck the Hide Trailing Zeros box.
(This will allow us to display data as required with five significant digits.)
Page 7 of 13
You now have a front panel design that meets requirements, but there is no program
knowledge of how data will flow from inputs to outputs. This will be entered on the block
diagram panel. When you open the block diagram view, you should see all of the
controls and indicators you just placed on the front panel.
Open the block diagram view. (Note: Control-E can be used to toggle between
the front panel and block diagram.) On the block diagram, arrange your program
inputs to be on the left (i.e., Arduino Connection and Arduino Analog Channel)
and your program outputs (the two error LEDs and Sensor Data) to be on the
right. (This will not affect the layout of these items on the front panel.) This
rearrangement will cause a natural flow of data from left to right, and is
important for clarity and simplicity in troubleshooting problems.
For LabVIEW to communicate with the Arduino DAQ, we need to get the
Arduino_Communication_SubVI and place it on the block diagram. (You should
have downloaded this SubVi to your laptops hard drive following the procedure
detailed in Understanding the Arduino to LabVIEW Interface. If not, you must
do so now.) On the functions palette, select Select a VI... all the way on the
bottom. Browse to and select the Arduino_Communication_SubVI.vi. Click OK
and place it on your block diagram between the inputs and outputs. Expand
the SubVI as detailed in Understanding the Arduino to LabVIEW Interface.
Three front panel items can be wired immediately; that is there are no data
conversions or mathematical operations required. Wire the:
- Arduino Connection control to COM port on the SubVI (notice both have
a purple color)
- Data Entry Error LED to Data Input Error on the SubVI (notice both have
a green color)
- Communications Error LED to Hardware Error on the SubVI (notice
both have a green color)
Next, we would like to wire the Arduino Analog Channel selector to the input
of the SubVI which is Message. However, their colors are different, which
indicates they are different data types and generally cannot be connected. If you
try to wire them together, you will get an error. Arduino Analog Channel is a
numeric integer; Message is an ASCII string. Additionally the
Arduino_Communication_SubVI needs to receive a specific sequence of string
characters (the protocol described in Understanding the Arduino to LabVIEW
Interface) otherwise the Arduino DAQ will not understand what is requested.
Hence, in the block diagram we must implement the data conversion and the
required protocol string, as follows:
- Convert the Arduino Analog Channel number into ASCII by selecting from
the Functions palette the Programming, String, String/Number Conversion,
Number to Decimal String Conversion icon.
- Create the protocol string input required by the SubVI by selecting the
Programming, String, Concatenate String icon. This icon simply merges
Page 8 of 13
ASCII strings together. It will have a default input length of two (which is what
we need), but it can be "stretched" down (left click/stretch) to any length
desired. Connect the first input to an ASCII A constant. This can be done by
pointing to the first (upper) input connection, right clicking, and selecting
Create, Constant. Type the constant required into the box that appears.
Connect the second (lower) input to the ASCII output coming from the icon
that converted the Arduino Analog Channel from a number to ASCII.
- Connect the output of the concatenated string to the SubVI input named
Message.
The final connection we need is to get the output from the SubVI, Arduino
Reading, and display it on our Sensor Data, VDC numeric display. However,
again the colors are different which indicates a conversion is needed, this time
from ASCII to a numeric value. Also the data coming from the Arduino is an
integer number in the range of 00000 to 50000 (recall the light sensor data in
Design I). To convert this to Volts in X.XXXX format we need to divide by 10000.
Hence, in the block diagram we must do these data conversions as follows:
- Convert the Arduino Reading ASCII output into a number by using the
Programming, String, String/Number Conversion, Decimal String to Number
Conversion icon. Note the output of this icon is the terminal named Number.
- Divide the resulting numeric output by 10000 using the Programming,
Numeric, Divide icon. Connect a constant = 10000 to the denominator (y
input) of the divide function. (Use Help, by right clicking on the function.)
- Connect the Output of the divide function to the Sensor Data, VDC
numeric display.
You should now have a fully functioning LabVIEW program. Assign one of the three
following enhanced front panels to each member on your team and proceed to design
and develop them.
This front panel makes selecting the analog channel even easier by incorporating a
drop down menu. It also introduces the concept of warning/system status indicators by
comparing sensor data to predefined/acceptable limits.
The input Arduino Analog Channel numeric control shall be changed from the
baseline design to a selectable drop down menu. (Hint: Combo Box) There shall
be six selectable menu options: CdS #1, CdS #2, Solid State Sensor, Spare #1,
Spare #2 and Spare #3. These menu options must be associated (Assigned)
with the six available Arduino DAQ analog input channels 0, 1, 2, 3, 4 and 5.
Three LED output indicators shall be added to the Front Panel to warn of certain
conditions as follows:
Page 9 of 13
- One LED labeled No Light Source shall be illuminated RED when the solid
state light sensor indicates that the tunnel light source is off (has been turned
off). Otherwise the LED shall be off (grayed). This LED shall be functional
only when the Arduino Analog Channel input has selected the Solid State
Sensor. If not selected, this LED shall be off. (Hint: You must experimentally
determine a value from the Solid State Sensor that indicates the light source
is off. Also the comparison functions equal to, equal to or less than, equal
to or greater than and the logical AND function may be useful.)
- One LED each shall be associated with the two CdS light sensors. A LED
labeled Level #1 shall be associated with CdS#1 sensor and a LED labeled
Level #2 shall be associated with CdS#2 sensor. The LEDs shall turn on
Green when the associated CdS light sensor output indicates a
predetermined light intensity level has been achieved or exceeded (greater
intensity, brighter). The predetermined intensity for each LED shall be
independently entered on an associated numeric input control. These inputs
shall be labeled Operating Level #1, VDC and Operating Level #2, VDC.
The input values for both operating levels shall have the same format as
Sensor Data, VDC, that is X.XXXX Volts DC. If the associated intensity
levels are not reached or exceeded, or if they had been reached or exceeded
but then drop below them, the associated LED shall be off (grayed). The LED
associated with CdS#1 shall be functional only when the Arduino Analog
Channel has selected CdS#1. The LED associated with CdS#2 shall be
functional only when the Arduino Analog Channel has selected CdS#2.
If not selected, the associated LEDs shall be off.
This front panel offers the user versatility to select any of the six analog channels
available on the Arduino DAQ and display up to three of them simultaneously, i.e. it
emulates a three channel display/monitoring device. It also introduces the graphical
plotting of data in real time when LabVIEW is placed in the Run Continuously mode.
The Front Panel shall be redesigned to include three identical (Hint: Copy and
Paste after one is complete) monitoring panels. Each monitoring panel will
have one input device and two output devices as follows:
- One six position rotary switch input device labeled Select Sensor. This
input selector shall select which one of the six Arduino DAQ analog channels
to monitor. The first three position markers on the rotary switch shall be
labeled CdS #1, CdS#2, and Solid State Sensor. (Hint: Right Click on
the device and explore the available options.) The last three switch positions
shall be labeled Spare#1, Spare#2 and Spare#3.
Page 10 of 13
- In addition to the Sensor Output, VDC used in the baseline, a numeric
output indicator labeled Raw Sensor Output shall display the associated
sensors raw output, i.e., directly as sent from the Arduino DAQ.
- A graph output display labeled Sensor Output shall plot the data
associated light sensor. The x-axis shall be time, and be scaled so that data
is displayed for approximately 3 seconds before it scrolls off of the graph.
The y-axis shall be Raw Sensor Data, but calibrated in volts and scaled to
range of 0.0000 volts DC to 5.0100 volts DC. (Hint: The Waveform Chart
already has the x-axis setup for time.)
When LabVIEW is placed in the Run Continuously mode, all three monitoring
panels shall simultaneously and continuously display sensor data in real time as
selected by the six position rotary switch, both on the numeric output indicator
and on the graphical strip charts.
The following controls and indicators should NOT be replicated for each
monitoring panel. Only one of each is required to oversee operation of all three
monitoring panels: Arduino Connection, Communications Error, Data Entry
Error
This front panel comes closest in configuration to a final user application, not a
development version. It places controls of how to run program right in the front panel.
Once the program is started, it should never have to be stopped.
Page 11 of 13
pressed again, it will extinguish its light and the program shall return to the
Single Read mode of operation.
The front panel shall contain one graph that will display in real time the data
being received from the selected Arduino Analog Channel when the program
is operating in Continuous Read mode of operation. The x-axis shall be time and
be scaled so that data is displayed for approximately 2 seconds before scrolling
off of the chart. The y-axis shall be Sensor Data, VDC scaled to cover the
range from 0.0000 5.0200 VDC. (Hint: Use right click properties to change
graph parameters)
As designs are completed and tested successfully, alert your instructor so that
credit can be assigned.
The organization, clarity, and presentation of your report shall count for 6 Points.
When writing your report, structure it according to the Lab Report Template, Lab
Report Format for Experiment 1. Within the template provide the following data and
analysis:
Present the step-by-step procedure you used to configure the experimental setup
and carry out the data collection procedures. (Not the LabVIEW Front Panel or
Block Diagram creation procedure.) (10 Points)
Present depictions of your three Enhanced Front Panel designs. I.e., use the
Print Window command to print out BOTH your three front panel designs AND
the three associated block diagrams. (15 Points)
Enter collected data into Excel and use the Excel graph function to generate x-y
scatter plots of all light intensity data. BE SURE TO CLEARLY LABEL ALL
AXES AND PLOTS.
- Present one graph for Procedure 1 Requirements with light intensity as the
independent variable (x-axis) and sensor outputs as the dependent variables (y-
axis). Plot the output data for all three sensors on the one graph so that their
data differences can be readily seen. Scale the graph to get good differentiation
of the data. (5 Points)
- Present three separate graphs for Procedure 2 Requirements. Each graph
should associate to one of the three light sensors (I.e., one graph for data from
CdS#1, one graph for data from Cds#2, and one graph for data from the Solis
State light sensor). Each graph should plot distance from light source
(independent variable, x-axis) vs. that sensors output (dependent variable, y-
Page 12 of 13
axis). Three lines should appear on each graph, all data from the same sensor
but at the three different intensities you chose to run the experiment. (12
Points)
- What differences in output readings do you see between the two Cds light
sensors for the same light intensity? How could you have used these
calibration plots to better compare sensor data from multiple light sensors
during the Design I robot experiment? (3 Points)
- What significant differences are clearly visible between the output of the CdS
sensors and the solid state sensor? Identify at least two. (3 Points)
- Based at looking at the data, for what situations would you more likely want to
use the solid state technology sensor over the CdS technology sensor? (3
Points)
- For all light sensors, what empirical observation can be made about how light
intensity drops off with distance from the light source? (3 Points)
Page 13 of 13