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:
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
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 | ![]() |
Once all the components have been procured, the first step is connecting everything. Connection requirements are as follows:
Connection Schematics are shown as follows:
The Actual Wiring will appear as shown below:
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:
After successful installation, open Arduino IDE and connect your Arduino UNO R3 using USB B Cable:
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.