As soon as you open the Arduino IDE, you will see a window of the Arduino code , consisting of basically two main parts: setup and loop. The entire code written in the Arduino IDE is known as sketch. A sketch is the name that Arduino uses for a program. It’s the unit of code that is uploaded to and run on an Arduino board. they are written in C/C++.
Arduino code: setup() and loop()
These are the two most important functions used in Arduino. The setup() function runs once in the entire program whereas loop() function is the heart of the Arduino sketch where the written commands are run over again and again. setup() is a good place to do tasks like setting pin modes or initializing libraries. You need to include both functions in your sketch, even if you don’t need them for anything.
Other Important functions
- pinMode(): This function configures a pin as either an input or an output. Syntax : pinMode(pin number, OUTPUT/INPUT);
- digitalWrite() : This outputs the value on a pin. Syntax: digitalWrite(pin number, HIGH/LOW) ;
- delay(): The delay tells the Arduino to wait for the milliseconds specified inside the brackets. Syntax : delay(number of milliseconds);
Uploading the sketch
To upload a sketch, click on the Tools option in the tools bar at the top. Select the board as Arduino Uno/nano and the port in which it is plugged. After saving the sketch, press Ctrl+U or press the second icon(the arrow button) below the tools bar.
Comments in Arduino
Everything between the /* and */ is ignored by the Arduino. It is written so that the user is able to explain exactly how the code will work, which pins are used, etc. For a single line comment, you should write ‘//’ and then the comment.