Quick-Start Arduino Guide

Quick-Start Arduino Guide

Before we dig in, have a look at the below mind-map we created for you in order to save your time planning about ‘where to start’ and ‘What Next?’ type things. You can follow the mind map even if you have never touched the electronics before. You can click on ‘Present this Coggle‘ button to view Mind-map in full screen.

This post assumes that you know basic electronics and thus content is presented accordingly.

An Arduino is a prototyping board used for various electrical projects by Students, hobbyists, engineers, designers, and anyone interested in Programmable electronics. A Picture of the most popular Arduino model – Arduino Uno is shown below:

Image Credits: Arduino Store

Besides Arduino Uno, other flavors of Arduino boards include Arduino nano, Arduino pro mini, and Arduino Mega. They differ based on their size and specifications.

What are programmable electronics?

Just like ordinary computers perform tasks because of the instructions given to its processor, An Arduino is able to do things, take input, or provide an output based on the instructions we gave to its small-sized processor – known as micro-processor or micro-controller we talked about earlier.

Thats why Arduino falls under the category of programmable electronics.

Arduino in Pakistan microcontroller
Image Credits: Starting Electronics

Arduino Uno consists of a 16MHz ATMega Processor (shown above) with 32 KB of Flash memory and 2 KB of RAM which is enough to run small programs. Such small processors are used everywhere around us – where we need very low computation power capable of running 1 or 2 sets of instructions at a time.

What you can do with an Arduino?

Because of small size, low cost and ease of programming, Arduino is used by thousands of makers all around the world to build amazing projects. Young students and beginners also use it to learn basic programming and electronics.

Have a look at the blinking LED example done by programming the Arduino board below. We will refer to this image later in this post to understand how it works.

arduino blinking LED gif image
Source: Hack Club

The biggest benefit of Arduino is that it is interesting. A Change in program uploaded to Arduino causes a change in its output thus causing observers and learners to test their idea and get output in real-time.

Arduino Board Description:

Besides an ATMega Processor, Arduino consists of Input/Output pins known as Arduino I/O pins out of which 14 are Digital I/O pins having pin numbers like 1,2,3,4 and so on. There are also 6 Analog I/O pins or Analog inputs referred with pin numbers A0, A1,A2, A3, A4 and A5 used to work with analog components.

A USB Port is used to connect Arduino with a computer in order to upload programs to the Arduino board.

Understanding an Arduino Program:

Arduino I/O pins are used for its interaction with the real world. These pins can take data “in” from a sensor or can provide data “out” in the form of digital and analog signals. To make things clear, lets first understand the code responsible for LED blinking in the above image.

Most beginners feel uncomfortable about Arduino programming language while getting started. Arduino language is based on C. Anyone having know-how of basic programming in C, can easily start programming in Arduino.

Every Arduino program must have two functions a setup() function – which runs only once and a loop() function which runs forever. Think of functions as sub-programs responsible for handling small tasks in a large program.

void setup() {
  pinMode(13, OUTPUT); 
}

void loop() {
      digitalWrite(13, HIGH); 
      delay(1000);
      digitalWrite(13, LOW); 
      delay(1000); 
}

At lines 1-3, we have defined that pin number 13 on our Arduino board will act as an output pin. Remember from our image above, LED was physically connected to pin number 13. pinMode (p is small, M is Capital) is used to tell Arduino whether to use the specified pin as Output or Input.

void loop() {
      digitalWrite(13, HIGH); 
      delay(1000);
      digitalWrite(13, LOW); 
      delay(1000); 
}

At lines 5-10, we have defined our loop function. digitalWrite is used to provide low or high voltage to the specified pin. We told our Arduino to give high voltage on pin number 13. Then we added a delay of 1000 milliseconds. delay() tells Arduino to pause the running of program for specified number of milliseconds – in our case 1000 milliseconds that are equal to 1 second. These two lines keep our LED on for one second.

digitalWrite(13, LOW); 
delay(1000);

At lines 8 and 9, we repeat digitalWrite() and delay() but this time we wrote LOW in digitalWrite instead of HIGH. So, this line will turn LED off and because of delay(), it will remain off for 1 second.

Writing lines 6-9 inside the loop() function causes LED to blink continuously.

Hopefully, you understand how Arduino works and what type of cool projects you can make with it. Let’s move on to set up an Arduino workspace on your computer.

Setting Up Arduino WorkSpace:

You bought an Arduino and looking to get started with it. Lets explore how you can setup your computer for writing and uploading programs to Arduino.

Installing Arduino IDE:

An IDE or Integrated Development Environment is a piece of software that allows us to write programs. Download and Install Arduino IDE from the Official Arduino Website for Windows, Mac or Linux. You can also use the Arduino web editor on official Arduino website to program Arduino directly without installing IDE.

arduino installation guide for windows
Source: MakeUseOf

Installation of IDE will also install the respective USB driver needed to recognize Arduino device when you connect it to computer.

Running Arduino IDE:

Now that the IDE is installed, we are all set to write and upload programs to Arduino board. Run the Application by Clicking on Desktop Shortcut named Arduino in Windows or type the command of ./arduino in Linux. You will see something like this:

Arduino IDE windows

For your ease, setup() and loop() functions are already there and you just have to write your own logic inside.

Starter Projects:

Arduino IDE came pre-packaged with some of the programs and you can upload them to Arduino with 1-click. The blinking LED program we understand above is also a part of built-in Arduino examples. To access this program just go to File > Examples > Basics > Blink. You should see the blink code will open up.

Arduino guide for basic projects

