User Tools

Site Tools


labview_nxt_sensor_tutorial

LabVIEW and NXT Sensors

Author: Yu Hang He Email: hey6@unlv.nevada.edu
Date: Last modified on <8/14/17>
Keywords: LabVIEW, NXT, LEGO MINDSTORMS, NXT Sensor
 NXT Sensors
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:

Touch Sensor

 Touch Sensor
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 palettesI/O.

Read Sensor VI have four available instances for Touch Sensor: Pressed, Released, Bumped, and Count.
 Read Sensor

  • Pressed return Boolean value based on whether or not Touch Sensor button has been pressed.
  • Released return Boolean value based on whether or not Touch Sensor button was released from press position.
  • Bumped return Boolean value based on whether or not Touch Sensor button was pressed then released from press position.
  • Count return number of times Touch Sensor button was bumped.

Similarly, Wait For VI have four available instances for Touch Sensor: Pressed, Released, Bumped, and Count.
 Wait For

  • Pressed wait until Touch Sensor button has been pressed.
  • Released wait until ouch Sensor button was released from press position.
  • Bumped wait until Touch Sensor button was pressed then released from press position.
  • Count wait until Touch Sensor button was bumped X number of times.

Example

Here is a simple example that set motor power at 75 when touch sensor button was bumped. And brake all motors when touch sensor button was bumped again.
 Touch Sensor Example

Sound Sensor

 Sound Sensor
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.
Using Read Sensor, you can choose which type of reading that sensor will return: dB or dBA.
 Read Sensor
Wait For allow the program to wait until sound reading surpass or fall below certain level.
 Wait For Sound Sensor

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.
 Sound Filter  Sound Filter

Light Sensor

 Light Sensor
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 Wait For.
Read Sensor have the option to read from Light Sensor with LED On or LED Off.
 Read Light Sensor Wait For have four instances:

  • Brighter Waits until the light sensor connected to the specified port detects a specified positive change in brightness (relative comparison).
  • Darker Waits until the light sensor connected to the specified port detects a specified negative change in darkness (relative comparison).
  • Brightness Waits until the light sensor connected to the specified port detects a brightness greater than the specified brightness value (absolute comparison).
  • Darkness Waits until the light sensor connected to the specified port detects a darkness less than the specified darkness value (absolute comparison)

 Wait For Light

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.  Steering On

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.  Light Sensor Example

Ultrasonic Sensor

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.  Read Sensor Ultrasonic Wait For wait until ultrasonic sensor returns a reading further or closer than an absolute value.  Wait For Ultrasonic

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.  Ultrasonic Sensor Example

Final Words

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 HelpMINDSTORS Module Help orFind Examples.
For questions, clarifications, etc, Email: hey6@unlv.nevada.edu

labview_nxt_sensor_tutorial.txt · Last modified: 2017/08/15 15:46 by yuhanghe