askvity

What is the Range Block in EV3?

Published in EV3 Programming 3 mins read

The Range block in LEGO MINDSTORMS EV3 programming is a logic block used to determine if a given numerical value falls within or outside a predefined numerical interval. Its primary function is to test a number against a specified range and provide a simple True or False result based on the outcome.

Understanding the Function of the Range Block

As stated in the provided reference, the Range block tests whether a number is inside or outside a specified numerical range. This means you provide the block with a number to evaluate and define the minimum and maximum limits of the range you are interested in.

The block then performs a comparison to see where the input number stands relative to these limits.

  • Input: The Range block requires a single numerical input value, which is the number you want to test.
  • Range: You configure the block with the lower (minimum) and upper (maximum) boundaries of the numerical range.

Range Block Modes: Inside or Outside

The functionality of the Range block is controlled by its Mode Selector. This allows you to choose how the test is performed relative to the specified range.

Use the Mode Selector to choose whether to test if a number is Inside or Outside a range.

  • Inside Mode: In this mode, the block outputs True if the input number is greater than or equal to the minimum value AND less than or equal to the maximum value. Otherwise, it outputs False.
  • Outside Mode: In this mode, the block outputs True if the input number is less than the minimum value OR greater than the maximum value. Otherwise, it outputs False.

Output of the Range Block

The outcome of the Range block's test is always a Boolean value.

The output result is True or False.

This True/False output is typically used to control the flow of your program, for example, determining whether to execute a specific sequence of actions based on a sensor reading falling within or outside a desired range.

Practical Applications and Examples

The Range block is invaluable for creating programs that react dynamically to data, especially from sensors.

Here are some practical examples:

  • Sensor Thresholds: Check if a Color Sensor reading is within the range for the color Red (e.g., 50-60) or outside the range for Bright Light (e.g., outside 80-100).
  • Distance Monitoring: Verify if the Ultrasonic Sensor detects an object within a safe distance (e.g., 5-30 cm) or if it's too close (outside 0-5 cm).
  • Motor Control: Ensure a motor's rotation count or position is within acceptable limits (e.g., between 0 and 360 degrees).
  • Variable Checking: Test if a calculated score or counter variable is within a specific tier (e.g., score between 70 and 85 for a 'Good' rating).

By providing a clear True/False output based on numerical limits, the Range block simplifies complex conditional logic in your EV3 programs.

Related Articles