mySTEM™ Project Board for NI myDAQ

mySTEM™ Project Board
for NI myDAQ™
Copyright © 2013 Studica, Inc. All Rights Reserved
Tom White & Associates
mySTEM Project Board
2
mySTEM Project Board
Table of Contents
Introduction to the mySTEM™ Board ...................................................................................................................... 5
Power Connections ............................................................................................................................................ 5
myDAQ Connections .......................................................................................................................................... 7
Breadboard ........................................................................................................................................................ 8
Output connections............................................................................................................................................ 9
Connecting Signals to the Outputs ........................................................................................................................ 10
Computer Control of Outputs ............................................................................................................................... 11
Launch the NI ELVISmx Instrument ................................................................................................................... 12
Setting Up the Labview Interface .......................................................................................................................... 14
Beginning Labview Programming .......................................................................................................................... 18
Introduction to Sensors- Voltage Divider............................................................................................................... 23
Switches............................................................................................................................................................... 27
Digital Input: Express VI ........................................................................................................................................ 31
The Circuit........................................................................................................................................................ 31
Writing the simple program.............................................................................................................................. 32
Introduction to Programming Structures: ............................................................................................................. 43
Digital Outputs: Sending Signals to Devices: .......................................................................................................... 52
Wiring in the Motor ......................................................................................................................................... 55
Adding Reverse Direction ................................................................................................................................. 64
Designing Programs.............................................................................................................................................. 69
Flow Charts ...................................................................................................................................................... 69
State Machines..................................................................................................................................................... 71
Open Loop Programming:..................................................................................................................................... 74
Closed Loop Programming: ................................................................................................................................... 85
Creating Enum Constants ..................................................................................................................................... 93
Hand Dryer with a Photo Transistor .................................................................................................................... 102
Counter Utilizing a Photo Transistor.................................................................................................................... 112
Programming Structures: Conveyor Belt ............................................................................................................. 125
Parallel Programming: Elevator........................................................................................................................... 142
Introduction to Sensors- Voltage Divider for Analog Sensors ............................................................................... 155
Analog Input: Express VI ..................................................................................................................................... 158
The Circuit...................................................................................................................................................... 159
Writing the simple program............................................................................................................................ 160
Making Analog Decisions: ................................................................................................................................... 169
Introduction to Logic Gates................................................................................................................................. 175
The NOT Gate................................................................................................................................................. 175
Truth Table: ............................................................................................................................................... 176
Boolean Expression: ....................................................................................................................................... 176
AND and OR Gates: ........................................................................................................................................ 176
AND Gate Truth Table: ............................................................................................................................... 178
Boolean Expression: ....................................................................................................................................... 178
OR Gate ......................................................................................................................................................... 178
NOR Gate ....................................................................................................................................................... 179
NAND Gate .................................................................................................................................................... 179
Conclusion ..................................................................................................................................................... 179
3
mySTEM Project Board
mySTEM Project Board
4
mySTEM Project Board
Programming with the mySTEM™ Project Board
Introduction to the mySTEM™ Board
This activity will introduce you to the various aspects of the mySTEM™ Project Board. The mySTEM™
Project Board is designed to allow you to incorporate all manner of sensors with easily configurable
outputs. This and the following exercises will allow you to become familiar with reading sensors,
configuring Labview to process the information and create desired outputs. The mySTEM™ board plugs
into the side of the myDAQ™ or the myRIO™ turning them into compact affordable programmable
action controllers.
Power Connections
The mySTEM™ Project Board needs to be powered. You can supply any voltage between six and twenty
six volts Direct Current. There is an onboard regulator that produces the required 5 volts for the logic
circuits. You should select a power supply that can supply the voltage and current your output devices
need. The board ships with a Fischertechnik’s Motor. This motor requires 9V to operate.
The first method is to connect a wall transformer to supply the desired DC voltage. The connection is
done through a standard plug 2.1 mm x 5.5 center positive. It is recommended that your power supply
be a switching power supply that will protect the power supply in the event of over current or short
circuit.
5
mySTEM Project Board
For higher voltages, (26 Volts Max), and currents, (4 Amps max), you should use the Screw Terminals to
supply power and use a separate DC power supply as shown below.
The alternate power supply connections are labeled GND and SV+. The SV+ (Supply Voltage) is
connected to the Positive (red) terminal of the power supply connector which is the closest terminal to
the switch, while the GND terminal is connected to the Ground (black) terminal of the power supply
connector. AC adapters, and voltage transformers, are critical safety components.
mySTEM Project Board
6
mySTEM Project Board
IMPORTANT! Damage may be caused by use of improper rated or incompatible devices which can
result in damage or destruction of the mySTEM™ Project Board, and/or powered equipment, as well
as the risk of electrical shock or electrocution in certain cases. Studica will not be held responsible for
damage to equipment, blown electronic parts, or personal injury that may result from the use of this
material.
You should also be cautious when using higher currents as significant heating will occur in the controller
output chips U1 and U2.
To reduce the risk of fire, electrical shock, or damage to the unit, do not expose this unit to rain or
moisture or immerse in water. Short circuits on the outputs will cause excessive heating of the output
chips. Be sure you have wired your outputs correctly before turning on the power to the board.
The On/Off switch on the corner of the board controls power to the logic circuits and will not disconnect
the DC power. When making circuit changes the power should be disconnected from the board.
myDAQ Connections
Signals are passed to the myDAQ through the five Quad Point Contact Blocks. These blocks behave
similar to the breadboard. There are four interconnected holes that make up a node. The five blocks are
from left to right: Voltage sources, Analog Output, Analog Input, and two blocks of Digital Input/Output.
For a full discussion of these see the manual for the myDAQ found at
http://www.ni.com/pdf/manuals/373060e.pdf.
7
mySTEM Project Board
Breadboard
The 400 pin breadboard on the face of the mySTEM™ is utilized to build and configure temporary
circuits. A frequent use is for sensor connections. The picture below shows the surface of the
breadboard. Some of the pins are connected under the board by metal strips to make connections
between components convenient. These strips connect the holes on the top to form nodes. In the
picture below you can see the matrix of holes. ABCDE and FGHIJ describe five holes that line up in each
column. The columns are numbered. Circled are the two nodes found on Column 4. ABCDE in Column 4
are connected to each other. FGHIJ in Column 4 are connected to each other. The plastic grove running
down the center of the board separates the two nodes and prevents electrical conduction. On this board
there are 60 nodes. Each node is separate from all the other nodes.
On the outside of the board are two power rows. While the electrons do not care what the color of each
row is, general convention calls for the red rows to be used for the + or positive voltage on the board,
with the blue rows be used for the common ground row. If you learn to stay with color conventions
others will understand your wiring scheme and it will help you eliminate errors.
mySTEM Project Board
8
mySTEM Project Board
Output connections
The output screw blocks are labeled according to channel.
The blocks are labeled Output1-Output4. The polarity can be reversed if so desired to allow for reversing
the current through the output device.
At the end of the output blocks is a connection where the supply voltage (SV) and ground (GND) are
available for testing output devices.
9
mySTEM Project Board
Connecting Signals to the Outputs
There is a 12 pin connector next to the 400 pin breadboard for making connections to the output
channels. Output1 is controlled by the two pins En1 (Enable 1) and Dir1 (Direction 1). Output2 is
controlled by the two pins En2 (Enable 2) and Dir2 (Direction2) … and so on.
Output control signals on the mySTEM Project
Board.
Printout of the Output
Control Signals
To power an output channel you need to provide a digital high (3.3 to 5V) to the enable pin of the
channel. In the picture below a motor connected to output 1 is turned on by providing a jumper wire
from 5 V to En1. When the board is powered and turned on this jumper wire will turn the current on to
the output 1. The direction has a default setting so if you do not need to control direction you only need
to provide the digital high to the Enable of channel 1.
If you desire the motor to change direction you need to provide a second signal. Since the motor is
defaulted high on the direction you need to provide a digital low to the direction pin to have the output
channel reverse polarity. In the picture below the white jumper wire is added from the GND pin to the
Dir1 pin. The motor should spin the other way.
mySTEM Project Board
10
mySTEM Project Board
Try hooking up a motor to Output 1 and running a jumper wire from 5V to En1. When the board is
turned on the motor will spin. Add the jumper wire from GND to Dir1 and the motor will instantly switch
directions.
Computer Control of Outputs
NI Labview is a graphical programming environment that has been built specifically for engineers and
scientists with the intent of making them more productive and ensuring that they have all the tools they
need to prototype, design and build their applications. You can develop sophisticated measurement,
test, and control systems using intuitive graphical icons and wires that resemble a flowchart. LabVIEW
offers unrivaled integration with thousands of hardware devices and provides hundreds of built-in
libraries for advanced analysis and data visualization – all for creating virtual instrumentation. LabVIEW
relies on graphical symbols rather than textual language to describe programming actions.
Labview programs are called Virtual Instruments because their appearance and operation imitate actual
instruments, however they are analogous to main program, functions and subroutines from popular
computer languages such as C.
Connect your mySTEM™ Project Board to the myDAQ and connect the USB cable to your computer.
Now disconnect the input wires from 5V and GND and move them to the Digital Input and Output
section (DIO). Use DIO 0 for En1 and DIO 1 for Dir1. See the connections in the pictures below.
11
mySTEM Project Board
Launch the NI ELVISmx Instrument
On your computer launch the NI ELVISmx Instrument Launcher. It is found in the Start Menu>>All
Programs>>National Instruments>>NI ELVISmx for NI ELVIS & NI myDAQ>>NI ELVISmx Instrument
Launcher.
This brings up the instrument launcher. From the menu select the DigOut icon.
This launches the Digital Writer. You can set the “Lines to Write” to 0-3. Select run at the bottom of the
window. When you push the switch to HI for DIO 0 you will see the motor turn on and an LED on the
screen to let you know that DIO 0 is on. You can now change direction by taking the DIO 1 switch and
move it to the HI setting. You will see the motor reverse direction. Be sure that the DIO 0 is returned to
the LO position before stopping the VI with the stop button. If it is not turned off before you stop
running the program the motor will keep running. If you accidently stop the program with the motor
mySTEM Project Board
12
mySTEM Project Board
running you can select run button again and then stop the motor moving the switches to LO before
stopping the Digital Writer.
In the following exercises you will learn how to plan programming, program structure, analog and digital
inputs, configuring sensors, programming structures and charting data. It is hoped that you will be able
to create your own systems that can monitor inputs and control outputs to create complex cybermechanical systems.
13
mySTEM Project Board
Setting Up the Labview Interface
Open Labview and start a new VI.
From the Window pull down menu select Tile Left and Right. This toggles the two screens, the Front
Panel and the Block Diagram, so they are side by side. Another way to do this is with a keyboard
shortcut. On your computer keyboard hold the Ctrl key down while striking the T key
On the Front Panel select the Controls Palette the View Menu.
This launches the controls palette which provides you with a method of placing various controls and
indicators on the front panel. Everyone’s tastes are a little different so once you are familiar with the
commands and where to find them you will find yourself customizing the Palette. Until then you will
need to see certain ones as you work through the exercises.
mySTEM Project Board
14
mySTEM Project Board
Select the down arrows at the bottom of the Controls pallet.
Once everything is visible you will see the Customize icon at the top of the Controls Pallet. To turn the
palettes on and off you will need to select Customize at the top of the Controls Palette.
Select the option for “Change Visible Palettes.
15
mySTEM Project Board
Select at least the Modern and Express. Select OK. These palettes will then always show when you right
click on the front panel.
Once you have finished setting up the Front Panel move to the Block Diagram Window and select the
Functions Pallet from the View Pull down menu.
This launches the Functions palette which provides you with a method of placing various controls and
functions on the Block Diagram. Everyone’s tastes are a little different so once you are familiar with the
commands and where to find them you will find yourself customizing the Palette. Until then you will
mySTEM Project Board
16
mySTEM Project Board
need to see certain ones as you work through these exercises. Select the down arrows at the bottom of
the Functions pallet.
Once everything is visible you will see the Change Visible Palettes icon at the bottom of the Functions
Pallet. To turn the palettes on and off you will need to select Change Visible Palettes at the bottom of
the Functions Palette list.
You will need to check Programming and Express to follow the commands in the following exercises.
Select OK when you are done.
17
mySTEM Project Board
Beginning Labview Programming
Right click on the Front panel and select the Boolean pallet from the Modern pallet. On the Boolean
pallet select the Round LED and drag it to the Front panel.
You will see the LED on the front panel. Hover over the led and you should see some blue grip points on
the LED.
Left click and hold on one of those points and drag the corner to resize the LED.
This process will work on many of the components you place on the front panel.
mySTEM Project Board
18
mySTEM Project Board
For labels of the components you need to left click to select the text.
Once it is selected you can double click to select the text.
You can now rename the indicator to something that makes sense.
Once you are happy with the name you can resize the text by highlighting the text box again and
selecting the Font menu from the top of the screen.
19
mySTEM Project Board
From the dropdown menu select the size of the text you want.
When you are done you might only have some of the word showing.
Hover over the text and grab one of the blue points and stretch the box to show all the contents.
mySTEM Project Board
20
mySTEM Project Board
Return to the Boolean pallet found in the controls pallet. Select a Vertical Slide Switch and drag it to the
front panel.
Resize the switch and lettering to make it easy to find.
You should now have a switch and an indicator on the front panel.
Depress your ctrl key and the letter T at the same time. This is a shortcut to toggle the Front Panel and
Block Diagram so they are both visible. The front panel is where the user interacts with the program.
The Block Diagram controls the program flow. On the Block Diagram you should see the output and
21
mySTEM Project Board
switch showing. When you renamed them on the Front Panel the naming carried over to the Block
Diagram.
We need to connect the switch to the output. You can accomplish this by hovering over the output of
the switch and you will see what looks like a spool of wire. Click on the output of Switch 1 and then click
on the input terminal of Output.
It should look like the picture below when you are done.
We can now see if this simple program works.
On the front panel select the Run Continuously.
mySTEM Project Board
22
mySTEM Project Board
Once the program is running you can click on the switch and it will toggle and you should see the output
change with the position of the switch. The Boolean logic of the switch is passed to the LED.
Select the Stop button (Abort Execution) to shut the program down.
Introduction to Sensors- Voltage Divider
Sensor is the generic name given to group of devices that can monitor either the absolute value or a
change in the physical quantity and translates the value or change into a useful signal. A sensing system
is comprised by the sensor, data gathering and signal processing components. It is used to monitor,
make decisions and issue feedback to programs that control automated machinery. There are almost
countless varieties of sensors available that can measure anything. In short anything that can gather
information can be called a sensor.
Digital sensors are those transducers that provide an output that is one of two states: high or low, open
or closed, Logic 1 or Logic 0. Digital inputs are the easiest to deal with in programming. There are two
23
mySTEM Project Board
types of sensors you can utilize. They are loosely called active and passive. Passive sensors such as
switches cause a change in state when pushed or excited. No additional power is required. Active
sensors need their own power supplies and a common ground with your data acquisition device.
For the myDAQ to utilize a digital input you need to understand what the myDAQ sees as a high or low.
Electronic equipment utilizes threshold values to determine what is high and what is low. National
Instruments reports that to be read as a low the value must be below .8V. The High must be at least
2.0V. Values in between might be read as either high or low and should be avoided. To have the myDAQ
recognize a signal as a high or low we must be sure that it has the correct voltage input. Free floating
inputs are not recommended as they might be read as either high or low.
To utilize the digital inputs you need to understand the basics of a voltage divider circuit. This exercise
will help you see how to configure a switch to be read by the myDAQ and provide you with the correct
logic level. A voltage divider is a simple linear circuit that produces an output voltage that is some
fraction to the input voltage.
Begin with setting up the following circuit.
Using the basics of Ohm’s Law we know that current in the circuit can be calculated by dividing the
voltage potential by the resistance. Even resistors of the same resistance will have slightly different
resistances so you can double check the circuit by measuring the resistance of the 10K resistor. If you
are in doubt how to measure voltage, resistance and current see http://www.ni.com/whitepaper/11432/en/.
mySTEM Project Board
24
mySTEM Project Board
The 5 V power supply can come from the pin header on the board. You can use the 5V and GND
connections from either end of the pin header.
Place the 10 K resistor so it is inserted into 2 nodes on the breadboard. Bring the wires from the supply
voltage and place 5V at one end of the resistor and the GND at the other end. Turn on the power to the
board and then measure the voltage drop across the resistor. The Voltage dropped across the resistor in
a series circuit is called an IR Drop. The circuit below only has one resistor so the entire voltage is
dropped across the resistor. Measure the voltage across the resistor.
25
mySTEM Project Board
Now add a second resistor. The resistors will join by placing an end in the same node as shown in the
picture below. The GND wire has been moved to the end. There are now two places for an IR Drop.
Measure the voltage from end to end similar to the picture below.
Measure the voltage across the first resistor, similar to the photo below. What relationship does it have
to the total voltage?
Measure the voltage drop across the second resistor. How does it compare to the first? If you had used
different value resistors how would that have affected the voltage drops?
A good explanation of the mathematics and theory involved is found on the All About Circuits site.
http://www.allaboutcircuits.com/vol_1/chpt_5/2.html
mySTEM Project Board
26
mySTEM Project Board
Switches
Switches are installed in circuits to control the flow of electrons through the circuit. They are categorized
by the way they are actuated, by the number of poles and throws they have and their normal position.
The actuator is the mechanical method that causes the switch to open and close. Common types include
momentary, toggle, slide, rocker etc. A normally open switch is one where the circuit is open in its
normal position and the actuator has to be triggered in order to close the circuit and allow current to
flow. A normally closed switch is one where the current can flow unless the actuator causes the switch
to open blocking the current flow.
Poles provide the path for electrons. Throws control the circuits. The schematic below represents a
single pole single throw switch (SPST). It provides a single path for electrons and controls one circuit.
The basic fischertechnik switch is a Single pole double throw switch. It has a single pole for electrons but
two different paths. The schematic is shown below.
The picture below shows the actual Fischertechnik switch. It is a momentary switch which means
depressing the actuator causes a temporary changing of the path. As soon as you let go it reverts to its
original position.
With the cover removed the internal components are visible. The number 1 connection is the middle
contact. You can see that it is in contact with the contact with the number 2 connection making the 1 &
2 normally closed and the 1 &3 normally open. When the button is pushed the connection between 1
27
mySTEM Project Board
and 2 is opened and the connection between 1 and 3 is closed. This is a temporary connection as the
spring will return the switch to its normal position as soon as the pressure is released.
To see how the switch is used in the voltage divider we can replace one of the resistors with a switch. In
the picture below red and green flat plugs are attached to the ends of the jumper wires. This will allow
them to be easily attached to the Fischertechnik switch. The switch is a single pole double throw
momentary switch. Momentary means as soon as you take the pressure off the switch it returns to its
original position. The switch can be used in the normally open or normally closed mode.
The picture below has the jumper wires connecting pin 1 and pin 3. This is the normally open position of
the switch.
mySTEM Project Board
28
mySTEM Project Board
The switch replaces the second 10K resistor.
Measure the voltage across the resistor and switch. You should see the 5V applied. While measuring the
voltage depress the red switch toggle. Does this change the voltage?
Now measure the voltage across the resistor. Depress the switch again. Does this change the voltage?
29
mySTEM Project Board
We are interested to see the voltage on the Signal Out pin. In the picture below you will see the voltage
being measured across the switch. Depress the switch. Does the voltage change?
When the switch is open you have the equivalent of an infinite value resistor. The 10K in series with the
infinite value resistor hardly has an effect on the voltage drop across the entire circuit so you are seeing
the equivalent of the logic Hi. When the switch is depressed you have a resistor of almost no resistance.
At that point the majority of the voltage drop occurs across the 10K resistor so it provides the equivalent
of a logic low.
There is a special name for a resistor utilized in this manner. Because the resistor is attached to the plus
voltage and is used to hold the input at a logic high it is a called a pull up resistor. Its function is to pull
the input to a high state. When the switch is closed it causes the input to see a logic low. If the wiring is
reversed with the resistor between the switch and ground then it becomes a pull down resistor as it
holds the input at a low until the switch closes and allows the 5V to be seen as a logic high.
Now that you can wire a switch to be read by the myDAQ you should learn how to configure an input to
read the value. See the exercise on the Digital Input Express VI.
mySTEM Project Board
30
mySTEM Project Board
Digital Input: Express VI
Before beginning this exercise, be sure you understand how a pull up resistor is utilized with a switch or
other sensor to allow for logic voltage to be seen at an input. This is covered in the exercise on the
Voltage Divider for Digital Circuits.
Digital sensors are those transducers that provide an output that is one of two states: high or low, open
or closed, Logic 1 or Logic 0. Digital inputs are the easiest to deal with in programming. There are two
types of sensors you can utilize. They are loosely called active and passive. Passive sensors such as
switches cause a change in state when pushed or excited. No additional power is required. Active
sensors need their own power supplies and a common ground with your data acquisition device. The
program you are writing will need to import the data you are sensing from the outside world. To
accomplish this, the program has a special function to read from the Digital Input/Output (DIO) pins.
The Circuit
Wire the following circuit using a pull up resistor and a switch to provide input to DIO 0
When you are done it will probably look something like the picture below. The five volts is coming from
the pin header. You can use either of the 5V outputs. The 5V is connected to a 10K resistor and the 10K
resistor is connected to pin one of the fischertechnik switch. Pin 3 of the switch is connected to either of
the GND connections on the pin header.
31
mySTEM Project Board
In the picture a yellow wire is used to connect the junction of the 10K resistor and the switch to the DIO
0 pin header. The end of the resistor and both wires are in the same node on the breadboard.
Writing the simple program
Now that the screen is set up we can build a simple program to read an input. You must have the
myDAQ connected to your computer with the USB cable for this to work.
On the block diagram right click to bring up the Functions pallet. Select the Express option to bring up
the Express pallet.
mySTEM Project Board
32
mySTEM Project Board
From the Express pallet select Input.
From the Input pallet select the option for DAQ Assist.
Place the block on the block diagram. The hand will allow you to move it anyplace on the screen. When
you are happy with the placement click to release the block.
33
mySTEM Project Board
This block is an Express VI. This means that much of the configuration is already done for us and we
need to provide some information to complete the action. When the “Create New…” screen comes up
expand the Acquire Signals menu and then the Digital Input menus so you can select the Line Input
option.
This will bring up the Supported Physical Channels dialog box. Since we connected our input to DIO 0 we
will select that one from the list.
mySTEM Project Board
34
mySTEM Project Board
Once you select the option for port0/line0 you will see the Finish button be enabled. Select Finish. Be
patient as it will take a while for it to finish building.
Once it has finished building the DAQ Assistant will show you the channel. To test your input select Run
at the top of the DAQ Assistant.
35
mySTEM Project Board
With the mySTEM™ Project Board powered on you will be able to read the input as you toggle the
switch. The DigitalIn LED will light when it detects a Logic High and be off when it sees a logic low. Once
you are sure it is working you can select Stop from the menu at the top of the DAQ Assistant.
Look for the OK button at the bottom right corner of the dialog box. It sometimes hides off screen and
needs to be dragged onto the screen so you can see it.
mySTEM Project Board
36
mySTEM Project Board
Once you say OK it will take a while to build the Block, be patient one more time.
You will know it is done when you see the DAQ Assistant block diagram with the Data port showing. This
port is where the information from the sensor is showing.
We want an indicator on the Front panel to show us the status of our push button switch.
Right click on the Front panel and select the Boolean pallet from the Modern pallet. On the Boolean
pallet select the Round LED and drag it to the Front panel.
37
mySTEM Project Board
You will see the LED on the front panel. Hover over the led and you should see some blue grip points on
the LED.
Left click and hold on one of those points and drag the corner to resize the LED.
This process will work on many of the components you place on the front panel.
For labels of the components you need to left click to select the text.
Once it is selected you can double click to select the text.
You can now rename the indicator to something that makes sense.
mySTEM Project Board
38
mySTEM Project Board
Once you are happy with the name you can resize the text by highlighting the text box again and
selecting the Font menu from the top of the screen.
From the dropdown menu select the size of the text you want.
39
mySTEM Project Board
When you are done you might only have some of the word showing.
Hover over the text and grab one of the blue points and stretch the box to show all the contents.
You should now see the LED show up on the Block diagram.
If you try to connect the data pin to the output you will see the program give you a visual clue that you
cannot connect these two terminals.
This is the most common of errors in the Labview programming environment. There is an additional step
we need to do before we can see the output on the screen. The DAQ Assistant builds an array of data
mySTEM Project Board
40
mySTEM Project Board
that it provides the rest of the program. The LED only wants a Boolean input. It cannot decide what to
do with the data. For a complete explanation see the exercise Introduction to Arrays.
For now we will add one block so we can pick the information we wish from the DAQ Assistant.
From the Functions pallet select the Array pallet from the Programming pallet. On the Array pallet
select the Index Array block.
Place the block on your screen. Hover your cursor over the lower left hand corner and you will see the
Index window show.
Right click and select the option to Create and then select Constant.
41
mySTEM Project Board
Once you select the constant it will appear on your screen with a 0 in the box. This is what we need.
Now wire the blocks together so they resemble the picture below.
The information is passed from the DAQ Assistant to the Index Array block. The Index Array block is
selecting the first block of information and passing the output to our output LED.
Test the program by selecting the Run Continuously button.
If you have set this up correctly you will see the LED on the front panel react to the switch to show you
the logic level being delivered.
Stop the program. Rewire the Fischertechnik switch so your wires are connected to terminals 1 and 2.
This is using the switch as a normally closed switch. Run the program continuously again. How does the
output of the LED differ from your first wiring?
Save your program as we will use that again when we learn to configure outputs.
mySTEM Project Board
42
mySTEM Project Board
Introduction to Programming Structures:
The mySTEM™ Project Board needs to talk to the Labview program you write to know when to turn on
and off an output. Before we learn to turn on an output it is important to learn how to turn it off first.
There are two programming structures you need to learn so you can be sure your output is turned off
before exiting your program. In this exercise you will learn those structures and see how they operate.
Once you have mastered the structures you can then learn how to configure an output to run larger
current devices. In a previous exercise you learned how to configure an input and hooked a switch up to
DIO 0. Open the saved file from that exercise. It should look similar to the one below.
Hook up your myDAQ to the computer and connect the mySTEM™ board.
When you ran this program after you wrote it you selected the run continuously button to launch it.
While this works on very simple programs it is very limiting. The first structure we will explore is called a
While Loop. This forces a program to repeat an instruction until some condition is met. The first step is
to place a while loop on the Block Diagram.
Right click on your block diagram to access the functions pallet. From the Programming pallet you will
select the Structures pallet. On the Structures pallet you will select the While Loop.
43
mySTEM Project Board
Instead of a block you will get a strange looking icon where your mouse is. Start above and to the left of
the program structure and then click and drag until you are below and to the right of the program blocks
you already have.
You will have traced a dotted box around your program.
Once you click on the screen below and to the right of the last programming block you will see the
structure appear.
In the lower right hand corner you will see the conditional terminal. In the picture above the conditional
terminal is the “Stop if True” condition. The condition behavior can be changed by right clicking on it and
mySTEM Project Board
44
mySTEM Project Board
selecting another option. The default condition is acceptable. We need to create a condition for the loop
to stop. Right click on the front panel and select the Boolean Pallet from the Modern Pallet.
From the Boolean pallet select the Stop button and place it next to your output LED.
Once placed select the button and drag it to the desired size.
45
mySTEM Project Board
Once you have the button resized you can then resize the text.
Back on the Block Diagram you will find the stop button. Drag it close and then wire it to the conditional
terminal.
mySTEM Project Board
46
mySTEM Project Board
Now the program is run by selecting just the Run button.
You can toggle your switch to see the output change. After you see it work select the stop button. The
program should end. As long as we only have the LED on the front panel as our output it doesn’t really
matter what state it is in when the program ends.
Run the program again and try to stop the program with the LED in the on status. In the picture above
you see the LED was on when the program stopped. If this had been a motor it would stay running
when you select stop. This could be a dangerous situation.
To be sure we always are turning off the output we need to provide a structure that allows us to run a
program and make decisions but when we hit the stop button everything stops. When you think about
this there are really two cases for behavior. One case when the stop button is not pressed and gives us
a false Boolean output, and the other when we press the stop button and it gives us a true output. The
structure we will use is called a Case Structure.
47
mySTEM Project Board
Create some room inside the While Loop by clicking on the loop and using the blue drag boxes.
Unwire the output by clicking on the wire and then selecting the delete button on your keyboard.
Right click on the block diagram and select the Structures pallet from the Programming pallet. On the
Structures pallet select Case Structure.
mySTEM Project Board
48
mySTEM Project Board
Drag the structure around the DAQ Assistant and Index array blocks.
When you let go you will see the structure in place.
The top case is true and that is where your blocks appear. If you think about the stop button, the
program should stop completely when it is pushed and the Boolean is true. We need to move the DAQ
Assistant and Index Array blocks to the False case. The easiest way to do that is to right click on the case
outline and select the option for “Make This Case False”.
Once the case is false we will wire the Index Array Block to the output through the wall of the case
structure.
49
mySTEM Project Board
Now switch to the True case by selecting the down arrow next to false and selecting the true option.
You will see that the True case is empty and there is a wiring tunnel in the side of the True case. Right
click on the block and select The Boolean pallet from the Programming pallet. Select a False Constant
from the Boolean pallet.
mySTEM Project Board
50
mySTEM Project Board
Place this in the True Case structure and wire it to the tunnel connection.
The case structure needs an input on the left side so it knows whether to run the True case or the False
case. Wire this input from the stop button.
Once this is wired run the program again by selecting the run button. Now try to stop the program with
the LED in the on state. You will notice no matter what position your switch is in, when you click on the
stop button the LED shuts off. Using these two programming structures together will allow you to safely
control motors and other output devices and know they will be turned off when you hit the stop button.
Save this program and we will adapt it to run a motor.
Once you are comfortable with the structures you can move on to the exercise on Creating a Digital
output.
51
mySTEM Project Board
Digital Outputs: Sending Signals to Devices:
The mySTEM™ Project Board needs to talk to the Labview program you write to know when to turn on
and off an output. Before we learn to turn on an output it is important to learn how to turn it off first.
There are two programming structures you need to learn so you can be sure your output is turned off
before exiting your program. Once you have mastered the structures you can then learn how to
configure an output to run larger current devices. If you have not completed the exercise on the
Introduction to Basic Structures you should complete that before attempting to configure an output.
Make another set of jumper wires with the red and green flat plugs connected to one end. Connect the
Fischertechnik motor to Output1 on the mySTEM™ Project Board.
The Fischertechnik motor included with the board is a DC motor inserted into a case with slots and
electrical connections built in. This allows the motor to be connected to hundreds of different
components used in the design of cyber-mechanical devices.
mySTEM Project Board
52
mySTEM Project Board
The picture below shows the motor both in and outside of the case.
The motor itself consists of two permanent magnets in a case which establishes a magnetic field
between them.
Inside the magnetic field we place a shaft wound with wire that is free to Rotate. This shaft is called an
armature. Current passing through the wire of the armature causes a creation of a magnetic field. The
wire is wound around a series of segmented plates of silicon steel to concentrate the magnetic fields.
53
mySTEM Project Board
mySTEM Project Board
54
mySTEM Project Board
The current passes through brushes which are the two pieces in the red circle on the left. These brushes
contact the commutators on the armature allowing the armature to rotate in the magnetic field.
This setup allows a motor to run in two directions depending on the polarity of the connections. The
mySTEM™ Project Board allows for the control of the direction of the current allowing the user to select
the direction of the motor spin when desired.
Wiring in the Motor
Run a jumper wire from DIO 1 to the EN1 on the Pin Header.
55
mySTEM Project Board
Setup the voltage divider using the 10K resistor and switch from the Digital Input activity. Wire the signal
to the DIO 0 pin.
Open the program you saved after completing the Introduction to Structures activity.
The block diagram should resemble the one pictured here with both the While and Case Structures
Loops.
mySTEM Project Board
56
mySTEM Project Board
57
mySTEM Project Board
Create a little more room by extending the right side of the While Loop.
Right click on the block diagram and select Express from the Functions pallet. Select the Output pallet
from the Express pallet. Select the DAQ Assist from the Output pallet.
Place the DAQ Assistant inside the While Loop similar to the picture below.
mySTEM Project Board
58
mySTEM Project Board
In the Create New dialog box Expand the Generate Signals and then Digital Output sections to find the
Line Output.
In the Supported Physical Channels select port0/Line1 option and select Finish.
59
mySTEM Project Board
This will bring up the DAQ Assistant dialog box. With the board plugged in and turned on select the Run
at the top of the DAQ Assistant.
Once the DAQ Assistant is running click on the radio button above the DigitalOut label. If you are
hooked up properly the motor should turn on.
Be sure the motor is turned off before you hit the Stop button. If you accidently hit the stop button
without unchecking the DigitalOut radio button you will have to run the DAQ Assistant again to shut off
the output.
mySTEM Project Board
60
mySTEM Project Board
In the Settings area in the DAQ Assistant there is a check box for Invert Line. Place a check in the box.
Run the DAQ Assistant again. Click on the radio button on the DigitalOut again. How does this behavior
differ from the when the box was not checked. Be sure the motor is off before stopping the DAQ
Assistant.
Once the DAQ Assistant is off uncheck the Invert Line check box to unselect the Invert Line option and
click the DigitalOut radio button to clear the input.
When you are done Select the OK button at the bottom right hand corner of the DAQ Assistant dialog
box.
You will see the notification that it is building the VI.
61
mySTEM Project Board
Once the VI is complete arrange it so your program looks like the picture below.
We can Rename the DAQ Assistant2 by clicking on the words and removing them. Enter a descriptive
name. The example below has named the DAQ Assistant2 to OUTPUT.
We need to connect the data to OUTPUT. Since this is a DAQ Assistant and can handle many outputs at
once the data has to be in an array format. If we try to wire without creating an array we will see the
wiring error.
To allow us to connect we need to change the Boolean information to an Array of Boolean information.
mySTEM Project Board
62
mySTEM Project Board
From the Functions pallet select the Programming Pallet. On the Programming Pallet select the Array
pallet. On the Array pallet select the Build Array block and place it on the block diagram.
Once placed it will look like the picture below.
You can now wire in the information to the data input of the OUTPUT block.
63
mySTEM Project Board
If we look very closely at the data flow from the input to the output we will see subtle differences in the
sizes of the wire. In the labeled diagram below you can follow the data. The data in the array is in the
thicker green lines. The Boolean Data is in the narrow green lines.
Now it is time to see if our program will run. With the myDAQ connected to your computer and the
mySTEM™ Project Board connected and powered, select run at the top of the window. As you toggle
the switch the motor should run and shut off.
When you hit the Stop button the motor and the program should shut down.
Save your program.
Adding Reverse Direction
We are going to add a second output to our program so you can see how the build array works.
Double click on the OUTPUT Block. This will bring up the DAQ Assistant dialog box again. Select the blue
+ sign on the Configuration Tab.
mySTEM Project Board
64
mySTEM Project Board
This will bring up the Supported Physical Channels box again. Add port0/line2 to the task and select OK.
You now see two tasks in the list. It will be confusing unless we name them something that means
something to us.
Right click on the DigitalOut_0 and select Rename from the options.
65
mySTEM Project Board
In the dialog box type a distinct name for what the task is. In the example below the channel name has
become Direction1. Select OK.
Repeat the process renaming the DigitalOut to Enable1 and select OK. Now the two tasks have unique
names that relate to what we want them to do.
Select OK from the bottom right hand corner of the DAQ Assistant window and allow it time to rebuild.
On your front panel select the Modern pallet from the Controls pallet. From the Modern pallet select
the Boolean pallet. From the Boolean pallet select the Vertical Slide switch and place it on your screen.
mySTEM Project Board
66
mySTEM Project Board
Resize and rename the switch. In the picture below it was named Direction.
On the block diagram find the Direction block and arrange it to resemble the picture below. You might
have to do some rearranging to make it fit.
Hover over the Build Array block and drag the blue grip point downward.
67
mySTEM Project Board
Pull slowly and stop when you have a second section on your Build Array block. The enable data is going
into the first block. We can feed the Direction data into the second data entry point on the Build Array
block.
The OUTPUT knows that DIO 1 will be connected to the first element in the array and the DIO 2 will be
connected to the second element in the array. Wire the Direction block to the second element in the
Build Array block.
Run a jumper wire from DIO 2 to Dir1 on the pin header.
mySTEM Project Board
68
mySTEM Project Board
You now have an onscreen switch on your front panel that will allow you to control the direction of the
motor. To enable the motor you must press the Fischertechnik switch. Connect the board to power and
run the program. Hold the fischertechnik switch so the motor is running. Slide the direction switch to
the other position. What happens to the motor?
Save your program.
Designing Programs
There are a number of ways to design programs. We present two different ways here. It should be
noted there is no one correct or perfect way to solve these problems. The following exercises are
presented in order to help you organize your thinking.
Flow Charts
Flowcharts are a graphic representation of an algorithm, often used in the design phase of programming
to work out the logical flow of a program. Flowcharts use simple geometric symbols and arrows to
define relationships between elements. This visual representation of the flow of a process helps
organize thinking. The program designer knows where decisions need to be made and can identify what
processes are conducted and in what order. Flowcharts are also used in other design work to explain
complex processes and as an aid in quality control. This activity will introduce you to flowchart symbols.
While there are numerous symbols used by professional programmers this exercise will concentrate on
the ones used most often. You should familiarize yourself with the basic shapes and what they
represent.
The Terminator block is used to indicate the Start or End of a program.
The process block represents a Process that occurs. This might be turning a motor or lamp on, getting
the value of a variable or setting input or output pins.
69
mySTEM Project Board
The Decision block is used to branch the program after comparing variables or checking the position of
switches.
Data blocks are used to assign variables and allow us to set parameters. This shape is also used for
assigning inputs and outputs to variables as well as defining delays.
Blocks are connected by arrows called Flow Lines which show how the blocks connect together.
Review the flow chart that follows. Step through it to follow the logic it is mapping out.
mySTEM Project Board
70
mySTEM Project Board
What is the eventual course of action if it is the weekend?
If it is not the weekend and you missed the bus what is your next action.
Conclusion:
Using the information from the flowchart section above prepare a flow chart for each of the following
problems and attach them to this sheet.
1. Create a flow chart for placing toothpaste on a toothbrush and then brushing your teeth for 45
seconds.
2. Create a flowchart for creating a peanut butter and jelly sandwich.
3. Create a flowchart for helping a three-year-old child put on their jacket.
State Machines
State Diagrams are graphical representations of how systems sequentially behave. They depict the flow
of control using states and transitions. State Diagrams describe a system as a series of States which
perform an activity or wait for an event to occur. The system can only exist in one state at a time. The
system executes the current state until a change is initiated by a triggering event or condition that will
cause a transition to another state. State machines are used to design programs and sequential logic
circuits. Understanding how to draw state machines will help solve more complex programming
problems. Since there are many ways to approach any problem state machines can define a system and
71
mySTEM Project Board
allow the programmer to focus on transitions and guarding actions. This exercise will help you
understand and create state machines to help you design programs to control models, robotics, and
experiments.
There is a graphical language used in state diagrams. Below are the simple graphics and what they
represent:
mySTEM Project Board
72
mySTEM Project Board
A simple example of what you might create to explain a motion sensing light with a photoelectric eye.
This would turn the lights on when it was dark and motion detected. It would recheck every 15 minutes.
You can clean up complicated diagrams like the one below by nesting them, creating separate state
diagrams for each section. This makes them easier to read.
Before and After images of the same diagram. The nested one below allows for better organization.
73
mySTEM Project Board
Conclusion:
Translating diagrams into Labview programming is fairly easy. For example a case structure used to shut
down all the motors found in the Introduction to Programming Structures allows for a switch to change
between one state and another. When the Boolean signal goes from low to high you change states.
Before attempting a difficult program you should get some experience creating state diagrams.
1. Create a state diagram for the process of buying lunch.
2. Create a nested state diagram for the systems in a car. You might include the starter,
transmission, acceleration and breaking.
Open Loop Programming:
Basic systems consist of an input, a process and an output. These simple systems are called open loop
systems because the system cannot interact with the world. For example the clothes washer has no idea
if the clothes are clean or not. The cycle runs for a time and then stops. Understanding how open loops
control actions is the first step in learning programming.
This exercise utilizes parts found in the Do Engineering Basic Kit available from Studica. The components
are listed below.
Rack and Pinion 60
(3)
Building block 15 with 2 pins
(2)
Base Plate
(1)
Motor Rack Gearbox
(1)
Building Block 30
(7)
S Motor
(1)
Flat Plug Red
(6)
Flat Plug Green
(6)
Cable Clamp
(5)
The components are assembled as shown below. There are seven of the building block 30s that allow
the rack gears to be aligned in a row. The two 15 mm blocks with the two pins hold the assembly up in
the air. Electrical wiring should be organized in any model you construct. The cable clamps allow the
wire to be supported and out of the path of the motor. Be sure you leave enough wire so the motor and
gear box can travel from end to end of the rack gear.
mySTEM Project Board
74
mySTEM Project Board
The gear box will lock upon the rack gear when the motor is engaged. Pull the motor up slightly to
release the gear before moving the assembly by hand. The picture below shows the motor in both
positions. On the left you can see the worm gear on the motor as it is not engaged with the gears. On
the right the motor worm is all the way down and the assembly should not move unless you power the
motor. Damage will result when the motor and gearbox are forced.
75
mySTEM Project Board
Wiring this exercise is fairly simple. The picture below shows the wiring necessary.
The motor wires are connected to Output1 on the board.
mySTEM Project Board
76
mySTEM Project Board
The motor is controlled by two signals. Enable 1 turns the motor on and is connected to DIO1. Direction
is controlled by DIO0. The picture below shows the jumper wires going from the DIO section to the pin
header for the output channels.
The Program
Below is the state diagram for the Open Loop programming.
77
mySTEM Project Board
In the state diagram the first decision that needs to be made is the state of the stop button. If it is not
pressed then the first nested diagram is run. if it is then the program should shut down the output to
the motor and close the program. The program should run except for that one condition. If it is not
pressed we then look at the nested states. This program will use time to control the motor. The
program will not know where the motor is on the rack gear and it will run off the track if you are not
careful. Be sure there is enough wire to run off each end of the rack gear so you have time to shut the
motor down if you need to.
You should complete the exercises on Programming Structures and Digital Outputs before attempting
this exercise.
Begin a new Labview Virtual Instrument (VI).
Place a While Loop on the screen from the Structures pallet. This will continuously run the various
states placed inside it until a true condition is fed to the conditional terminal. Wire a stop button to the
conditional terminal.
Place a case structure from the Structures pallet inside the while loop to create the structure needed to
control the motor. Wire the All Stop button to the case selector. This will select state True when the All
Stop button is pressed.
When the All Stop button is pushed we want the motor to stop. Since the motor has both an enable
signal and a direction signal being used (DIO 0 and DIO 1) both of these pins should be set to provide a
mySTEM Project Board
78
mySTEM Project Board
digital 0 when the All Stop button is pressed. In the True case place an Output DAQ Assistant. In the
dialog box select Generate Signals, Digital Output and select Digital Output, Line Output, and select
port0/line0 and port0/line1. Do this by holding your control or shift key down while you select them
one at a time. When both are highlighted select the finish button at the bottom of the dialog box. Select
OK at the bottom of the dialog box and it will create the Assistant. Once Created rename it so you will
remember what it is for.
We have to add two signals to control the motor. One false constant to be sure the direction is canceled
and a second false constant to switch the enable signal to the motor to the off position which will stop
the motor. Select the false constant from the Boolean pallet on the block diagram. Place them on the
True case.
Remember that the DAQ assistants like information in the form of an array. From the Array Pallet select
the block for “Build Array”
Once you place that block hover over it until you see the arrows. Drag slowly down until you have a two
input Build Array block.
79
mySTEM Project Board
Finish wiring the build array block.
Change the case to false by selecting the down arrow next to True at the top of the case structure.
When the Stop Button is not pressed we are directed to the false case by the logic of the switch. As long
as the stop button is not pressed we want the motor to travel back and forth on the rack. In reality there
are two cases that we want to occur here and we have to tell the program what state we want to have.
Inside the False case place another case structure.
Leave room around the area to work.
For this example we will keep the naming of the states simple. Since there are two states to deal with
we will select 0 and 1 for our state names. If state 0 is moving the motor right, then state 1 will be
moving the motor left.
mySTEM Project Board
80
mySTEM Project Board
Inside the true state place a DBL Numeric Constant block from the Numeric pallet.
Wire the DBL numeric constant to the edge of the case structure. By clicking on the structure you are
creating a tunnel.
Once that is accomplished you can wire the tunnel around to the conditional terminal on the other side
of the case structure. This should automatically place a feedback node in the line.
81
mySTEM Project Board
If you do not see the node you will probably see the error on the proposed wire.
If you see that error right click on the wire and select the insert feedback node to insert one.
To select which of these cases go first we need to move our cursor over the * on the Feedback node.
You will see that it is the Initializer Terminal. Right click and select Create>>Constant.
mySTEM Project Board
82
mySTEM Project Board
Make the constant a 0. This will force the 0 case to go first.
You will see that the name of the case has changed. It is now 1. Change to the 0 case and add a DBL
numeric constant there. Click on it until it highlights and change the value to 1.
Wire it to the tunnel. This wiring will cause the next state after 0 to be 1. Looking at the 1 case the next
case after 1 will be 0. This will continue this pattern until the stop button is pressed.
We can now define what we want for the programming in each case.
Return to the initial true case. Stretch a capture box around the blocks there to select them all.
83
mySTEM Project Board
Once they are all highlighted select the CTRL key and the C key at the same time to copy the blocks. You
can also go to the edit menu and select the Copy function.
Return to the False case. Paste the blocks into the 1 case. Change the false constants to true constants
by clicking on them.
Change to the 0 case. Paste the blocks again. This time change only the lower false constant to true.
Leave the top false constant as a false.
The program doesn’t know when to change states yet. If you were to run the program it would try to
change states as fast as possible. We need to give this time to work so a wait block is needed.
mySTEM Project Board
84
mySTEM Project Board
Place a wait block from the Timing Pallet. Right click on the Wait Block and select create constant. Set a
value of 1000 for 1000 milliseconds. This will allow the motor to travel for one second and then switch
direction. Place a wait block in the other state so each one will wait for 1000 milliseconds.
Run the program and see how far the motor will travel in each direction. Does the motor run farther in
one direction than the other?
Conclusion:
Stop the program and adjust the wait time until you are covering almost all the rack gear with the motor
travel. Save your program.
Closed Loop Programming:
Basic systems consist of an input, a process and an output. These simple systems are called open loop
systems because the system cannot interact with the world. For example the clothes washer has no idea
if the clothes are clean or not. The cycle runs for a time and then stops. For most of our needs simple
systems are not enough or are energy wasters. Closed loop systems add feedback to the system from
sensors to continuously monitor and regulate the system. Street lights have a sensor to turn themselves
on when it gets dark and off again when it becomes light. In programming we design loops to monitor
sensors to allow control of systems.
85
mySTEM Project Board
This exercise utilizes parts found in the Do Engineering Basic Kit available from Studica. The components
are listed below in addition to wires and two 10K resistors.
Rack and Pinion 60
(3)
Building block 15 with 2 pins
(2)
Mini-Switch
(2)
Motor Rack Gearbox
(1)
Building Block 30
(8)
S Motor
(1)
Flat Plug Red
(6)
Flat Plug Green
(6)
Cable Clamp
(5)
Base Plate
(1)
The components are assembled as shown below. There are seven of the building block 30s that allow
the rack gears to be aligned in a row. The two 15 mm blocks with the two pins hold the assembly up in
the air. Electrical wiring should be organized in any model you construct. The cable clamps allow the
wire to be supported and out of the path of the motor. Be sure you leave enough wire so the motor and
gear box can travel from end to end of the rack gear. In the picture below you can see the switches set
up at each end of the rack gear.
mySTEM Project Board
86
mySTEM Project Board
The gear box will lock upon the rack gear when the motor is engaged. Pull the motor up slightly to
release the gear before moving the assembly by hand. The picture below shows the motor in both
positions. On the left you can see the worm gear on the motor as it is not engaged with the gears. On
the right the motor worm is all the way down and the assembly should not move unless you power the
motor. Damage will result when the motor and gearbox are forced.
Wiring this exercise is fairly simple. The picture below shows the wiring necessary. The two switches are
connected to a pull up resistor to provide the appropriate logic to the circuit.
Wiring the Motor:
The motor wires are connected to Output1 on the board.
87
mySTEM Project Board
The motor is controlled by two signals. Enable 1 turns the motor on and is connected to DIO1. Direction
is controlled by DIO0. The picture below shows the jumper wires going from the DIO section to the pin
header for the output channels.
Wiring the Switches
In the picture below you will see the wiring for the switches.
mySTEM Project Board
88
mySTEM Project Board
To utilize these switches as digital sensors we create a voltage divider circuit by applying power.
The 5 V power supply can come from the pin header on the board. You can use the 5V and GND
connections from either end of the pin header.
We use the power from the pin header and then utilize the common hot and ground nodes on the
breadboard. In the picture below the 5V is connected to one end of each of the 10K resistors. The
orange wires carry the signal out to the switches. The Yellow wires connect to DIO2 and DIO3.
89
mySTEM Project Board
The orange wires have the red fischertechnik connectors attached so wiring the switch is easier. The
Green ground wires are connected to the common ground on the breadboard.
The Program
This program will use switches to control the transition to the next state. The program will not know
which switch is at which end of the rack gear. You should use the DigIn program from the NI ELVIS
mySTEM Project Board
90
mySTEM Project Board
instrument launcher to determine which switch is which. Since the first time running the program it is
likely that the motor will run off the track if you are not careful so be sure there is enough wire to run
off each end of the rack gear so you have time to shut the motor down if you need to.
You should complete the exercises on Programming Structures, Digital Outputs, Digital Inputs and Open
Loop Programming before attempting this exercise.
Begin a new Labview Virtual Instrument (VI).
Place a While Loop on the screen from the Structures pallet. This will continuously run the various
states placed inside it until a true condition is fed to the conditional terminal. Wire a stop button to the
conditional terminal.
Place a case structure from the Structures pallet inside the while loop to create the structure needed to
control the motor. Wire the All Stop button to the case selector. This will select state True when the All
Stop button is pressed.
When the All Stop button is pushed we want the motor to stop. Since the motor has both an enable
signal and a direction signal being used (DIO 0 and DIO 1) both of these pins should be set to provide a
digital 0 when the All Stop button is pressed. In the True case place an Output DAQ Assistant. In the
dialog box select Generate Signals, Digital Output and select Digital Output, Line Output, and select
port0/line0 and port0/line1. Do this by holding your control or shift key down while you select them
one at a time. When both are highlighted select the finish button at the bottom of the dialog box. Select
91
mySTEM Project Board
OK at the bottom of the dialog box and it will create the Assistant. Once Created rename it so you will
remember what it is for.
We have to add two signals to control the motor. One false constant to be sure the direction is canceled
and a second false constant to switch the enable signal to the motor to the off position which will stop
the motor. Select the false constant from the Boolean pallet on the block diagram. Place them on the
True case.
Remember that the DAQ assistants like information in the form of an array. From the Array Pallet select
the block for “Build Array”
Once you place that block hover over it until you see the arrows. Drag slowly down until you have a two
input Build Array block.
mySTEM Project Board
92
mySTEM Project Board
Finish wiring the build array block.
Change the case to false by selecting the down arrow next to True at the top of the case structure.
When the Stop Button is not pressed we are directed to the false case by the logic of the switch. As long
as the stop button is not pressed we want the motor to travel back and forth on the rack. In reality there
are two cases that we want to occur here and we have to tell the program what state we want to have.
Inside the False case place another case structure.
Leave room around the area to work.
Creating Enum Constants
As our programs become more complex with many more states naming the various states becomes
much more important. In this example we want to have the motor travel forward, then pause, then
travel in the reverse direction and then pause again. For naming we can call these states Forward,
Reverse, Pause1 and Pause2. To name the various states we utilize enumerated type controls (Enum for
short). These allow the programmer to set up names that explain what function they wish the states to
utilize and then apply them to move from state to state. This helps keep confusion to a minimum during
programming.
93
mySTEM Project Board
Right click and select Enum Constant from the Numerical pallet.
Place the block on the diagram close to the right hand side of the case structure.
Right click on the Enum Constant and select Edit.
mySTEM Project Board
94
mySTEM Project Board
Select Insert and type Forward into the box.
Continue selecting the insert button on the Enum Constant Properties and adding items called Pause1,
Reverse and Pause2.
95
mySTEM Project Board
If you want you can reorder the list to make sense to what you are doing by selecting the move up or
move down buttons. In complicated programs the order becomes more important.
Now that you have the enum constants created begin by left clicking in the middle of the enum
constant. This will give you the choice of all the possibilities. Select forward.
Once Forward is selected wire it to the case structure by selecting the wiring tool and clicking on the
edge of the case structure.
The Enum constant is not wired to the case structure.
Wire from the tunnel to the case selector on the other side of the case structure terminal.
If you do this you will see a feedback node automatically created on the wire.
mySTEM Project Board
96
mySTEM Project Board
If you wire the structure and you do not see the feedback node you will see an error on the wire. If you
see that error, right click on the wire and select the insert feedback node to insert one.
To select which of these cases go first we need to move our cursor over the * on the Feedback node.
You will see that it is the Initializer Terminal. Right click and select Create>>Constant.
Make the constant Forward from the choices. This will force the Forward case to go first.
To add all the cases necessary right click on the edge of the case structure and select Add Case for Every
Value. This will add all the necessary cases automatically.
We can now define what we want for the programming in each case.
97
mySTEM Project Board
The first step is to add the enum constants to each case. In the forward case we will add the Pause1
enum. In the Pause1 case we add the Reverse enum. In the Reverse case we add the Pause2 enum and
in the Pause2 case we add the forward enum. This tells the structure where to go in the next case.
Return to the initial true case. Stretch a capture box around the blocks there to select them all.
Once they are all highlighted select the CTRL key and the C key at the same time to copy the blocks. You
can also go to the edit menu and select the Copy function.
mySTEM Project Board
98
mySTEM Project Board
Return to the False case. Paste the blocks into all the cases. Begin on the forward case. Change the
Boolean constants to be both true.
Change to the Pause1 case. Paste the blocks again. This time leaving the Boolean False Constants false
for both cases. This will cause the motor to shut off and wait
Change to the Reverse case. Paste the blocks again. This time change only the lower false constant to
true. Leave the top false constant as a false. Finally go to the Pause2 case and past the blocks a final
time leaving the false constants.
On Pause1 and Pause2 we will add a wait block. Frequently when building automation there are times
when we utilize a wait block to allow for time for sensors to be read or the system to stabilize before
moving on. Add 2000 for a constant value for the Pause cases. This will force a pause for two seconds
between motion cases.
In the forward and reverse cases we want the motor to run until it hits the switch. To do this we need to
create a DAQ Assistant to monitor the position of the switches. We wired the switches to DIO2 and
DIO3. From the Express Pallet select Input and DAQ Assistant. From the create new dialog box select the
99
mySTEM Project Board
Acquire Signals option. Select Digital Input from the options and Line Input from the Digital options.
Hold either the shift key or the CTRL key down and select both DIO2 and DIO3 and then select the finish
button. Be sure you know which switch is connected to which end. You can select run on the dialog box
and then press the switches to determine which is which. Select Stop and then OK at the bottom of the
dialog box to build the input DAQ assistant. Rename the DAQ Assistant to something that reminds you
of the function. In this example it is named Switch Readings.
We can now put a while loop around the Switch readings block. We will use the Switch Readings box to
end the while loop when the right switch has been encountered. The DAQ assistant provides
information in the form of an Array. We will need to add an Index Array block to pull the data we want
from the array of the two switches. The picture below shows the while loop and the Index array.
The first switch is being selected as that information is stored in the first position in the array which is
the 0 position.
mySTEM Project Board
100
mySTEM Project Board
Copy the while loop with the switch readings DAQ assistant. Paste that into the Reverse case. In the
reverse case the only difference is the use of the constant 1 to select the data from the other switch.
The program should be finished. A quick check for logic is required in each of the cases. If you are
comfortable you can run the program. If your program is correct the motor will move until it encounters
a switch, stop and pause, then go the other way. If it runs over the switch and keeps going click on the
other switch and hit the stop button and the program should end.
Conclusions:
Move the switch positions on the rack. Can you control the position where the motor stops?
Adjust the timing of the pauses. Can you create different length pauses between the cases?
101
mySTEM Project Board
Hand Dryer with a Photo Transistor
Before beginning this exercise, be sure you understand how a pull up resistor is utilized with a photo
transistor which is covered in the Photo Transistor exercise.
The circuit below is a voltage divider with the phototransistor in series with a 10K pull up resistor. There
is also a fischertechnik lamp bulb connected to the Output 1 Terminals of the mySTEM™ Project Board.
There is a Fischertechnik Motor connected to Output2 Terminals of the mySTEM™ Project Board.
The structure is made from Fischertechnik components found in the mySTEM™ Do Engineering Starter
kit. The Lens bulb is inserted in the lamp holder and placed on the base plate. The light mask covers the
bulb so there is only a small opening.
Building Block 30
(6)
Building Block 15
(2)
Photo Transistor
(1)
Cable Clamp
(5)
Flat Plug Green
(6)
Flat Plug Red
(6)
Light Mask
(2)
Plug in Lamp Holder
(1)
Building Block 5
mySTEM Project Board
102
mySTEM Project Board
Lens Bulb
(1)
Base Plate
(1)
S-Motor
(1)
Pointed adapter for
Propeller
(1)
Propeller
(1)
With 2 pins
(1)
The assembled system is shown below. The photo transistor is mounted on the arm. It can slide in and
out so it can be positioned directly over the light.
A mask covers the phototransistor so only the area directly in front of the sensor is open. Before you put
the cover over the sensor be sure you know which is the red terminal so you can wire it correctly.
103
mySTEM Project Board
Because the sensor is at the top of the arm you will need a long wire to connect to the mySTEM™
Project Board. The picture below shows the wires as very short. The wiring to DIO 0 will be exactly the
same, just with longer wires.
You will also have to have a set of wires connected to Output 1 to power the lamp.
You will also need a set of wires connected to output2 that will connect to the motor.
mySTEM Project Board
104
mySTEM Project Board
The picture below shows the lens tip bulb in the holder at the bottom of the tower. You can see the two
connections on the left and right. Light bulbs are not polarized so there is no positive or negative end of
the bulb.
For this project the bulb will be always on. The easiest way to accomplish this is to bring a 5V line to the
En 1 terminal. The picture below shows a small jumper being used. This will cause the light to turn on
when the board is being powered.
Turn on the power to the board. Open the ELVISmx Instrument Launcher. Select the DigIn option.
Run the Digital Reader with the lines to read set to read DIO 0. Move your hand through the space
between the lamp and the photo transistor. If it is wired correctly you will see the line state change
when you block the light.
105
mySTEM Project Board
If the state doesn’t change, check the alignment between the sensor and the bulb or the wiring. Once
you are sure it works turn the board off and stop the digital reader.
Wire the motor to Output2.
Run a jumper wire from DIO 1 to En2 on the board.
mySTEM Project Board
106
mySTEM Project Board
From the instrument Launcher select the DigOut option.
The application will open. Select Run at the bottom of the window and once running move the switch
for line 1 to the HI position. The motor should start. Return the switch to the LO position and the motor
should turn off.
Once you are sure your wiring is working it is time to think about the programming.
Below is a simple state diagram for this program.
107
mySTEM Project Board
In the state diagram the first decision that needs to be made is the state of the stop button. If it is not
pressed then the first nested diagram is run. if it is then the program should shut down the output to
the motor and close the program. The program should run except for that one condition. If it is not
pressed we then look at the nested states. To begin the programming, place a while loop and a stop
button on the block diagram. This structure will allow the program to continue running until the stop
button is pressed.
The program needs to communicate with the motor. Add an Output DAQ Assistant to the while loop.
Set it for a digital output and use line1. Rename the output block so you will know what it does.
In addition to ending the program we need to be sure that the stop switch also puts the motor in the off
state before the program closes. In essence there are two possible states. One where the program runs
and makes decisions based on input, and the other state that shuts the motor off and ends the program.
This requires us to make a choice of states. In this instance we will use a case structure to allow us to
make a decision based upon the stop button.
When the stop button is pushed it provides a Boolean true to the case structure and ends the program.
In the True case we want to feed a false constant signal to the motor controller so the motor will stop. A
False Constant block found on the Boolean pallet is used. The signal is fed through a tunnel in the case
mySTEM Project Board
108
mySTEM Project Board
structure. Since the Control Motor DAQ Assistant wants an array for an input we have to add a Build
Array block from the Array pallet to change the Boolean signal to the necessary array.
As long as the stop button is not pressed a false constant is delivered to the selector terminal and the
program will switch to the false case to create in the case structure. Change to the false case.
Looking at the state diagram there are two states left to create. Motor On and Motor Off.
109
mySTEM Project Board
The program needs to read the sensor input in order to make a decision on what state the motor should
be. Begin with a DAQ Assistant Input Block set to acquire a digital input. Set it for line0. Rename the
block to represent what it is doing.
This block will monitor the sensor and deliver us the data in an array format. We will use the data to
select one of two states. Create a case structure nested inside the false case.
In the True case we want the motor to turn on so we add a True Constant block from the Boolean pallet
and wire it through the tunnel so that it can feed the proper signal to the motor.
mySTEM Project Board
110
mySTEM Project Board
Switch to the False Case and place a False Constant and wire it through the tunnel.
To make the decision we need to change the data array to simple data using an Index Array from the
Array pallet. This is then wired to the Selector Terminal of the Case Structure.
You have now finished the program and it should be functional. You might find that the program is
almost too responsive. Normally if you are in a bathroom the hand dryer runs for a second after you
remove your hands. This delay allows for normal hand motion without turning the motor on and off
quite often. This allows the motor to have a longer life and actually use less electricity as starting a
motor takes over five times the energy of just running the motor. In this case we can add a Wait block
from the Timing pallet and using 1000 (milliseconds) as a constant. This will then allow the sensor to be
checked once a second.
111
mySTEM Project Board
Run the program and try changing the timing to see what effect the delay has on the program.
Counter Utilizing a Photo Transistor
Before beginning this exercise, be sure you understand how a pull up resistor is utilized with a photo
transistor which is covered in the Photo Transistor exercise.
A counter is a term for a device which can monitor a process and can keep track of and display the
number of times a particular event has occurred. We are using the photo transistor in combination with
a lamp to monitor the number of times the beam has been broken. There are numerous applications of
a counter build this way. The number of people passing through a doorway would be one example. A
rotary optical encoder on a motor is another way a counter might be used.
Switches are installed in circuits to control the flow of electrons through the circuit. The phototransistor
is setup as a fast acting semiconductor switch. Without light it is a normally open switch. When light
strikes the device it begins to conduct and will continue to conduct until light is no longer there. The
schematic for a phototransistor is shown below.
mySTEM Project Board
112
mySTEM Project Board
The circuit below is a voltage divider with the phototransistor in series with a 10K pull up resistor. There
is also a fischertechnik lamp bulb connected to the Output 1 Terminals of the mySTEM™ Project Board.
The structure is made from Fischertechnik components found in the mySTEM™ Do Engineering Starter
kit. The Lens bulb is inserted in the lamp holder and placed on the base plate. The light mask covers the
bulb so there is only a small opening.
Building Block 30
(5)
Building Block 15
(1)
Photo Transistor
(1)
Cable Clamp
(3)
Lens Bulb
(1)
Base Plate
(1)
Flat Plug Green
(4)
Flat Plug Red
(4)
Light Mask
(2)
Plug in Lamp Holder
(1)
The assembled system is shown below. The photo transistor is mounted on the arm. It can slide in and
out so it can be positioned directly over the light.
113
mySTEM Project Board
A mask covers the phototransistor so only the area directly in front of the sensor is open. Before you put
the cover over the sensor be sure you know which is the red terminal so you can wire it correctly.
mySTEM Project Board
114
mySTEM Project Board
Because the sensor is at the top of the arm you will need a long wire to connect to the mySTEM™
Project Board. The picture below shows the wires as very short. The wiring to DIO 0 will be exactly the
same, just with longer wires.
You will also have to have a set of wires connected to Output 1 to power the lamp.
The picture below shows the lens tip bulb in the holder at the bottom of the tower. You can see the two
connections on the left and right. Light bulbs are not polarized so there is no positive or negative end of
the bulb.
115
mySTEM Project Board
For this project the bulb will be always on. The easiest way to accomplish this is to bring a 5V line to the
En 1 terminal. The picture below shows a small jumper being used. This will cause the light to turn on
when the board is being powered.
Turn on the power to the board. Open the ELVISmx Instrument Launcher. Select the DigIn option.
Run the Digital Reader with the lines to read set to read DIO 0. Move your hand through the space
between the lamp and the photo transistor. If it is wired correctly you will see the line state change
when you block the light.
mySTEM Project Board
116
mySTEM Project Board
If the state doesn’t change, check the alignment between the sensor and the bulb or the wiring. Once
you are sure it works turn the board off and stop the digital reader.
Building the Counter
The picture below shows a digital signal. When we broke the light beam we saw the Line State LED light
representing a digital high. When the beam made it to the sensor we saw a logic low and no light in the
Line State. In between those states we have what is called the Edge of the signal. The edge that goes
from low to high is called the rising edge. The edge that goes between high to low is called the falling
edge. Most counters pay attention to the edges not to the High or Low.
117
mySTEM Project Board
Be sure the myDAQ is connected to your computer with the USB cable. Begin a new VI. Toggle the
screens so you can see the Front Panel and Block Diagram on the screen. On the Block Diagram right
click and select the DAQ Assistant from the Input Pallet of the Express Pallet and place it on the Block
Diagram.
In the Create New Dialog box select the Counter Input and Edge Count as the type.
mySTEM Project Board
118
mySTEM Project Board
The next dialog box will show the supported physical channels. You will see that there is only one
channel supported. It is called ctr0. DIO 0 is the only pin that can be used to count events in this way.
This is a special digital input case. Once you have highlighted the ctr0 option select finish.
The next window brings up the options to use around a counter. Select Rising for the Active Edge. This
will cause the counter to ignore the falling edge. So in one wave form the program will count a single
time. If it looked at both edges it would count two for each wave form. The count direction allows us to
set the count direction. 1..2..3..4 for example is counting up. 10…9…8…7 is counting down. The initial
count establishes the number to begin with.
119
mySTEM Project Board
Once you have the parameters set turn the board on so your lamp is turned on. Then select run at the
top of the DAQ assistant.
As you pass your hand between the beam and the light you will see the count begin. It should only count
one for each time you break the beam.
Select Stop. At the bottom of the DAQ Assistant select the OK button to compile the DAQ assistant. As it
finishes the compilation you will see the notice that a loop is required to run the counter and it asks
permission to create it. Select yes.
mySTEM Project Board
120
mySTEM Project Board
You should then see something similar to the picture below. The stop button is wired to the DAQ
Assistant and then to the conditional terminal of the while loop.
Double click on the work DAQ Assistant and once it highlights replace it with a name that describes the
function you can easily identify once you develop a large program. In the picture below it was named
counter.
We might want to know the count at any time so on the front panel place a numeric indicator from the
numeric pallet from the modern pallet.
121
mySTEM Project Board
Resize and re-label so the indicator makes sense.
Wire the count indicator to the data port on the block diagram.
Turn the board on to illuminate the lamp. Run the counter program and see if you can see the count
advance on the screen. Once this is working select the stop button.
Turn the board off. If this were used on an automated machine that put bottles in cases we would want
to count the bottles going by and stop the flow when the case had the correct number. In this next
section we will take the information from the counter and use that to end the program at a specific
point.
mySTEM Project Board
122
mySTEM Project Board
On the block diagram place the Equal? Block from the comparison pallet. We will use this block to
trigger an output when our count reaches a point we set.
This block already has a stop button wired to the conditional terminal. We will add a section to allow us
to stop the program when either the Stop button is selected OR the count reaches the preset limit. This
requires an OR gate from the Boolean Pallet. (For more information about Boolean decisions see the
exercise on Logic Gates.
123
mySTEM Project Board
Place the Or Block near the Equal? Block. Erase the connection from the conditional terminal and wire
similar to the picture below. Now the terminal will stop the while loop when the stop button is pressed
or the Equal? Block provides the signal that the data in the count is equal to the preset amount.
On the front panel place a horizontal fill slide from the numeric pallet.
Resize and rename the fill slide. Right click on the slide and select Digital Display from the Visible Items
menu.
mySTEM Project Board
124
mySTEM Project Board
Your front panel should resemble the one shown here.
Finish the wiring on the block diagram. It should now be complete. The data will come from the counter
and be compared to the count limit you set from the front panel.
Power the board on and run the program. You should see the current count and the program should
shut down when the count reaches the limit you set.
Programming Structures: Conveyor Belt
Before beginning this exercise, be sure you understand how a pull up resistor is utilized with a photo
transistor which is covered in the Photo Transistor exercise.
The structure is made from Fischertechnik components found in the mySTEM™ Do Engineering Starter
kit. The assembled system is shown below. The photo transistors are mounted on each end of the
conveyor belt. Complete parts lists and assembly instructions are found here.
http://studica.com/downloads/130879_robo_transportband.pdf
125
mySTEM Project Board
Wiring
The circuit below is a voltage divider with the phototransistor in series with a 10K pull up resistor. These
are wired into digital inputs DIO2 and DIO3. There are also two fischertechnik lamp bulbs connected to
the Output 1 Terminals of the mySTEM™ Project Board. There is a Fischertechnik Motor for the
conveyor connected to Output2 Terminals of the mySTEM™ Project Board. There is a jumper wire to
connect 5V to the enable (En1) of output channel 1. There are jumper wires connecting DIO 0 to the
direction (Dir2) for output channel 2 and DIO 1 to the enable (En2) of channel 2.
mySTEM Project Board
126
mySTEM Project Board
A mask covers the phototransistor so only the area directly in front of the sensor is open. Before you put
the cover over the sensor be sure you know which is side is the red terminal so you can wire it correctly.
To utilize these phototransistors as digital sensors we create a voltage divider circuit by applying power
to the voltage divider.
The 5 V power supply can come from the pin header on the board. You can use the 5V and GND
connections from either end of the pin header.
127
mySTEM Project Board
We use the power from the pin header and then utilize the common hot and ground nodes on the
breadboard. In the picture below the 5V is connected to one end of each of the 10K resistors. The
orange wires carry the signal out to the positive end (red) of the phototransistors. The Yellow wires
connect to DIO2 and DIO3 to take the signal to DIO2 and DIO3.
Below the fischertechnik connectors are ready to plug into the wiring from the two photosensors.
mySTEM Project Board
128
mySTEM Project Board
You will also have to have a set of wires connected to Output 1 to power the lamps.
The Lens bulb is inserted in the lamp holder and placed on the one side of the conveyor at each end.
The light mask covers the bulb so there is only a small opening. In the picture below the lamps are
shown across from the sensors toward the bottom of the picture. Be sure the light strikes your sensors.
The bulbs are wired in parallel and connected to Output1. See the schematic. There is a jumper wire
connected from the 5 V source on the Pin Header to the En1 (Enable 1) to allow Output1 to be on all the
time without taking up a DIO pin.
129
mySTEM Project Board
You will also need a set of wires connected to output2 that will connect to the motor. In addition you
will need jumper wires connecting DIO 0 to the direction (Dir2) for output channel 2 and DIO 1 to the
enable (En2) of channel 2.
From the instrument Launcher select the DigOut option.
The application will open. Select Run at the bottom of the window and once running move the switch
for line 1 to the HI position. The motor should start. Return the switch to the LO position and the motor
should turn off.
Once you are sure your wiring is working it is time to think about the programming.
mySTEM Project Board
130
mySTEM Project Board
Below is a simple state diagram for this program.
This program will use Phototransistors and timing circuits to control the transition to the next state. The
program will not know which phototransistor is at which end of the conveyor. You should use the DigIn
program from the NI ELVIS instrument launcher to determine which end of the conveyor the
phototransistor is.
You should complete the exercises on Programming Structures, Digital Outputs, Digital Inputs and Open
Loop Programming before attempting this exercise.
Begin a new Labview Virtual Instrument (VI).
131
mySTEM Project Board
Place a While Loop on the screen from the Structures pallet. This will continuously run the various
states placed inside it until a true condition is fed to the conditional terminal. Wire a stop button to the
conditional terminal.
Place a case structure from the Structures pallet inside the while loop to create the structure needed to
control the motor. Wire the All Stop button to the case selector. This will select state True when the All
Stop button is pressed.
When the All Stop button is pushed we want the motor to stop. Since the motor has both an enable
signal and a direction signal being used (DIO 0 and DIO 1) both of these pins should be set to provide a
digital 0 when the All Stop button is pressed. In the True case place an Output DAQ Assistant. In the
dialog box select Generate Signals, Digital Output and select Digital Output, Line Output, and select
port0/line0 and port0/line1. Do this by holding your control or shift key down while you select them
one at a time. When both are highlighted select the finish button at the bottom of the dialog box. Select
OK at the bottom of the dialog box and it will create the Assistant. Once Created rename it so you will
remember what it is for.
mySTEM Project Board
132
mySTEM Project Board
We have to add two signals to control the motor. One false constant to be sure the direction is canceled
and a second false constant to switch the enable signal to the motor to the off position which will stop
the motor. Select the false constant from the Boolean pallet on the block diagram. Place them on the
True case.
Remember that the DAQ assistants like information in the form of an array. From the Array Pallet select
the block for “Build Array”
Once you place that block hover over it until you see the arrows. Drag slowly down until you have a two
input Build Array block.
133
mySTEM Project Board
Finish wiring the build array block.
Change the case to false by selecting the down arrow next to True at the top of the case structure.
When the Stop Button is not pressed we are directed to the false case by the logic of the switch. As long
as the stop button is not pressed we want the motor to travel back and forth on the rack. In reality there
are two cases that we want to occur here and we have to tell the program what state we want to have.
Inside the False case place another case structure.
Leave room around the area to work.
Creating Enum Constants
As our programs become more complex with many more states naming the various states becomes
much more important. In this example we want to have the motor travel forward, then pause, then
travel in the reverse direction and then pause again. For naming we can call these states Forward,
Reverse, Pause1 and Pause2. To name the various states we utilize enumerated type controls (Enum for
short). These allow the programmer to set up names that explain what function they wish the states to
utilize and then apply them to move from state to state. This helps keep confusion to a minimum during
programming. Right click and select Enum Constant from the Numerical pallet.
mySTEM Project Board
134
mySTEM Project Board
Place the block on the diagram close to the right hand side of the case structure.
Right click on the Enum Constant and select Edit.
135
mySTEM Project Board
Select Insert and type Forward into the box.
Continue selecting the insert button on the Enum Constant Properties and adding items called Pause1,
Reverse and Pause2.
mySTEM Project Board
136
mySTEM Project Board
If you want you can reorder the list to make sense to what you are doing by selecting the move up or
move down buttons. In complicated programs the order becomes more important.
Now that you have the enum constants created begin by left clicking in the middle of the enum
constant. This will give you the choice of all the possibilities. Select forward.
Once Forward is selected wire it to the case structure by selecting the wiring tool and clicking on the
edge of the case structure.
The Enum constant is not wired to the case structure.
Wire from the tunnel to the case selector on the other side of the case structure terminal.
137
mySTEM Project Board
If you do this you will see a feedback node automatically created on the wire.
If you wire the structure and you do not see the feedback node you will see an error on the wire. If you
see that error, right click on the wire and select the insert feedback node to insert one.
To select which of these cases go first we need to move our cursor over the * on the Feedback node.
You will see that it is the Initializer Terminal. Right click and select Create>>Constant.
Make the constant Forward from the choices. This will force the Forward case to go first.
To add all the cases necessary right click on the edge of the case structure and select Add Case for Every
Value. This will add all the necessary cases automatically.
mySTEM Project Board
138
mySTEM Project Board
We can now define what we want for the programming in each case.
The first step is to add the enum constants to each case. In the forward case we will add the Pause1
enum. In the Pause1 case we add the Reverse enum. In the Reverse case we add the Pause2 enum and
in the Pause2 case we add the forward enum. This tells the structure where to go in the next case.
Return to the initial true case. Stretch a capture box around the blocks there to select them all.
Once they are all highlighted select the CTRL key and the C key at the same time to copy the blocks. You
can also go to the edit menu and select the Copy function.
139
mySTEM Project Board
Return to the False case. Paste the blocks into all the cases. Begin on the forward case. Change the
Boolean constants to be both true.
Change to the Pause1 case. Paste the blocks again. This time leaving the Boolean False Constants false
for both cases. This will cause the motor to shut off and wait
Change to the Reverse case. Paste the blocks again. This time change only the lower false constant to
true. Leave the top false constant as a false. Finally go to the Pause2 case and past the blocks a final
time leaving the false constants.
On Pause1 and Pause2 we will add a wait block. Frequently when building automation there are times
when we utilize a wait block to allow for time for sensors to be read or the system to stabilize before
moving on. Add 2000 for a constant value for the Pause cases. This will force a pause for two seconds
between motion cases.
mySTEM Project Board
140
mySTEM Project Board
In the forward and reverse cases we want the motor to run until it sees the block on the belt. To do this
we need to create a DAQ Assistant to monitor the conditions of the phototransistors. We wired the
phototransistors to DIO2 and DIO3. From the Express Pallet select Input and DAQ Assistant. From the
create new dialog box select the Acquire Signals option. Select Digital Input from the options and Line
Input from the Digital options. Hold either the shift key or the CTRL key down and select both DIO2 and
DIO3 and then select the finish button. Be sure you know which switch is connected to which end. You
can select run on the dialog box and then block the light to determine which is which. Select Stop and
then OK at the bottom of the dialog box to build the input DAQ assistant. Rename the DAQ Assistant to
something that reminds you of the function. In this example it is named PhotoTransistor Readings.
We can now put a while loop around the PhotoTransistor Readings block. We will use the
PhotoTransistor Readings box to end the while loop when the phototransistor light is blocked. The DAQ
assistant provides information in the form of an Array. We will need to add an Index Array block to pull
the data we want from the array of the two inputs. The picture below shows the while loop and the
Index array.
The first Phototransistor is being selected as that information is stored in the first position in the array
which is the 0 position. Copy the while loop with the PhotoTransistor Readings DAQ assistant. Paste
141
mySTEM Project Board
that into the Reverse case. In the reverse case the only difference is the use of the constant 1 to select
the data from the other PhotoTransistor.
The program should be finished. A quick check for logic is required in each of the cases. If you are
comfortable you can run the program. If your program is correct the motor will move until it encounters
a switch, stop and pause, then go the other way. If it runs over the switch and keeps going click on the
other switch and hit the stop button and the program should end.
Conclusions:
Create a program that will not allow the conveyor to start until a block is placed in the path of the
phototransistor at one end of the track. As the block exits the other end of the conveyor you should
keep a running count of the blocks that pass by. You can utilize the exercise on creating a counter with
the phototransistor. This is a typical program for a counting and packaging machine. When enough
parts have traveled down the conveyor the belt pauses while the bag is sealed and the count is reset.
Parallel Programming: Elevator.
Before beginning this exercise, be sure you understand how a pull up resistor is utilized with a photo
transistor which is covered in the Photo Transistor exercise.
Rack and Pinion 60
(3)
mySTEM Project Board
Motor Rack Gearbox
(1)
142
Flat Plug Red
(6)
mySTEM Project Board
Building block 15 with 2
pins
(2)
Mini-Switch
(2)
Base Plate
(1)
Building Block 30
(8)
Flat Plug Green
(6)
Cable Clamp
(5)
S Motor
(1)
Link 15
(2)
The structure is made from Fischertechnik components found in the mySTEM™ Do Engineering Starter
kit. The elevator should look like the one below. Here are two views showing the different sides. Be sure
there is enough wire so the motor can travel the entire distance up and down. Be sure to disengage the
motor when sliding it by hand on the rack gear to prevent damage.
143
mySTEM Project Board
The circuit below is a voltage divider with the phototransistor in series with a 10K pull up resistor. There
is also a fischertechnik lamp bulb connected to the Output 1 Terminals of the mySTEM™ Project Board.
There is a Fischertechnik Motor connected to Output1 Terminals of the mySTEM™ Project Board.
Wiring the Motor:
The motor wires are connected to Output1 on the board.
mySTEM Project Board
144
mySTEM Project Board
The motor is controlled by two signals. Enable (En1) turns the motor on and is connected to DIO1.
Direction (Dir1) is controlled by DIO0. The picture below shows the jumper wires going from the DIO
section to the pin header for the output channels.
Wiring the Switches
In the picture below you will see the wiring for the switches.
To utilize these switches as digital sensors we create a voltage divider circuit by applying power.
145
mySTEM Project Board
The 5 V power supply can come from the pin header on the board. You can use the 5V and GND
connections from either end of the pin header.
We use the power from the pin header and then utilize the common hot and ground nodes on the
breadboard. In the picture below the 5V is connected to one end of each of the 10K resistors. The
orange wires carry the signal out to the switches. The Yellow wires connect to DIO2 and DIO3.
mySTEM Project Board
146
mySTEM Project Board
The orange wires have the red fischertechnik connectors attached so wiring the switch is easier. The
Green ground wires have the green connectors and are connected to the common ground on the
breadboard. Use terminals 1 & 2 on the switch. You will need longer wires to make the connection.
Testing the switches:
Turn on the power to the board. Open the ELVISmx Instrument Launcher. Select the DigIn option.
Run the Digital Reader with the lines to read set to read 0 - 3. Push the switches one at a time. If they
are connected correctly you should see the channel associated with the switch show a change in state.
147
mySTEM Project Board
If the state doesn’t change, check the wiring using the DMM. Once you are sure it works turn the board
off and stop the digital reader.
Programming the elevator
Below is a simple state diagram for this program. Notice that this diagram implies there are two
separate programs running in Parallel. This is why it is known as Parallel programming.
In the state diagram the first decision that needs to be made is the state of the stop button. If it is not
pressed then the first nested diagram is run. if it is then the program should shut down the output to
the motor and close the program. The program should run except for that one condition. If it is not
pressed we then look at the nested states.
mySTEM Project Board
148
mySTEM Project Board
To begin the programming, place a while loop and a stop button on the block diagram. This structure
will allow the program to continue running until the stop button is pressed.
The front panel will need controls and indicators. From the Boolean pallet place two round LED
indicators and two push button switches. Arrange them so they are easy to see. Rename and resize
them so they resemble the picture below.
The switches to call the elevator need to be momentary switches. This will allow them to shift the logic
but will reset them to their original state when you release the switch
Right click on the switch and select properties. On the Operation tab select the “Switch until released”
option. You can preview the action with the preview selected behavior test switch. When you are
satisfied you can select OK at the bottom of the properties window. Repeat the process for the Floor 2
Call button.
149
mySTEM Project Board
In the Block Diagram place two case structures. These will work in parallel.
Connect one call button to each Selector Terminal
This structure is set up to match the State Diagram from above. The choice of what will happen will
depend on inputs. Two of the inputs are Floor Call switches on the Front Panel which will select the
appropriate case structure. The other inputs are the position switches on the side of the elevator
structure. We will use these to control motion and the indicators.
Change to the False state on the case structure connected to Floor 1 Call.
Place a DAQ Assistant from the Input Pallet from the express pallet. Set it to acquire signals>>Digital
Input>>Line Input>> port0/ line2. Select Finish at the bottom of the dialog box so it can build. Rename
the DAQ Assistant. This example called this block First Floor Data. Add an Index Array from the array
pallet so the Input DAQ assistant can be read by the Floor 1 LED which you created earlier.
mySTEM Project Board
150
mySTEM Project Board
Repeat the process for the floor 2 case structure. In this case you would set the parameters to acquire
signals>>Digital Input>>Line Input>> port0/ line3.
If the floor call button for the floor is not pushed the false cases will read the position switches on the
sides of the elevator and turn on the position light if it detects a signal.
The logic for controlling the motors is more difficult.
Change the case structure for the first floor to the True Case. There are two outputs needed to control
the motor in this example. Enable allows current to activate the motor. Direction allows the current
direction to be controlled so the motor and gearbox to travel either up or down as the logic dictates. We
will need two separate Output DAQ Assistants.
The first one to create will control DIO 0 which will be the direction. In the “Create New DAQ Assistant”
dialog box adjust the settings to Generate Signals>>Digital Output>>Line Output>>port0/line0. Select OK
and it will create the block. Rename the block to Direction.
Repeat the process to create the DAQ Assistant which will turn the motor on and off. In the Create New
DAQ Assistant dialog box, utilize the settings to Generate Signals>>Digital Output>>Line
Output>>port0/line1. Select OK and it will create the block. Rename the block to Enable.
151
mySTEM Project Board
Copy the First Floor Data DAQ assistant from the false case and past it into the True case.
Surround them with a while loop and add an index array to allow the signal to be used for the
conditional terminal. This will allow the loop to end when it sees the position switch on the elevator
activate.
The logic for this section is slightly different. The way the switch is wired, when the switch is open we
want the motor to move and when the switch is closed we need it to stop and stay stopped. Normally an
output DAQ assistant will look for a true to turn it on and a false to turn it off. To change this behavior
we double click on the Enable block. This will open the DAQ Assistant Dialog box again. Check the box
for Invert Line. What this will do is cause the block to produce an output as long as it does not have a
true for an input. It will turn off when it sees a true. Once you check Invert Line select OK at the bottom
to rebuild the block.
mySTEM Project Board
152
mySTEM Project Board
Switch to the true case of the Floor2 case structure. Copy the Direction and Enable blocks from Floor 1
and paste them into the True case of the Floor 2 case structure. Copy the 2nd Floor Data block from the
False case of Floor 2 and past that into the True case of Floor 2. Wire the case similar to the picture
below.
In this case the direction is changed from the Floor1 case. Double click on the Direction block and check
the Invert Line box. Select OK to complete. If you copied the Enable block it should still have its Invert
Line Box checked. Double check to be sure this is the case.
153
mySTEM Project Board
Your program should resemble the one below.
When you test your program with the model be sure you have access to the on/off switch of the
mySTEM™ Project Board in case your logic is not correct and you need to stop motion in a hurry.
Conclusion:
Once you have this logic worked out you can add an additional switch to make for three floors. There
should be a call button on each floor. The elevator control should send the elevator to the floor farthest
from the direction first, so if two floors wish to go down, the car will go to the highest one first. You are
to design the control panel for the inside of the elevator to select the floor. The elevator return to the
first floor if it has not been used in two minutes
mySTEM Project Board
154
mySTEM Project Board
Introduction to Sensors- Voltage Divider for Analog Sensors
Sensor is the generic name given to group of devices that can monitor either the absolute value or a
change in the physical quantity and translates the value or change into a useful signal. A sensing system
is comprised by the sensor, data gathering and signal processing components. It is used to monitor,
make decisions and issue feedback to programs that control automated machinery. There are almost
countless varieties of sensors available that can measure anything. In short anything that can gather
information can be called a sensor.
Analog sensors produce a change in an electrical property to indicate a change in its host environment.
Most things that we need to measure have a range of possibilities. Sensors are designed so they have a
measurement section that is fairly linear but frequently the low and upper ranges of the device are not.
It is important to select a sensor of the appropriate range to allow fairly good response to the property
being measured. The price will vary on sensors depending on the precision and accuracy requirements
of the measurement being performed. There are differences between two sensors made at the same
time in the same factory. Because of this difference calibration of sensors is sometimes necessary if
exact results are required. The fuel level in the gas tank of a car is important to know so a refueling trip
can be scheduled before the automobile stops running. However you might not need to know how
many milliliters are left in the tank. Analog sensors are divided into two basic categories; active and
passive. Passive sensors react to the world around them and produce a change in a passive electrical
quantity, such as resistance, capacitance, or inductance which can be measured. Active sensors actively
probe the environment and will require energy from a power source to function. These devices usually
have an on-board processor which conditions a signal for your use, hence the name active.
To utilize the analog inputs you need to understand the basics of a voltage divider circuit. If you have not
done so already look at the Introduction to Voltage Dividers activity.
Begin with setting up the following circuit.
R1 is a photo sensitive resistor. These are known by many names such as light dependent resistors,
photocell and cadmium sulphide (CdS) cells. They come in a variety of shapes, cases and resistances.
Looking at the top surface you see a wavy pattern. In darkness these have high resistance and in bright
light their resistance drops to fairly low resistance.
155
mySTEM Project Board
Their resistance varies depending on the amount or intensity of light striking the surface. Using the
basics of Ohm’s Law we know that current in the circuit can be calculated by dividing the voltage
potential by the resistance. If you are in doubt how to measure voltage, resistance and current see
http://www.ni.com/white-paper/11432/en/. You can measure the resistance by using the Ohm meter.
In the picture below a photo sensor in a fischertechnik case is being measured for resistance. This sensor
is available from Studica and is also found in many kits. Observe the resistance and then shade the
device with your hand. You should be able to see the resistance change when you move your hand.
When using analog sensors you need to be aware of how your sensor views the area around where it is
placed.
mySTEM Project Board
156
mySTEM Project Board
Place the photocell in series with your 10K resistor. Measure the resistance across the circuit. See what
happens when you shade the photocell. Did you observe any changes?
If we place a voltage across this combination of resistors there will be a voltage drop across each resistor
in proportion to its portion of the total resistance. Connect this series resistance combination to the 5 V
power supply. The 5 V power supply can come from the pin header on the board. You can use the 5V
and GND connections from either end of the pin header.
Your circuit should resemble the one in the picture below.
157
mySTEM Project Board
Once you have completed the circuit, measure the voltage across the photocell. As you shade the
photocell observe the change in voltage. A good explanation of the mathematics and theory involved is
found on the All About Circuits site. http://www.allaboutcircuits.com/vol_1/chpt_5/2.html
Since the voltage is a range of values, not just on or off as in a switch you will need to utilize a different
method of importing the data into Labview.
See the exercise on the Analog Input Express VI.
Analog Input: Express VI
Before beginning this exercise, be sure you understand how a pull up resistor is utilized with an analog
sensor. This is covered in the exercise on the Voltage Divider for Analog Circuits.
Analog sensors produce a change in an electrical property to indicate a change in its host environment.
Most things that we need to measure have a range of possibilities. Sensors are designed so they have a
measurement section that is fairly linear but frequently the low and upper ranges of the device are not.
It is important to select a sensor of the appropriate range to allow fairly good response to the property
being measured. The price will vary on sensors depending on the precision and accuracy requirements
of the measurement being performed. There are differences between two sensors made at the same
time in the same factory. Because of this difference calibration of sensors is sometimes necessary if
exact results are required. The fuel level in the gas tank of a car is important to know so a refueling trip
can be scheduled before the automobile stops running. However you might not need to know how
many milliliters are left in the tank. Analog sensors are divided into two basic categories; active and
passive. Passive sensors react to the world around them and produce a change in a passive electrical
quantity, such as resistance, capacitance, or inductance which can be measured. Active sensors actively
mySTEM Project Board
158
mySTEM Project Board
probe the environment and will require energy from a power source to function. These devices usually
have an on-board processor which conditions a signal for your use, hence the name active.
The Circuit
Wire the following circuit using a pull up resistor and a photocell. Connect the junction of the photocell
and resistor to the Analog Input (AI 0+). The other end of the photocell is connected to the AI 0-, AGND
and the Digital ground on the board.
When you are done it will probably look something like the picture below. The five volts is coming from
the pin header. You can use either of the 5V outputs. The 5V is connected to a 10K resistor and the 10K
resistor is connected the Photocell.
159
mySTEM Project Board
The wiring for the input should resemble this. The AI 0- node is connected to the AGND node and the
signal from the sensor is connected to AI 0+.
Writing the simple program
It’s time to build a simple program to read the input. Open Labview and start a new VI.
You must have the myDAQ connected to your computer with the USB cable for this to work. On the
block diagram right click to bring up the Functions pallet. Select the Express option to bring up the
Express pallet.
mySTEM Project Board
160
mySTEM Project Board
From the Express pallet select Input.
From the Input pallet select the option for DAQ Assist.
Place the block on the block diagram. The hand will allow you to move it anyplace on the screen. When
you are happy with the placement, click to place and release the block.
161
mySTEM Project Board
This block is an Express VI. This means that much of the configuration is already done for us and we
need to provide some information to complete the action. When the Create New screen comes up,
expand the Acquire Signals menu and then the Analog Input menus so you can select the voltage option.
This will bring up the Supported Physical Channels dialog box. Since we connected our input to AIO 0 we
will select that one from the list.
Select the finish button at the bottom of the dialog box. Once it has finished building the DAQ Assistant
will show you the channel.
mySTEM Project Board
162
mySTEM Project Board
To test your input power the board and then select Run at the top of the DAQ Assistant.
You will see the voltage value being displayed on the right hand column. In this case it is 161 millivolts.
Shade the sensor and see how much the value changes. You will see continuous changes as you block
more of the light. In the example below the actual voltage changed from 0.161V to 1.033 V
Select Stop. The collection will end.
163
mySTEM Project Board
Now Right click on the Voltage in the Channel Settings. Select rename and give it a name that will
describe the.
In this example the task has been renamed to Photocell Reading. In future programs when you are
looking at several sensors this will help you quickly determine which one you want.
Look for the OK button at the bottom right corner of the dialog box. It sometimes hides off screen and
needs to be dragged onto the screen so you can see it. Once you say OK it will take a while to build the
Block, be patient while it builds.
mySTEM Project Board
164
mySTEM Project Board
You will know it is done when you see the DAQ Assistant block diagram with the Data port showing. This
port is where the information from the sensor is showing.
You can rename this DAQ Assistant by selecting the text in the box and replacing it with a name that will
help you remember what this assistant does.
Now that the program has the ability to import data, it should be displayed on the front panel. With a
digital input, it is either on or off so a simple indicator is all that is needed. Analog inputs are continuous
in nature and will vary depending on the environmental inputs to the sensor.
Right click on the Front panel and select the Numeric pallet from the Modern pallet. On the Numeric
pallet select the Meter and drag it to the Front panel.
165
mySTEM Project Board
mySTEM Project Board
166
mySTEM Project Board
This will place a meter on the front panel.
Left click on the meter and drag the corner to resize the Meter.
Now double click on the Meter label and change it to something that shows what is being observed.
Resize the text to be able to see it easily.
Now double click on the ten at the end of the scale. Enter a number higher than the largest voltage you
observed.
The meter shows a graphical representation of the data. If you want to be able to see an actual read out
of the data you can also turn on a display.
167
mySTEM Project Board
Right click on the meter and select Visible Items from the options. Select Digital Display and you will see
a text box with a number in it. Swipe the number and resize the text.
Add a Boolean Stop button to the front panel.
On the Block diagram place a while loop around the Read Sensor analog input VI. Wire the VI so it
resembles the one below.
When your circuit is ready, run the VI. You should see the reading from the sensor show up on the meter
on the front panel. You will also see the digital display match your meter reading.
mySTEM Project Board
168
mySTEM Project Board
End the VI by selecting the stop button on the front panel. Sometimes you will want to see a graph of
the voltage over time.
Save your program.
Making Analog Decisions:
Before beginning this exercise, be sure you have covered the Voltage Divider for Analog Sensors, and
also the Analog Input: Express VIs lesson.
Analog sensors provide a range of voltage levels depending on the environment that the sensor is
monitoring. When monitoring external environments, there are times when you wish to make a
decision. If it is too dark then close the blinds. If it is too warm then open the windows. If the washing
machine has enough water then turn the water off. These decisions provide a digital result from the
varying inputs from the environment around the sensor. The digital results can be used to control
outside events that require on/off characteristics.
Open the same circuit you created for the Analog Input: Express VI exercise. This VI can be adapted to
make a decision utilizing the input from the photocell.
We want an indicator on the Front panel to show us the status of the decision.
169
mySTEM Project Board
Right click on the Front panel and select the Boolean pallet from the Modern pallet. On the Boolean
pallet select the Round LED and drag it to the Front panel.
Resize and name the indicator so it is easy to find. In this case the name was changed to Dark Yet?
On the Block Diagram expand the while loop to provide room. Move the indicator inside the loop.
mySTEM Project Board
170
mySTEM Project Board
Right click on the block diagram and from the Functions pallet select the Programming pallet and then
the Comparison pallet. On the Comparison pallet select the Greater? And place it on your block diagram.
This block will allow the comparison of the value of the data being collected and compare it to a preset
quantity. It will provide a Boolean result based upon the comparison. Wire the data into a terminal on
the Greater? Block.
On the other input to the comparison block right click and select create constant.
171
mySTEM Project Board
Enter in a value that you know will require shading of the sensor to reach.
In this example enter the number 1 is used and it represents one volt.
Finish wiring the block diagram.
Connect the power and run the VI.
You should see the meter provide you with the current reading. The LED will not light until the data
value is above the preset limit.
To change the value for the comparison the value of the constant can be changed. This is fairly time
consuming and you cannot adjust it while the VI is running. Stop the VI and turn off the power to the
circuit.
mySTEM Project Board
172
mySTEM Project Board
Right click on the front panel and from the Modern pallet select the Numeric pallet and then select the
Knob. This allows for continuous adjustment.
Place the Knob on the front panel. Resize and rename the knob. Then click on the last number on the
dial and change it to match the highest value on the meter.
This will change your scale to match.
Right click on the knob and select Digital Display so we will have the value displayed.
173
mySTEM Project Board
You can set the value by turning the knob or by typing in the value window.
On the Block Diagram drag the Value Set knob into the while loop and position it near the comparison
block.
Delete the constant and then wire the knob to the comparison block.
Turn on the power to the sensor and run the VI again. Use the knob or Value set window to change the
value while the VI is running. You are now making a digital decision with an analog sensor input. This
allows you to combine input from several types of digital and analog sensors to control outputs. For
information on turning motors on and off see the exercise on Digital Outputs.
See the exercises on the Introduction to Logic Gates for information on how to combine the various
inputs to select when an output occurs.
mySTEM Project Board
174
mySTEM Project Board
Introduction to Logic Gates
Logic gates allow us to take inputs and make decisions upon them. In the exercise above you created an
output directly tied to a switch. What follows will allow us to derive an output from a combination of
inputs. For these exercises it is necessary to have the programming pallet visible.
For an excellent explanation of logic and Boolean Algebra see the All About Circuits Website.
http://www.allaboutcircuits.com/vol_4/chpt_7/1.html
The NOT Gate
The not gate is the simplest of gates with only one input and one output. Sometimes these gates are
called inverters. Start by placing a button. You will find the buttons in the Control elements found in the
Operating elements section.
Using the LED and Switch we placed earlier we can begin the exploration of logic. Start by erasing the
connector between the switch and light. Simply click on the wire and select delete.
You should be back to just the independent control and indicator.
Right click on the block diagram. From the programming palette select the Boolean Palette and then on
the Boolean Palette select the Not gate. Drag the Not gate to the block diagram.
175
mySTEM Project Board
Wire the not gate between the output and Switch 1.
Truth Table:
Start the program. When the program is running record what you see in the chart below. When writing
logic the switches are represented by the letters A, B , C etc. The output is represented by the letter Y.
Click on the Switch to toggle it from a 0 to a 1. If you see a 0 in the chart that means the Switch should
be off. Observe the Logic lamp. If the light is off place a 0 in the logic column. If the light is on place a 1 in
the logic column.
NOT
A
0
1
Y
Boolean Expression:
A Boolean Expression is a mathematical expression detailing the relationship between the inputs and
the outputs. It is written in the form of the Output equals the Input that caused the output. The Input in
our example is called A. Since A has two states we call it A when the input is High and NOT A when the
input is Low. We write NOT A by placing a bar over the letter.
In our example the Output is called Y. From your Truth Table above you must determine the formula.
Circle the correct one below and cross the other out. Ask yourself was the Y Lamp lit when A was
pressed or not pressed.
AND and OR Gates:
Logic depends on a combination of inputs. We use Logic gates to create an output when we see a
desired combination of inputs. This exercise will help you understand the basic logic involves and how to
translate from Boolean Expressions to Truth Tables to Control Circuitry.
mySTEM Project Board
176
mySTEM Project Board
Begin with the program you wrote in the above exercise. The first step in this exercise is to erase the Not
gate. Then delete the wires. Place a second Switch on the Front Panel. Name the second switch B and
rename Switch 1 to A. This way they will match the truth tables. Rename Output to Y to match the
Truth Tables.
On the Block Diagram right click and select the Boolean Palette from the Programming Palette and place
an AND gate.
Wire the circuit together.
177
mySTEM Project Board
AND Gate Truth Table:
Start the program again. When the program is running record what you see in the chart below. Click on
the Switches to toggle the value from a 0 to a 1. (off to on). There are four possible combinations. If you
see a 0 in the chart that means the switch should be off. Observe the Logic indicator. If the light is off
place a 0 in the Y logic column. If Y is on place a 1 in the Y logic column.
A
0
1
0
1
AND
B
0
0
1
1
Y
Boolean Expression:
Since there are two inputs there are more possibilities for the Boolean expression. From your earlier
research you found out that we are interested only in the value of the Inputs when the Output is High.
Write the Boolean expression for the AND gate below.
OR Gate
Stop the program and then right click on the AND and select the Replace option. Select the Boolean
Palette option and then click on the OR gate. This will change the gate without having to rewire the
circuit.
mySTEM Project Board
178
mySTEM Project Board
Repeat the process with the Switches and fill in the OR truth table and write the Boolean Expression for
the OR Gate.
A
0
1
0
1
OR
B
0
0
1
1
Y
Boolean Expression:
NOR Gate
Replace the OR gate with a NOR gate.
This logic is called a NOT OR or NOR for short. Repeat the test to discover the truth table. Record it
below. Write the Boolean expression next to the Truth Table.
A
0
1
0
1
NOR
B
0
0
1
1
Y
NAND Gate
Replace theNOR gate with an NAND gate. Now we have a NOT AND gate, a NAND for short. Develop the
truth table for this one and write the Boolean expression for the gate next to the truth table.
A
0
1
0
1
NAND
B
0
0
1
1
Y
Conclusion
1.
2.
3.
4.
Describe in words each gate and what inputs are required to get an output.
How does the truth table of an AND gate differ from an OR gate?
Describe the difference between the AND and NAND truth tables?
Could you use a truth table to figure out which gates to use to solve a problem?
179
mySTEM Project Board
mySTEM Project Board
180