Map() function in arduino programming || Arduino programming tutorial -11

In this tutorial, we will see about map function. What is map function, Why it is used And how to use map function? We will cover all this free question in this tutorial, So without wasting any time lets start. First of all, we will see what is map function. Map function is a function. By using it, We can convert a number range to another number range, Its Syntex is map And inside it you have to write first, the name of that Variable of which you want converts its range. And after this you have to write the minimum value of this range, Maximum value of this range, And So far as you want to map this range Here have to write its minimum value And here have to write its maximum value. So this is the syntax of map function. Now we will take its example. Suppose I connect an LED with pwm pin of arduino and I connect a potentiometer with analog pin of arduino, And here I want to control the brightness of LED by potentiometer. So for this I use map function, And for this I will take an integer data type variable i, And inside this variable I will store the value of potentiometer And the minimum value that will store in this variable Will be 0 and maximum value will be 1023. Now I will write map function Inside map function. I will write variable I And after this I will write The minimum value that store in this variable, which is 0.

And after this I will write the maximum which is 1023 And because I connect LED with pwm pins of arduino And the output from the pwm pin will be from 0 255, So thats. Why inside map function, I will write 0 and 255 So, like this map function, converts the range that stored in variable i from 0 1023 to 0 255, And after this we will store this mapped value in another variable, So thats, why? I will write here: int j, So like this all the 256 values that we get from map function Will be stored in variable j, And after this I will write this variable inside analogwrite function. So like this, when I rotate the potentiometer, Then its Total 1024 values will be stored in variable. I And map function will converts this 1024 0 1023 values to 2560 255 values, And after that, this 256 values will go to analogwrite function That will control brightness of LED. So friends like this in this tutorial, we learned about map function. Next, video, we will control Servo motor with the help of potentiometer by using map function. Please, like this video And share this video, And if you want to learn arduino programming from basics, Then please subscribe our YouTube channel and press the bell icon.

Share.
Exit mobile version