In order to upload code to Arduino , First select Arduino Model by selecting Tools > Board Menu. We are using Arduino Uno in this case.

Arduino Uno in Pakistan

Once you finish selecting board, choose the serial port on which Arduino is connected to your PC by selecting Tools > Port. On windows it’s like COM3 or COM4 or something like that. it corresponds to your computer’s USB port.

Arduino uno code for led

Finally click on Upload button (The Left arrow like) to Upload this example to Arduino as shown in image below.

arduino upload code

You can also access other examples and learn along the way by running example programs.

If you want to explore more, there are lot of buit-in Arduino code examples available within the IDE. By using jumper wires, breadboard, and other arduino compatible components e.g sensors and components like bluetooth module, a lot of innovative projects can be made. Also, the internet is full of fun, cool and useful arduino projects.

Arduino’s functionality can be extended by using add-on boards known as Arduino shields. An example is Arduino wifi shield that allows your arduino to connect to an available wifi network or to become a wifi hotspot.

Some Simple Arduino Projects:

Below are some of the fun and simple projects you can make with Arduino.

Temperature and Humidity sensor project:

This project aims to measure temperature and humidity in the surrounding using DHT11 temperature and humidty sensor. 

Things you need:

  • An Arduino Uno board
  • DHT11 sensor breakout
  • Breadboard
  • Jumper wires

Normally, there are two types of DHT11 sensors available. We are going to use the DHT11 breakout for this project. You can read the basic difference between these two types here.

Lets make hardware connections.

The rightmost pin of DHT sensor is the ground pin. Use a jumper wire to connect it to GND pin on Arduino. Central pin known as VCC pin should be connected to 5V pin on Arduino. At last, the signal pin of DHT should be connected to an Arduino digital pin. In our case, we are using pin number 2.

DHT sensor pinout wiring arduino

After making hardware connections, lets move on to our arduino software IDE.

Programming:

For our Arduino to read from DHT sensor, we first need to install the DHT arduino library. An arduino library is a packaged set of instructions that make programming easier. Normally, most of sensors came with their own library.

To install the library, go to Sketch > Include Library > Manage Libraries, search for DHT sensor library by Adafruit and install it.

installing arduino libraries

Similarly, also install Adafruit unified sensor library by Adafruit. This library is required by our DHT library to work properly.

After installing libraries, copy and paste the following code in Arduino IDE and click on upload.

//DHT11 with Arduino code by iotechy.com
#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 



// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600); 
  Serial.println("DHT test!");
 
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);

  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hi);
  Serial.println(" *F");
}

After the code uploaded successfully, open serial monitor from Tools > Serial Monitor and you will see temperature and humidity readings displayed there.

serial monitor arduino
Source: Random Nerd

How the Code works?

First of all, we start by importing DHT library by writing the following line of code.

#include "DHT.h"

Then we defined the pin number on which DHT sensor is connected. it is connected to digital pin number 2.

#define DHTPIN 2 // what digital pin we're connected to

Next, we defined the type of DHT sensor we are using. It’s DHT11.

#define DHTTYPE DHT11 // DHT 11

Then we created an object of DHT with the name dht and which takes two parameters – pin number and DHT sensor type.

DHT dht(DHTPIN, DHTTYPE);

In the setup() function, we issued the command to start serial communication at 9600 baud rate.

Serial.begin(9600);
Serial.println("DHT test!");

Initialize the DHT sensor by calling begin() function.

dht.begin();

In the loop() function, we first defined a delay of 2 seconds. As DHT is a slow sensor so its maximum sampling rate is 2 seconds.

delay(2000);

DHT library has built in readTemperature() and readHumidity() methods to take sensor readings in float type.

float h = dht.readHumidity();
float t = dht.readTemperature();

In order to read temperature in Fahrenheit, we just need to pass true as a parameter in readTemperature() function.

float f = dht.readTemperature(true);

We can also computer heat index in Fahrenheit and Celsius using computeHeatIndex() function.

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

At last, we displayed all the readings on Serial monitor.

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");

That’s all about reading temperature and humidity arduino project using DHT11 sensor.

Wrapping Up:

As you can see, making projects and learning electronics and programming is fun and easy with Arduino. Arduino is by far the best prototyping board available out there. We will come up with more Arduino guides and Projects in future.

Do you have any Arduino projects in mind? What Arduino model do you have? Share your thoughts in the comment box below.

Stay Tuned and also don’t forget to share the post with the people you love!

FAQs:

Is Arduino beginner Friendly?

Arduino is one of the low-cost prototyping board available out there. Anyone can start instantly with Arduino due to lots of learning material available on internet.

Which language Arduino uses?

Arduino language is based on basic C/C++. If you have a little bit know-how of basic programming in C, Arduino will be a fun for you. But Absolute beginners with no programming experience can also learn it fast.

Is Arduino difficult to learn?

Certainly not. Arduino is so easy that even a 5th grade kid can easily start building projects on it. However, for a person absolutely new to coding, it may take some to grasp programming concepts.

Arduino vs Raspberry Pi? Which one to use?

Arduino is most popular due to its simplicity and beginner-friendly nature. If you are just starting out, go for Arduino. Raspberry Pi is like a small computer which is used for complicated and high-end projects as it is more powerful than Arduino.

What are the uses of Arduino?

Arduino is used by makers, hobbyists and anyone interested in programmable electronics. it is also used by various schools in science projects and STEM based education.

This Post Has 2 Comments

  1. anxiety games

    At this time I am going away tto do my breakfast, once having mmy breakfast cming again to
    rread fuurther news.

    1. ioTechy.com

      Let me know your views in comments

Comments are closed.