logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Arduino

How to Use Map Function Using Arduino

DevicePlus Editorial Team
Published by DevicePlus Editorial Team at March 10, 2020
Categories
  • Arduino
Tags
Arduino map function

Introduction

Have you ever noticed interconnected electronics are always compatible in their working ranges despite having different units and different extents of upper and lower limits? For example, while playing a video game on Playstation 4, when you pull your movement thumbstick all the way to the right, it is translated into maximum movement of your character to the right. So we can say that the extent of your thumbstick and the extent of your character movement is matched. This process of calibrating the extents at different stages is called “mapping”.

The mapping process is generally used to calibrate the input values from sensors according to the desired actuation. For example, in the case of an electronic steering wheel in a modern automobile, for a 720-degree rotation of the wheel, the wheel of the car turns approximately 40 degrees. Therefore, we can see that the 0-720 degree range has been mapped to 0-40 degrees by the electronic control system being used in electronic steering. Such electronic control systems incorporate the use of microcontrollers or PLCs. It is necessary to have analog input on a microcontroller that can be mapped for the desired actuation through PWM or digital pins. By the end of this DIY project, you will be able to understand:

  • What is mapping?
  • How to read sensor input
  • How to map the sensor input to the desired range of values
  • How mapped range is used for the desired actuation
  • Syntax of the map function in Arduino
  • Application of the map function using Arduino UNO

Overview

In this DIY project, we’ll develop a process to translate changes in resistance of the potentiometer against the desired number of LEDs using Arduino UNO. In other words, in this case, the potentiometer is being used as a “sensor input,” Arduino UNO is being used as a “mapping device,” and 10 x ROHM LEDs are being used as actuators. LEDs are usually delicate items and they usually present random faults. Therefore, we have chosen ROHM LEDs, and they provide sufficient endurance against current spikes and show consistent performance. Ten Blue ROHM LEDs will be mapped against the rotation of the potentiometer. The explanation of this project will follow the following sequence:

  • Required components
  • Circuit schematic
  • Setting up Arduino IDE
  • Programming
  • Execution

Required Components

Component Link/Picture
10 x ROHM Blue LEDs https://www.rohm.com/products/led/led-lamps-mono-color-type/sla560bct-product

Arduino UNO R3 https://www.aliexpress.com/item/32981776049.html

USB B Cable

(Mostly comes in package with Arduino UNO R3)

10k Potentiometer https://www.aliexpress.com/item/32859477972.html

830-point solderless breadboard https://www.aliexpress.com/item/32701019904.html

20x male to male jumper wires https://www.aliexpress.com/item/32951945552.html

1 x 1k Ohm Resistor Any Electronics Shop

Windows-based computer for programming

 

Circuit Schematic

Once all the components have been procured, the first step is connecting everything. Connection requirements are as follows:

  • Principally for this project, you are required to connect the positing end (longer terminal) of 10 x ROHM blue LEDs separately to digital pins of Arduino.
  • For this particular example, we have used digital pins 4-13.
  • The negative terminal of each LED is required to be connected to the ground through 1kOhm resistor.
  • The potentiometer has three terminals. The first is connected to the ground terminal of Arduino, the second is connected to analog pin A5 and the third terminal is connected to 5V. Doing this will vary the voltage at the second terminal from 0-5 V.

Connection Schematics are shown as follows:

connection schematics

The Actual Wiring will appear as shown below:

wiring to breadboard

  • At this stage, your system has been wired up and you are ready to program your Arduino UNO R3.

Setting Up Arduino IDE

Programming of Arduino requires setting up of the Arduino IDE. The Arduino IDE is available for Linux and Windows. For this DIY project, we will be using the Windows desktop application. Visit the following link to download and install Arduino IDE:

  • https://www.arduino.cc/en/Main/Software
  • Choose following Link:
    1. Windows Installer, for Windows XP and up

After successful installation, open Arduino IDE and connect your Arduino UNO R3 using USB B Cable:

Arduino Map Function

  • Select the appropriate COM Port from Tools > Port > COM 3 (Arduino Genuino / UNO) in Arduino IDE.
  • At this stage, your setup is ready to begin the programming.

Programming

In Arduino programming, there are two basic functions: Void Setup and Void Loop. The complete code and its explanation is as under:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
void setup() {
//Declare A5 Analog pin as input pin
pinMode(A5, INPUT);
//Declare  4-13 Digital Pins as Output Pins (For controlling 10 x ROHM LEDs)
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
//Check Analog value at pin A5 and store it in variable x
  int x = analogRead(A5);
//Map analog values ranging from 1-1023 to values 0-10
  int y=map(x,0,1023,0,10);
/*Use a loop to turn off LEDs having number greater than y. Here “i+3” corresponds to pin number on arduino. Since 10th LED is connected to Digital Pin number 13. Therefore +3 offset has been used*/
  for (int i=10; i>y; i--)
  {
    digitalWrite(i+3,LOW);
  }
//Use a loop to turn on LEDs having number lesser than y
  for (int i=0; i<y; i++)
  {
    digitalWrite(i+4,HIGH);
  }
  delay(5);
}
//As a result number of LEDs lit will corresponding to the position of potentiometer

Execution

If you are not powering Arduino UNO through an external Jack, keep it connected to your computer during execution. Now rotate the potentiometer from one end to another end. When the potentiometer is giving 0 value at the analog pin, no LEDs will lit. While the potentiometer is rotated, the number of glowing LEDs will keep increasing. Once the value given by the potentiometer reaches 1023, the number of LEDs will reach 10. In this way, we can say we have mapped the range of sensor values to the number of LEDs.

  • Initial position of potentiometer. (Analog value 0)

  • Midway position of potentiometer. (Analog value 512)

  • Final position of potentiometer. (Analog value 1023)

DevicePlus Editorial Team
DevicePlus Editorial Team

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • How to detect motion in your Arduino with an accelerometerHow to detect motion in your Arduino with an accelerometer
  • Using Arduino with Parts and Sensors – Stepper Motor Part 1Using Arduino with Parts and Sensors – Stepper Motor Part 1
  • How to control your computer using hand gesturesHow to control your computer using hand gestures
  • Let’s use Arduino with a light sensor!Let’s use Arduino with a light sensor!
  • How to Measure Distance using ArduinoHow to Measure Distance using Arduino
  • The Basics of Arduino Electronics: Controlling the MotorThe Basics of Arduino Electronics: Controlling the Motor
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2023. Device Plus - Powered by ROHM
© 2023 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort