LEGO Engineering

| | | | | | | |
How can I do I combine the values of different sensors in NXT-G? For example, how could I program the motors to start only when there is combination of a loud sound AND a bright light?


20th of April, 2010

(4 )
75% thumbs up 25% thumbs down

Sensor values can be easily combined using the wiring ports on the sensor blocks. The sensor blocks are different from the 'wait for' blocks, as they have wiring capabilities and return the value of the sensor.  Also, they don't delay the program with a 'wait' command, but run continuously. As a result, if you want such a program to run properly, chances are you will have to put it in a loop to allow the motors to run in the way that you want them to. Without a loop, a value wired to a motor will only be sent once, that value being the initial condition of the environment that the sensors detect, and the program will end very quickly.

The best way to make the motor act differently depending on a combined sensor value is to use a logic switch. When you open a switch block, the first pull-down menu in its options is whether you want to use it as a sensor switch or value switch. In this case, you want to use the value option, which will in turn allow you to choose whether to use logic, a number, or text. Here you want logic. If you combine the sensor values using a math block and compare that combined value to a threshold value using a comparison block, then you will get a true/false result. Wire this into the logic switch, and in the 'true' part of the switch put a motor forward block, and in the 'false' part of the switch, put a stop motor block. This should make the motor move forward if the values are above the threshold and stop when they are not.

Another way to accomplish this, if you want to be sure that each sensor value is above its own threshold, is to use two separate comparison blocks, one for each sensor, asking whether or not the value is above its threshold. (The threshold is designated in the Comparison block, not the the sensor block here, unlike the 'wait for...' blocks.) Then wire both comparison blocks to a logic block to ask whether both are true. Wire the logic block to the logic switch described above. This will have the same result with more individualized sensor options.

     The first option is shown below:



This (above) is the sensor bar on the complete palette... it is not the same as the \"wait for\" bar on the common palette (shown below).





This (above) is the logic switch control box for the program below.  Notice that the 'control' menu option is set for value, not sensor (which is the default).



   :
   :
* :
* :
 


Home | About Us | Contact Us

© 2013 Center for Engineering Educational Outreach, Tufts University
© 2013 The LEGO Group. All rights reserved.