0Pricing
Arduino & IoT Academy · Lesson

map() Values to a New Range

Rescale raw readings into useful units.

map() Values to a New Range is a free Arduino & IoT Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Raw Values Are Awkward

A 0 to 1023 reading rarely matches what you need. Often you want a percentage or an angle, not a raw sensor count.

Meet the map Function

The map function rescales a number from one range into another. It does the proportional math so you do not have to.

Its Five Arguments

You give map five things: the value, plus the low and high of its current range and the low and high of the target range.

map(value, fromLow, fromHigh, toLow, toHigh);

Scale to a Percentage

To turn a knob into 0 to 100 percent, map from the analog range to a percent range. The result reads like a volume dial.

int pct = map(analogRead(A0), 0, 1023, 0, 100);

Scale to a Servo Angle

Servos expect 0 to 180. Map a knob into that range and the reading becomes a usable angle for the motor.

int angle = map(analogRead(A0), 0, 1023, 0, 180);

It Returns Whole Numbers

The map function works in integers, so it returns whole numbers and drops the fraction. That is fine for most controls.

You Can Flip the Range

Set the target low above the high to invert the output. Now turning the knob right makes the result go down.

int v = map(analogRead(A0), 0, 1023, 100, 0);

It Does Not Clamp

The map function will go past your limits if the input does. Use constrain afterward to keep the result safely inside bounds.

int v = constrain(map(x,0,1023,0,100),0,100);

Negative Ranges Work Too

Targets can be negative, like -50 to 50 for a centered control. The map math handles that direction with no extra effort.

Map for Brightness

Pair map with PWM later to set brightness. A knob can scale neatly into the 0 to 255 range an LED dimmer expects.

int b = map(analogRead(A0), 0, 1023, 0, 255);

A Tool You Will Reuse

You will reach for map constantly: percentages, angles, ranges, and more. It turns raw sensor data into meaningful numbers.

Quick Check

What is the job of the map function?

Recap: Rescaling with map

You learned map rescales a value between ranges using five arguments. Pair it with constrain to clamp results into safe bounds.

Frequently asked questions

Is the “map() Values to a New Range” lesson free?

Yes — the full text of “map() Values to a New Range” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.

What will I learn in “map() Values to a New Range”?

Rescale raw readings into useful units. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Arduino & IoT Academy?

No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “map() Values to a New Range” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Arduino & IoT Academy lesson?

Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Digital vs Analog Signals
  2. analogRead Returns 0–1023
  3. Read a Potentiometer Knob
  4. map() Values to a New Range
← Back to Arduino & IoT Academy