Skip to main content

range

Scale, clamp, or wrap numeric values between configurable input and output ranges.

Overview

The range node maps numeric values from one range to another. It supports three actions: scale (linear interpolation), clamp (limit to bounds), and wrap (modulo wrap-around). Essential for converting raw ADC readings to engineering units, mapping sensor inputs to PWM outputs, or normalizing data for dashboards.

Scale
Linear Map
Clamp
Limit Bounds
Wrap
Modulo
Round
Integer Option

Properties

Property Type Default Description
action string "scale" Action type: "scale", "clamp", or "wrap"
minIn number 0 Input range minimum
maxIn number 100 Input range maximum
minOut number 0 Output range minimum
maxOut number 1 Output range maximum
round boolean false Round result to nearest integer

Range Actions

Scale (Linear)

Linear interpolation between ranges

// Formula:
// out = (val - minIn) / (maxIn - minIn)
//       * (maxOut - minOut) + minOut

// Example: 0-1023 → 0-3.3V
// Input:  512
// Output: 1.65

Clamp

Limit value to stay within output range

// Scales then clamps:
// minOut=0, maxOut=100

// Input:  150 → Output: 100
// Input:  -20 → Output: 0
// Input:   50 → Output: 50
// Values never exceed bounds

Wrap

Modulo wrap within the output range

// Wraps around using modulo:
// minOut=0, maxOut=360

// Input: 370 → Output: 10
// Input: 720 → Output: 0
// Input: -10 → Output: 350
// Useful for angles/rotations

Example: Sensor ADC to Voltage Conversion

Convert a 10-bit ADC reading (0-1023) to an analog voltage (0-3.3V).

// Range node configuration
{
  "action": "scale",
  "minIn": 0,
  "maxIn": 1023,
  "minOut": 0,
  "maxOut": 3.3,
  "round": false
}

// Input message
{
  "topic": "adc/channel0",
  "payload": 512
}

// Output message
{
  "topic": "adc/channel0",
  "payload": 1.6504
}

// Another example:
// Input: 1023 → Output: 3.3
// Input: 0    → Output: 0
// Input: 768  → Output: 2.475

Example: PWM Duty Cycle Mapping

Map a 0-100% brightness percentage to a PWM duty cycle value (0-255) for LED control.

// Range node configuration
{
  "action": "clamp",
  "minIn": 0,
  "maxIn": 100,
  "minOut": 0,
  "maxOut": 255,
  "round": true
}

// Input: brightness slider at 75%
{
  "payload": 75
}

// Output: PWM value (clamped and rounded)
{
  "payload": 191
}

// Clamp prevents over-drive:
// Input: 120 → Output: 255 (clamped to max)
// Input: -10 → Output: 0   (clamped to min)

Example: Joystick to Servo Angle

Map an analog joystick input (-512 to 512) to a servo angle (0-180 degrees).

// Range node configuration
{
  "action": "scale",
  "minIn": -512,
  "maxIn": 512,
  "minOut": 0,
  "maxOut": 180,
  "round": true
}

// Joystick centered (0)
{ "payload": 0 }   // → { "payload": 90 }

// Joystick full left (-512)
{ "payload": -512 } // → { "payload": 0 }

// Joystick full right (512)
{ "payload": 512 }  // → { "payload": 180 }

Common Use Cases

ADC Conversion

Convert raw ADC counts to engineering units (volts, amps)

Motor/Servo Control

Map UI sliders to PWM duty cycles or servo angles

Dashboard Gauges

Normalize sensor values to 0-100% for gauge widgets

Color Mapping

Map temperature ranges to RGB color values for indicators

Related Nodes