Arduinos Map Function and How to Use it

arduino logo

What is Arduinos Map Function?

Arduinos Map Function is a useful utility function that helps you remap or scale a value from one range to another. It’s often used to convert an input value (e.g., from a sensor or user input) that falls within one range to an output value that falls within a different range. This is particularly handy when you need to adapt sensor readings to control actuators or display data on a screen with Arduino.

Here's a brief explanation of the map() function:

Basic Syntax:
mappedValue = map(inputValue, inputMin, inputMax, outputMin, outputMax);
  • inputValue: The original value you want to map to a new range.
  • inputMin and inputMax: The minimum and maximum values of the original range (the range of the inputValue).
  • outputMin and outputMax: The minimum and maximum values of the target range (the range you want to map inputValue to).

The map() function takes inputValue, which typically falls between inputMin and inputMax, and scales it linearly to a new value (mappedValue) within the range defined by outputMin and outputMax.

Here’s an example:
int sensorValue = analogRead(A0);  // Read a sensor value between 0 and 1023
int motorSpeed = map(sensorValue, 0, 1023, 0, 255);  // Map it to a motor speed between 0 and 255

In this example, the sensorValue is read from an analog sensor (which provides values between 0 and 1023), and the map() function is used to convert it into a motor speed value between 0 and 255. As the sensorValue changes, the motorSpeed will also change accordingly, allowing you to control a motor based on the sensor input.


The map() function simplifies the process of scaling values, making it easier to adapt input from various sensors or user inputs to control different output devices within the desired range.


If you don’t already own any Arduino hardware, we highly recommend purchasing the Elegoo Super Starter Kit. This kit has everything you need to start programming with Arduino.

You can find out more about this kit here: Elegoo Super Starter Kit

Luke Barber

Hello, fellow tech enthusiasts! I'm Luke, a passionate learner and explorer in the vast realms of technology. Welcome to my digital space where I share the insights and adventures gained from my journey into the fascinating worlds of Arduino, Python, Linux, Ethical Hacking, and beyond. Armed with qualifications including CompTIA A+, Sec+, Cisco CCNA, Unix/Linux and Bash Shell Scripting, JavaScript Application Programming, Python Programming and Ethical Hacking, I thrive in the ever-evolving landscape of coding, computers, and networks. As a tech enthusiast, I'm on a mission to simplify the complexities of technology through my blogs, offering a glimpse into the marvels of Arduino, Python, Linux, and Ethical Hacking techniques. Whether you're a fellow coder or a curious mind, I invite you to join me on this journey of continuous learning and discovery.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights