Vidyasagar Academy Wishes a Very Happy, Healthy & Prosperous Diwali to all our Students & Teachers!
- Basics of Arduino Coding
- How to use Android Phone to write codes and upload in Arduino?
- Effective coding techniques in Arduino: More about datatypes
- Effective coding techniques in Arduino: More about variables
- How to design Cathode Ray Oscilloscope using Arduino? Code of just 9 lines!
- How to start learning NodeMCU in simple steps? Basic Tutorial on NodeMCU
- How to use array to rotate servo motor in different angles?
- Blinking LED code for Arduino in Assembly Language Programming (ALP)
- Having trouble to drive Servo motor with Arduino Uno SMD? Get perfect solution now…
An array is a collection of values which are accessed with an index number. Any value in the array may be called in the program by calling the name of the array and the index number of the value.
The students who studied Python programming at Vidyasagar Academy will understand array and its indexing more easily.
The indexing of array starts from 0 i.e. the first value in the array begins at index number 0. An array needs to be declared and optionally assigned values before they can be used.
int arrayname[] = {value0, value1, value2...}
Likewise it is possible to declare an array by declaring the array type and size and later assign values to an index position:
int arrayname [5]; // declares integer array with 6 positions
arrayname [3] = 10; // assigns the 4th index the value 10
To retrieve or call a value from an array, assign a variable to the array and index position:
x = arrayname [3]; // x will be equal to 10
Arrays are often used in for loops, where the increment counter is also used as the index position for each array value.
The following example uses an array to rotate the servo motor, connected to pin-3 of Arduino UNO or Arduino Nano in different angles from 0 degree to 180 degree in steps of 30 degrees.