This is a very important function in the arduino. This is similar to the part of the main() function before any process starts.
For ex: 1. pinMode (13, OUTPUT),
2. digitalWrite (11, HIGH),
3. Serial.begin (9600)
Initialization of pins and declaration of variables is done at the starting of the program outside the setup() function.
For example: int a=100, pin1=8
1. pinMode() is an instruction which is used to set the mode in which we are going to use the pin 13, i.e. we are setting pin13 as output.
2. digitalWrite() is used to write the value to the pin 11 i.e. high
3. This instruction is used for serial communication with other devices. For that we have to decide the speed of communication then only data will be synchronized.
4. A is a variable of type integer and 100 is stored in it.
5. Pin1 is also an integer variable, which has assigned 8th digital pin.
This is another important function in the arduino program. Loop is what? It is something that repeats itself infinite number of times. So whatever you are writing inside loop() function, it will be executed every time once the pins, variables and other things are fixed accordingly in setup() function. This is similar to any normal loop in the c language. You write some instructions in that and those instructions will get executed after satisfying some condition.