Getting started with Arduino

So, you have finally decided that you want to make something with electronics, but are unable to find a good starting point? Don’t worry as you have come to the right place. In this blog, you will learn how to light up and then blink an LED along with .

To get started, we must first familiarize ourselves with the parts required

  • LED bulb
Image result for 5mm LED bulb image
5 mm LED
  • Arduino
Arduino Uno
  • A USB cable(specifically for Arduino)
Image result for arduino usb cable
USB to Arduino

Wait, I thought that we will be blinking an LED? What is that green circuit board for? That my friend is an Arduino Uno. It is a neat little piece of tech called a microcontroller. It was made by some very smart people to make electronics easy and provides a very powerful and flexible platform to convert your ideas to reality(to know more click here). So without any further delay, let’s get started!

Step 1: Getting the parts

If you already have all the required components, then you can skip this step, otherwise, read along.

The LED comes in a variety of colors, so feel free to make your choice, just remember to buy 5 millimetre LEDs as they will work best with the project. They can be brought from any website which sells electronic components, even Amazon(Some other websites are listed in the end). The 2 legs of the LED are of unequal length and make sure you keep it that way. DO NOT trim them to equal length, your job will be much easier.

The Arduino is a little more complicated, it comes in 3 varieties-

  • Arduino(official)
  • Genuino
  • clones

While all 3 of them work equally fine and will serve our purpose, they do have some important differences. The Arduino and Genuino boards are made by the official creators of Arduino and I recommend buying at least a few of them to show your appreciation. Arduino for the US and Genuino for everywhere else. The clone boards, on the other hand, are made by a variety of people and are much cheaper than the official boards. If you need to purchase many Boards, then I recommend buying the clone boards instead as they serve the same purpose at a lesser price and sometimes even give additional features.

