yancy-min-842ofHC6MaI-unsplash

Lego MINDSTORMS EV3: Logic Operations Block In Detail

In Lego Mindstorms by Glenn TurnbullLeave a Comment

In this post we will cover the Logic Operations programming block used within the Lego MINDSTORMS EV3 programming software. We will cover all the available options and also provide a step by step example program.

What Is the Logic Operations Block?

The Lego EV3 Logic Operations block is used to perform a logic operation on the passed inputs. It takes 2 logic (true/ false) inputs and outputs a true or false output  depending on the mode and inputs. Using this blo

It’s available from the red data operations palette within the EV3 Programming Software.

Lego EV3 Logic Operations Block

What modes are available within the Logic Operations Block?

There are 4 modes available from within the Lego MINDSTORMS EV3 Logic Operations block:

AND Mode

AND mode of the Logic Operations block is the default mode. It uses both A and B input and it’s True if both A and B are True, and False for all other combinations.

Examples:

A Input B Input Output
True True True
False True False
False False False
True False False

OR Mode

Or mode uses both A and B inputs. Its True if A or B (or both) are True and False if both A and B are False.

Examples:

A Input B Input Output
True True True
False True True
False False False
True False True

XOR Mode

XOR mode uses both A and B inputs. Its True if A or B are False, False if both A and B are True and False if both A and B are False.

Examples:

A Input B Input Output
True True False
False True True
False False False
True False True

NOT Mode

NOT mode uses  A input only. Its True if A is True, False if A is False.

Examples:

A InputOutput
True True
False False

How to use the Lego EV3 Logic Operations Block?

All but the NOT mode of the Logic Operations block accept 2 inputs and has 1 output, the NOT mode accepts 1 input and has 1 output. All inputs (A and B) can be either be wired into or hardcoded directly within the program.

The example below uses the AND mod and will follow the True case route of the switch, changing either A or B input to False will follow the False route instead (see previous section for AND mode logic).

Lego EV3 Logic Block -Example

Lego EV3 Logic Operations Example Program

For the Lego MINDSTORMS Operations block example program we will create a program that will move the robot forward if the button is pushed, but it will only to this if no object is detected. If a object is detected 10cm (#Inches) or less away the robot will not respond to the button push.

Program Logic

  1. Using the Ultrasonic sensor check to see if there’s an object 10cm or less away
  2. Using the button sensor check to see if the button has been pushed
  3. If step 1 = 1 False and step 2 = 2 True then move the robot, otherwise stop the robot
    • Checking the modes above I’d like to move the robot if the output of step 1 and step 2 combined is True. Based on this we could use either the XOR or OR modes of the Logic Operations block.
  4. Repeat steps 1 through 3 for 20 seconds

Lets get started.

  1. Set up the loop and check for an object and a button push
    • Drag and drop an orange Loop block next to the Start block
      • Set its mode to Time Indicator
      • Set the Seconds input to 20
    • Drag and drop an yellow Ultrasonic Sensor block inside of the Loop block
      • Set its mode to Compare | Distance in Centimeters
      • Set the Compare Type to 4
      • Set the Threshold Value to 10
    • Drag and drop an yellow Touch Sensor block next to the Ultrasonic sensor block
      • Set its mode to Compare | State
      • Set the State to 1
Lego EV3 Logic Block -Example Program Step 1
  1. Check the output and either move or stop the robot
    • Drag and drop a red Logic Operations block next to the touch sensor
      • Set its mode to XOR
      • Wire the Compare Result (=) from the Ultrasonic block into the A input
      • Wire the Compare Result (=) from the Touch Sensor block into the B input
    • Drag and drop an orange Switch block next to the Logic Operations block
      • Set its mode to Logic
      • Wire the Result (=) of the Logic operations block into the logic input
    • Drag and drop a green Move Steering block into the True case of the switch
      • Set its mode to On for Rotations
      • Set the Rotations to 2
    • Drag and drop a green Move Steering block into the False case of the switch
      • Set its mode to Off
      • Set Brake at End to True

That’s it, hit the download and play button to test your program. The full program should look like the picture below (click to view a larger size):

Lego EV3 Logic Block -Example Program Whole Program

We hope you enjoyed this deep dive post into the Lego MINDSTORMS EV3 Logic Operations programming block. Feel free to leave a comment if you have any questions or have a suggestion for a future post.

Blog photo by Yancy Min on Unsplash 

Leave a Comment