Add this page to your book
Remove this page from your book
Table of Contents
LabVIEW and NXT Sensors
Author: Yu Hang He Email: firstname.lastname@example.org
Date: Last modified on <8/14/17>
Keywords: LabVIEW, NXT, LEGO MINDSTORMS, NXT Sensor
The photo above depicts a LEGO MINDSTORMS NXT brick with four NXT sensors attached to it: touch, sound, light, and ultrasonic sensors. Using LabVIEW module for LEGO MINDSTORMS allows you to directly read and graph data collected through these sensors. This tutorial shows you how to use LabVIEW module for LEGO MINDSTORMS to program with these four sensors and takes approximately 4 hours to complete.
Motivation and Audience
This tutorial's motivation is to demonstrate how to use LabVIEW module for LEGO MINDSTORMS to program NXT sensors. This tutorial assumes the reader has the following background and interests:
* Know how to program with LabVIEW. (LabVIEW Basic Tutorial)
* Perhaps also know how to operate LEGO MINDSTORMS NXT.
* Perhaps also have basic understanding of how to use MINDSTORMS module. (LabVIEW and NXT)
* This tutorial may also attract readers who want to use LEGO MINDSTORMS for instruction purpose.
The rest of this tutorial is presented as follows:
NXT Touch Sensor have two states: pressed or unpressed. To receive inputs from NXT Touch Sensor, you can use instances of
Read Sensor or
Wait For VI, both are polymorphic VIs with many different instances. The two VI can be accessed through
function palettes →
Read Sensor VI have four available instances for Touch Sensor:
Pressedreturn Boolean value based on whether or not Touch Sensor button has been pressed.
Releasedreturn Boolean value based on whether or not Touch Sensor button was released from press position.
Bumpedreturn Boolean value based on whether or not Touch Sensor button was pressed then released from press position.
Countreturn number of times Touch Sensor button was bumped.
Pressedwait until Touch Sensor button has been pressed.
Releasedwait until ouch Sensor button was released from press position.
Bumpedwait until Touch Sensor button was pressed then released from press position.
Countwait until Touch Sensor button was bumped X number of times.
The Sound Sensor can detect both decibels [dB] and adjusted decibels [dBA]. The Sound Sensor can detect up to 90 dB. The Sound Sensor readings are displayed in percentage.
dBA: Sensitivity of Sound Sensor is adjusted to the level of human ears.
dB: Detecting standard decibels.
You can receive input from Sound Sensor through
Read Sensor and
Wait For polymorphic VIs.
Read Sensor, you can choose which type of reading that sensor will return:
Wait For allow the program to wait until sound reading surpass or fall below certain level.
Example: Sound Filter
Here is an example of sound filter included in LabVIEW Module for LEGO MINDSTORMS.
The VI/program use an array and shift register to record every new sound reading. It uses a secondary shift register to calculate the sum of recent recordings within filter window. For the first few sound sensor readings, while they are lower than filter window, the case structure condition is false and the VI average the sensor readings to calculate filtered value. Afterward, the filtered value is calculated as average of readings based on filter window. The filtered values are displayed in waveform chart.
Light Sensor can be used to distinguish between light and dark, as well as determine the light intensity in a room or the light intensity of different colors. The Light Sensor reading is recorded between 0 and 100.
Similar to other sensors, you can receive inputs from Light Sensor through two polymorphic VIs:
Read Sensor and
Read Sensor have the option to read from Light Sensor with
LED On or
Wait For have four instances:
BrighterWaits until the light sensor connected to the specified port detects a specified positive change in brightness (relative comparison).
DarkerWaits until the light sensor connected to the specified port detects a specified negative change in darkness (relative comparison).
BrightnessWaits until the light sensor connected to the specified port detects a brightness greater than the specified brightness value (absolute comparison).
DarknessWaits until the light sensor connected to the specified port detects a darkness less than the specified darkness value (absolute comparison)
Example: Line Follower
Here is an example of line following VI using NXT Light Sensor. For this example, we will use Steering on function. You can input power and steering as two variable for the function. Steering is a number between -100 and 100. Depending on how the motors are wired, a negative number turn them in one direction and a positive number turn them in opposite direction.
The program record initial light sensor reading of the line. In a continuous loop, the VI calculate the difference between current and initial sensor reading then apply that difference to
Steering On to turn motors in one direction or the opposite direction.
Ultrasonic Sensor can be used to measure distance to an object. It is able to measure distances from 0 to 2.5 meters with a precision of -/+ 3 centimeters.
Read Sensor with ultrasonic sensor return a sensor reading in centimeter.
Wait For wait until ultrasonic sensor returns a reading further or closer than an absolute value.
Example: Radar Gun
Here is an example of using Ultrasonic Sensor to measure velocity of object. The program read from Ultrasonic Sensor(converted to meter) and Timer(converted to second). It use two shift registers to keep track of previous readings then subtract them from current readings to calculate displacement and change in time. Divide displacement and change in time to calculate velocity.
This tutorial's objective was to demonstrate how to use LabVIEW MINDSTORMS module to program NXT sensors. Once the concepts were conveyed the reader could use LabVIEW to program NXT sensors and display and record sensor readings.
For more examples and help, access LabVIEW MINDSTORMS module manual through
MINDSTORS Module Help or
For questions, clarifications, etc, Email: email@example.com