We all are well familiar with Arduino board family. It’s a huge family of development boards which is useful from simple to complex projects. All these boards have some specifications regarding the operating voltage, memory, size and much more. But one thing that is common in all these boards is usage of Arduino IDE for programming purposes. All programs that are developed using Arduino IDE are known as sketches. So in this article we are going to see the Arduino IDE user interface and functions of some main buttons. We will discuss shortly that what points should be in our mind while writing a function, some basic type of errors that we can encounter, setup () and loop () functions that pre-defined whenever we make a new sketch and a sample Hello World sketch
ARDUINO IDE USER INTERFACE
So in this section we are going to explain some icons that are found at the top of Arduino IDE user interface and their functions.
- In order to verify your code, make use of this button. It will indicate any error if present in your code before uploading the sketch on Arduino board.
- After verification of your code use this button to upload the sketch.
- If you want to open a new editor window in place of your current code editing window then this button comes handy.
- To open a new file, this button is used.
- Use this button to save your sketch.
- To open a serial monitor for debugging purpose, this button is used.
- It gives you the option to add a sketch in your current project i.e. opening a new tab in your current project.
STRUCTURE OF ARDUINO SKETCH
Arduino programs made in Arduino IDE are known as sketches. So if we talk about the structure of basic Arduino sketch, then we can say that it consists of two mandatory functions known as setup () and loop () functions. Whenever we open a new window in Arduino IDE we can see that these two functions are already present in new sketch. So let’s talk about the basic necessities of functions and will explain it using hello world problem as a tradition to introduce beginners with programming.
WHAT IS A FUNCTION?
In order to define a function, we need to follow these instructions as a must:
v All function should have a unique name. For example setup () is an example of unique function name. It can be any name but it must be unique i.e. not more than one function can have same name in the same sketch otherwise there will be an error. The two main programs we discussed above that constitute the body of Arduino sketch i.e. setup () and loop () functions are special functions of Arduino program.
v The function name should be followed by closing and opening parentheses (). It is not mandatory to write something in function’s parentheses. Basically in function’s parentheses we can pass reference to some variables whose value is going to alter. These references to variables can be by name or by value. We will discuss detail of this later somewhere.
v All functions of Arduino sketch should have a return type. Mostly return types that are used are return 1, return 0 or void. The mandatory functions of Arduino sketch i.e. setup () and loop () are having void return type.
v The body of function is enclosed in opening and closing braces i.e. { }. The action we need our function to perform is present in these braces.
So let’s discuss all these requirements of function formation with some example.
HELLO WORLD SKETCH EXAMPLE:
So by following tradition set by programmers let’s start with hello world program in order to introduce beginners to programming in Arduino IDE. So if we talk about this function. It only prints the text “hello world” on the screen whenever we run this program. It is mostly used to ensure that our programming environment is installed properly and is in working form. If this “hello world” program runs smoothly without any errors then we can surely say that you are ready to start with the learning of new programming language. As we know that Arduino don’t come up with a screen so if we write this “hello world” program then where we will print it? Here we can make use of serial monitor window and the USB port.
SKETCH WRITING:
Now save this sketch in your sketch folder.
void setup() { Serial.begin(9600); Serial.println("Hello, world!"); } void loop() { }
RUNNING OF SKETCH:
We can run this sketch by plugging our Arduino in our PC by making use of a USB cable. After connecting it with PC, click the upload button in order to load program in our Arduino. Now after successful uploading of this code in our Arduino, open the Arduino serial monitor to see the sketch running and you can see the printed text over there.
ERROR FINDING:
The most errors or faults we can encounter are
v Programming errors
v Setup faults
v Baud rate settings fault
So let’s briefly discuss about these types of errors and faults.
PROGRAMMING ERRORS:
If we do some mistake while typing the above program in Arduino IDE then we have to face error. This type of error is known as compile error. If you want to make sure that you have typed everything correctly then you can verify that by using verify button in Arduino IDE. The compile error can be check in the bottomed Arduino IDE. Suppose you missed semicolon or parentheses or stuff like that then error will be displayed in some meaningful language when you will verify your program or upload it in your Arduino board. So you can open that error and can correct it by understanding your mistake and re-run that program
SETUP FAULTS:
Now coming to the second type of error which can be caused when we have verified our program and it’s not giving any sort of compile errors but still it’s not getting uploaded on our Arduino board. In case of this problem you have to make sure that you have selected the right board and it can be verified under tools -> board and also make sure that serial port is also correct by checking in tools -> serial port.
BAUD RATE SETTINGS FAULT:
The last type of error that can be expected is baud rate setting fault. At this point we are expecting that there are no compile or syntax errors and our program is uploaded successfully on Arduino board but still as expected from Hello World program we are not getting hello world printed on serial monitor. So in this case the only error that can prevent text from being printed / shown in serial monitor is that the baud rate settings at bottom right of our serial monitor window is not set to the value 9600 as we have declared that rate in our setup () as 9600. So because of this mismatch of values of baud rate we cannot see hello world printed in serial monitor so it can be corrected by just changing this value in our Arduino IDE.
SETUP () AND LOOP () FUNCTIONS:
v Setup (): It is always executed first. If we take example of our hello world sketch we are just setting baud rate to 9600 so our serial.begin (9600) will run first and then our printIn () function. This function is only executed once every time that sketch is run and it will start it’s execution of instruction present in it once it has been programmed in our Arduino board. It can be re-run by using reset button or by connecting Arduino again by disconnecting it
v Loop (): Statements present in loop () function will continuously run from top to bottom and then back to top. In our Hello World sketch we have nothing in loop function so our sketch will end up there. But even if we have nothing to do in loop () we still have to use this function in our sketch otherwise our microcontroller will start executing whatever it finds next in memory. So in order to prevent this issue we have to define loop function in our sketch. The operational functionality of Arduino takes place in loop () function.
I hope this article helps you in understanding functionality of Arduino IDE. Feel free to give your suggestions or to ask any question regarding this article in comment section below.
Pretty! This has been an incredibly wonderful post. Thanks for supplying this info.