Image result for arduino uno
Arduino Uno(official)
OpenHacks | Open Source Hardware | Productos | Genuino Uno Rev3
Genuino UNO
Arduino UNO R3 Clone + USB Cable - (CH340 USB Driver, SMD Model ...
Clone with additional features

The USB cable comes with the official boards however they may or may not come with the clones. They can be brought separately as well.

Step 2: Setting up the IDE

Remember when I said that the Arduino provided a platform, well I meant that it gives you the hardware(Circuit board), Software(programming environment) and the ecosystem(discussion forums). In this step, we will be setting up the free to use Arduino IDE(Integrated development environment) which is where you will be writing your code for the Arduino to execute. Sounds exciting? let’s get into it!

Related image
A screenshot of the IDE

To install the IDE, go to the downloads at the official Arduino website and find the version appropriate for your current computer(If you use a Raspberry Pi, then your method will be slightly different). You can even skip this step entirely by using the web editor but I don’t recommend this because of the features offered by the full software.

If you use Windows then you must open the installer and tick all the components. Enter the installation location(By default its in your programs) and finish the process. To know more, click here.

The Arduino Installer

If you use a mac, then click here or if you use Linux, then click here. If you are having any trouble, go to the troubleshooting page on the Arduino website. You can also describe your problem to me down in the comments and I will try my best to respond and fix your problem.

That’s it! you have the Arduino IDE installed and you are ready to go to the next step.

Step 3: Connecting Everything

In this step, we will connect the Arduino, LED and the IDE so that the whole project works as soon as we upload the code. Please complete this and the following steps carefully and do not skip any important information, otherwise both the current and your future projects may not work(Its super-easy, believe me).

Start by taking the LED and identifying its longer and shorter legs. Remember, the LED is polarized, meaning that it only works when connected in a particular way. The longer leg is the +ve leg(called anode) and the shorter leg is the -ve leg(called cathode). Take the longer leg and insert it into the hole which has been numbered 13 and take the shorter leg and insert it into the hole adjacent to it labeled as GND. It should look like this-

The longer leg is connected to pin 13 and shorter to GND

What does all this mean? Where are the negative and positive terminals like a battery? how? These might be some of the questions you are asking, but don’t worry, lets find out step by step. The GND pin is what is short for Ground pin and it is always connected to the negative terminal of your battery/power supply(Yes, you can power it via batteries, more on that later). Pin 13, as you might have guessed will act as the positive terminal of the LED but only initially. When we are going to blink the LED, we are going to constantly change its state to control the state of our LED(on, off, everything in between). In this circuit, if we were to draw the current flow, it would look like this-

Now, its time for the fun part, connecting the Arduino to the IDE. take the USB cable and plug its regular side into your computer and the other side into the Arduino. Once that is done, your computer will detect the newly connected device and start setting it up(installing drivers, updating existing drivers, collecting debugg data, you know what I mean). After this is done you can open the Arduino IDE and boom, you are ready to complete the next step.

Step 4: The Environment

Whoah! The moment you were waiting for is finally here, we can finally start writing some code and get our hands dirty!

After you open your IDE, you might see something like this-

Image result for arduino ide

Lets quickly go over the layout and features of the IDE so that you don’t face any difficulties while programming. First, the 5 buttons-

  • The first button with the ✔ is for verifying and compiling your programs. You will be using this often(really often). This basically converts your code into something which can be uploaded and executed by the Arduino board. Its keyboard shortcut is Ctrl+r.
  • The second button with the right-arrow is for uploading your program to the board. It basically transfers the compiled code into your Arduino via the USB cable to execute. It only works if your sketch has been verified and compiled and is error-free. Its shortcut is Ctrl+u.
  • The third square shaped button is to create a new sketch and it opens a new window with the new sketch. Its keyboard shortcut is Ctrl+n.
  • The fourth and fifth buttons are for opening and saving your sketches respectively. clicking on the down arrow will result in the file manager opening and prompting you to select a sketch to open. clicking on the down arrow will result in your current sketch getting saved. Keyboard shortcuts are Ctrl+o and Ctrl+s.

The 2 sets of curly braces you see are where your main code actually goes. The first one which reads void setup() is where your setup/init code goes that is only executed once. The next block is titled void loop() and does exactly what it says, that is to execute the code inside it again and again, till the end of time, or until power is supplied to the Arduino. All your code will be in either of these blocks. There are some conditions when it would go out of these such as global declarations but let’s not burden ourselves with that now.

There are still some minor things left to set up(They are very easy, trust me) but we will do them in the next step.

Step 5: Coding and uploading

In this step, we will be writing and understanding the code which controls our LED.

We need to start by telling the IDE that we are going to be using it program an Arduino Uno. You need to do is click on tools(on the menu-bar) and under it go to boards. Select the appropriate board you are going to use(Arduino Uno). Make sure you select Arduino Uno otherwise it will not work for this project. This does not matter if you are using a Genuino, clone or Arduino. The other options are also different Arduino boards but discussion of them is beyond the scope of this blog. If you wish to know more, however, click here.

The next step is to select the correct COM port on which the Arduino is connected. WAIT! Don’t leave yet, it takes less than a minute. Just go to tools but this time select port and click the COM port which appears. If there are multiple. just disconnect your board and see which one disappears, that is the correct one.

I know what you are thinking, when are we going to actually write some code? That moment, my aspiring maker, is finally here. Let’s get started with the initialization/setup code. place your cursor inside void setup(){} and write pinMode(13, OUTPUT); Make sure your capitalization is right and the semicolon is present. It should look something like this-

The code has been highlighted and coloured. If it has not, then double check your case and semicolon. Depending on your IDE version, the color scheme may slightly differ. But what does this piece of code mean? It basically tells the Arduino that it must send current out of pin 13. This is from where we will send power to the LED. pin 13 has been set to OUTPUT mode.

The next step is to tell the Arduino to turn the pin on i.e. to set it to HIGH. This is how it is done-

For now, all you must know is that this tells the Arduino to set the pin on, if we would have written LOW instead of high, it would be equivalent to switching the LED off. Your code should look something like this-

And that’s it, just click upload and see your LED turn on.

Final Step: Mixing and blinking

Okay, so you have successfully switched the LED on(and hopefully off) but how do we blink it? That’s easy, just add digitalWrite(13, LOW); after digitalWrite(13, HIGH); and your code should work right? The LED first turns on, then turns off and the whole process repeats. That is it.

HOLD ON! This does not work. After uploading, you probably saw that the LED stays off and refuses to turn on. Some of you who are eagle-eyed might have even realized that the LED does turn on but is extremely dim. Then why did I say this would work you ask? It was to demonstrate a very important concept. The Arduino might look small(especially the UNO) but it packs more than a punch for most of your projects. What is happening is that the Arduino is executing this piece of code millions of times per second which is creating an illusion of the LED becoming really dim. To fix this problem, all you need to do is add a delay(500); after both the Low and High lines and your code should look like this-

The delay function does exactly what you think it does, It tells the Arduino to stop doing whatever it is doing for the specified time. The number 500 is not random as well. It means 500 milliseconds or exactly 0.5 seconds. The delay function takes its value in milliseconds and does not accept decimal values(like 0.3, 0.5, 4.66 etc.). To get smaller delays, there are other methods, the discussion of which are beyond the scope of this blog. You can upload this code and then mess with the delays a bit to get various effects. Maybe try making it blink faster, or slower, or make the on and off durations unequal? You can do a lot of customization.

Whew! that was a lot, and hopefully, you read through, tried and more importantly UNDERSTOOD everything which I have told you. If you have, then you have successfully made your first project(Hello World) with Arduino and are ready to reach greater heights. If you haven’t then don’t worry, even I took some time as a beginner and you will get through it, eventually. Just don’t give up and remember that the only thing that can limit you is your imagination and the only thing limits your imagination is you!

Additional Resources(Give them a read too)

These are some other websites that will give you more information on arduino and maybe even inspire you to create something-

  1. Official Arduino website
  2. Arduino programming reference
  3. Arduino boards and the right one for you
  4. projects
  5. Instructables and Make

Purchase Links

Here are some online places that sell electronic components and a quick google search will yield many more-

  1. Amazon
  2. Robomart
  3. Rhydolabz
  4. Robokits India


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s