Beginner’s Guide to Arduino

Yash Mohan
7 min readJun 27, 2018

Arduino is a very helpful tool for our electronic projects. Not only ECE students but IT students also can learn it as it also has a coding part apart from circuit part. During Aparoksha an event named Topbot was organized in which we had to make a bluetooth controlled car using Arduino UNO R3 board.

Then I came to know about Arduino for the first time. So, I thought of writing an article to spread more awareness about Arduino in our college.

Arduino UNO R3

What is Arduino?

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

Arduino is a microcontroller on a circuit board which makes it easy to receive inputs and drive outputs.

Inputs

Some examples of inputs would be a temperature sensor, a motion sensor, a distance sensor, a switch and so forth.

Outputs

Some examples of outputs would be a light, a screen, a motor and so forth.

Thus, Arduino can be programmed to read and control electrical components connected to it.

Obtaining an Arduino Board

You can buy Arduino board from Flipkart or Amazon.

Often boards are bundled up with starter kits. Kits include a wide variety of inputs, outputs, resistors, wires and breadboards.

Arduinos come in different flavours. Most people starting off go for the UNO board. Most enthusiasts use sites like Adafruit and Element14.

If you are just getting a single Arduino board or starter kit be sure you have a USB A to B cable. Most, if not all, starter kits come with the USB A to B cable. The reason you need the cable is to program the device so it is best to double check when ordering.

Programming Arduino

For the example I am showing you will only need the Arduino UNO R3 board itself and the required USB cable to transfer the program from your computer to the board.

Arduino UNO R3

On the board left of the Arduino logo there is an LED, short for Light Emitting Diode, a small light, with the letter L next to it.

We are going to switch it on and off and then look in to making it blink on and off for 2 seconds at a time.

When you first plug your USB cable in to your Arduino and your computer, you may notice that this LED is blinking. It is the default program stored on the chip. We are going to override this.

The USB cable powers the device. Arduinos can run standalone by using a power supply in the bottom left of the board. Once you are done programming and don’t require it to be constantly connected to your laptop you can opt to power it separately. This is entirely dependent on the use case and circumstances you want to use the device in.

Download Arduino Software

You will need to download the Arduino Software package for your operating system from the Arduino download page.

When you’ve downloaded and opened the application you should see something like this:

Arduino Software

This is where you type the code you want to compile and send to the Arduino board.

The Initial Setup

We need to setup the environment to Tools menu and select Board.

Tools Menu < Board

Then select the type of Arduino you want to program, in our case it is the Arduino Uno.

Arduino Uno

The Code

The code you write for your Arduino are known as sketches. They are written in C++.

Every sketch needs two void type functions, setup() and loop().

The setup() method is run once at the just after the Arduino is powered up and the loop() method is run continuously afterwards. The setup() is where you want to do any initialisation steps, and in loop() you want to run the code you want to run over and over again.

So, your basic sketch or program should look like this:

void setup()

{

}

void loop()

{

}

Now we have the basic skeleton in place we can now do the Hello, World program of microcontrollers, a blinking an LED.

Headers and Pins

Arduino UNO R3

If you notice on the top edge of the board there’s two black rectangles with several squares in. These are called headers. Headers make it easy to connect components to the the Arduino. Where they connect to the board is called pins. Knowing what pin something is connected to is essential for programming an Arduino.

The pin numbers are listed next to the headers on the board in white.

The onboard LED we want to control is on pin 13.

In our code above the setup() method let us create a variable called ledPin. In C++ we need to state why type our variable is before hand, in this case it is an integer, so it is of type int.

So,

int ledPin = 13;

void setup()

{

}

void loop()

{

}

In the setup() method we want to set the ledPin to the output mode. We do this by calling a special function called pinMode() which takes two variables, the first the pin number, and second, whether it’s an input or output pin. Since we’re dealing with an output we need to set it to a constant called OUTPUT. If you were working with a sensor or input it would be INPUT.

So,

int ledPin = 13;

void setup()

{

pinMode(ledPin, OUTPUT);

}

void loop()

{

}

In our loop we are going to first switch off the LED to make sure our program is being transferred to the chip and overriding the default.

We do this by calling another special method called digitalWrite(). This also takes two values, the pin number and the level, HIGH or the on state or LOW the off state.

So,

int ledPin = 13;

void setup()

{

pinMode(ledPin, OUTPUT);

}

void loop()

{

digitalWrite(ledPin, LOW);

}

Next we want to compile and upload it to the Arduino.

Compiling the Code

To compile code to your Arduino before plugging it in to the computer go to the Tools menu, then Serial Port and take note of what appears there.

Here is what mine looks like before plugging in the Arduino UNO:

Plug your Arduino UNO board in to the USB cable and into your computer. Now go back to the Tools > Serial Port menu and you should see at least 1 new option.

They tty and cu are two ways that computers can talk over a serial port. Both seem to work with the Arduino software.

Once you have selected your serial or COM port you can then press the button with the arrow pointing to the right.

Arduino Software with button highlighted

Once that happens you should see the TX and RX LEDs below the L LED flash. This is the communication going on between the computer and the Arduino. The L may flicker too. Once this dance is complete your program should be running. And your LED should be off.

Now let us try and switch it on using the HIGH constant.

So,

int ledPin = 13;

void setup()

{

pinMode(ledPin, OUTPUT);

}

void loop()

{

digitalWrite(ledPin, HIGH);

}

Press Upload again and you should see your LED is now on!

Let us make this a little more interesting now. We are going to use another method called delay() which takes an integer of a time interval in milliseconds.

So after where we switch the LED on let us add delay(2000) which is two seconds, then digitalWrite(ledPin, LOW) to switch it off and delay(2000) again.

So,

int ledPin = 13;

void setup()

{

pinMode(ledPin, OUTPUT);

}

void loop()

{

digitalWrite(ledPin, HIGH);

delay(2000);

digitalWrite(ledPin, LOW);

delay(2000);

}

Press Upload and you should see the output.

What next?

The Arduino platform is an incredibly easy and versatile platform to get started with. It is an open-source hardware, meaning that people can collaborate to improve, remix and build on.

It is responsible for some of the most popular devices that are driving the next Industrial Revolution, the 3D printer.

I conclude by saying more and more students should work on Arduino projects in our college.

I found a website which has many Arduino projects-https://www.makerspaces.com/simple-arduino-projects-beginners/.

--

--