Wednesday, 18 April 2018

Getting started with Arduino coding. (A beginner’s quick guide)



Welcome to my first Arduino coding guide. This would take you to kickstart with Arduino boards. I would go through following things really quickly and thoroughly. You would enjoy this post. Arduino boards are really famous for hobby and rapid prototyping, types of applications. Kids really love Arduino boards. If you are an engineering student. I would request you to please stay away from Arduino boards if you really want to learn how to build your own custom hardware boards. It might be good for the project but you may lose a lot of essential skills needed to design reliable hardware. You get lifelong skills when you get a problem and you solve it all the way on your own. You never forget that problem and learning.

 1)      Arduino setup (software and hardware)
 2)      Coding example

Arduino setup:

To program an Arduino board you need to install Arduino software. Here is the link to download Arduino software https://www.arduino.cc/en/Main/Software

Please, select Windows if you are using windows 10 operating system as marked in figure 1 below.

Figure 1 Download page.

Please click on just download as marked in figure 2 below. I would encourage you to donate them some amount because they are contributing towards a better future for your children and for young engineers. Your contribution would enhance the development process and I believe that your good deeds would come to you one day for sure. 

Figure 2. download the setup file

Please, wait for the Arduino setup to download. grab some popcorns with you :) 

Figure 3 waiting for a program to download

Once it is downloaded click to install it. use next→ next and you will reach to this point. you are almost done just wait for a couple of minutes for this installation as shown in figure 4.

Figure 4 waiting for the installation to complete

Wow at this point you are down with installation just double-click on Arduino you can find this icon on your desktop as shown in figure 5 below.

Figure 5. Wow its done Just double-click on this
Now, you would come to a window as shown in figure 6 below. we are done with the software setup.

Figure 6. Software installation is done.

Now, At this time I have an Arduino Mega 2560. This board comes with USB type B cable. Connect your board with USB cable connector on board and to computer's USB port. USB connector is marked in figure 7 below
Figure 7 USB connection to this board.

Now, you have to select the communication port for Arduino board. Go to Tools→Ports→(Select Mega2560) as shown in figure 8 below.

Figure 8 Communication port selection in Arduino (COM6).

Now, You have to select which board you are using. Go to Tools→Boards→(Select Mega2560) as shown in figure 9 below.

Figure 9. Arduino board selection.

At this point, you are done with Arduino setup both hardware and software. Now, you are ready to program your first "Hello world" code. By means, Hello World is the very basic code that we can program to test hardware.

Coding Example:

The basic thing about Arduino is there are two functions as you can see in figure 10 below. The first setup function is called at the beginning when you turn on the hardware. and the loop function would be called every time after that. So the tasks which you want to do once at the startup of a board like initializations of Input and Output ports should be done in setup() function.

Figure 10 Setup function
There is a default LED on almost every Arduino board and it is connected to PIN 13. For setup pin 13 to drive that LED we need to setup this pin in output mode. so that we can write onto it. As shown in figure 11 below. and then press Ctrl + S to save your code. I saved it as HelloWorld.

Figure 11 Pin mode as Output
At this point you are done with pin setup Now you have to write a value to this pin. High means this pin would give 5 volts output and LOW means this would give 0 volts to pin 13. Now you should also know that microcontrollers work at high speed. So you have to add delay within one high and one low to see that PIN is really blinking or not otherwise it would blink fast enough that you can never be able to see it. Please see the code in figure 12 below. I coded delay for 500millisecond. You would get one ON and one OFF in a single second on LED or PIN13. Save it.

Figure 12 LED blinking code.
Now you are done with HelloWorld test code. Just program your Arduino board and see LED will blink. Click on the upload button as shown in figure 13 below.

Figure 12 Upload the code to Arduino board.
Once your code is uploaded you will see the message in the green area at the bottom "Done uploading". Now, check your board it will look like the figure 13 below. Please remember this is not realtime simulation.


Figure 13 LED blinking 

Thank you for reading this post. Just try it and you would love to do programing.



If you learned something interesting please contribute to the future posts. I would appreciate your contribution to opensource free information.




All the text and graphics contained on this page belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission. 

© Copyright 2018 IbrahimLabs. All rights reserved.









Getting started with Arduino coding. (A beginner’s quick guide)

Welcome to my first Arduino coding guide. This would take you to kickstart with Arduino boards. I would go through following things real...