You are on page 1of 15

Getting Started with Arduino Lab 2

Introduction to Arduino
Learn about Arduino and the Arduino UNO
and how you can integrate this board into
your makerspace and coding program. Make
interactive makerspace projects while

learning to code and problem solve.

The key features are:


 Arduino boards are able to read analog or digital input signals from different sensors
and turn it into an output such as activating a motor, turning LED on/off, connect to
the cloud and many other actions.

 You can control your board functions by sending a set of instructions to the
microcontroller on the board via Arduino IDE (referred to as uploading software).

 Unlike most previous programmable circuit boards, Arduino does not need an extra
piece of hardware (called a programmer) in order to load a new code onto the board.
You can simply use a USB cable.

 Additionally, the Arduino IDE uses a simplified version of C++, making it easier to
learn to program.

 Finally, Arduino provides a standard form factor that breaks the functions of the
micro-controller into a more accessible package.

1
Getting Started with Arduino Lab 2

What Is Arduino?
Arduino is an open source programmable circuit board that can be integrated into a wide variety of
makerspace projects both simple and complex. This board contains a microcontroller which is able
to be programmed to sense and control objects in the physical world. By responding to sensors and
inputs, the Arduino is able to interact with a large array of outputs such as LEDs, motors and
displays. Because of it’s flexibility and low cost, Arduino has become a very popular choice for
makers and makerspaces looking to create interactive hardware projects.
History
Arduino was introduced back in 2005 in Italy by Massimo Banzi as a way for nonengineers to have
access to a low cost, simple tool for creating hardware projects. Since the board is open-source, it is
released under a Creative Commons license which allows anyone to produce their own board. If
you search the web, you will find there are hundreds of Arduino compatible clones and variations
available but the only official boards have Arduino in it’s name.
In the next section, we’re going to discuss a few of the Arduino boards available and how they
differ from each other.

Types of Arduino Boards


Arduino is a great platform for prototyping projects and inventions but can be confusing when
having to choose the right board. If you’re brand new to this, you might have always thought that
there was just one “Arduino” board and that’s it. In reality, there are many variations of the official
Arduino boards and then there are hundreds more from competitors who offer clones. But don’t
worry, we’re going to show you which one to start with later on in this tutorial.

Below are a few examples of the different types of Arduino boards out there. The boards with the
name Arduino on them are the official boards but there are also a lot of really great clones on the
market as well. One of the best reasons to buy a clone is the fact they are generally less expensive
than their official counterpart. Adafruit and Sparkfun for example, sell variations of the Arduino
boards which cost less but still have the same quality of the originals. One word of caution, be
careful when buying boards from companies you don’t know.

2
Getting Started with Arduino Lab 2

Image credit – Sparkfun.com


Another factor to consider when choosing a board is the type of project you are looking to do. For
example, if you want to create a wearable electronic project, you might want to consider the
LilyPad board from Sparkfun. The LilyPad is designed to be easily sewn into e-textiles and
wearable projects. If your project has a small form factor, you might want to use the Arduino Pro
Mini which has a very small footprint compared to other boards. Check out Sparkfun’s Arduino
Comparison Guide for a breakdown and comparison of the top boards out there.
Next, we’re going to focus on our favorite Arduino board which we recommend beginners start
with.
Here is a list of different Arduino boards available.
Arduino boards based on ATMEGA328 microcontroller
Board Name Operating Clock Digital Analog PWM UART Programming
Volt Speed i/o Inputs Interface
Arduino Uno 5V 16MHz 14 6 6 1 USB via
R3 ATMega16U2
Arduino Uno 5V 16MHz 14 6 6 1 USB via
R3 SMD ATMega16U2
Red Board 5V 16MHz 14 6 6 1 USB via FTDI

Arduino Pro 3.3V 8 MHz 14 6 6 1 FTDICompatible


3.3v/8 MHz Header

Arduino Pro 5V 16MHz 14 6 6 1 FTDICompatible


5V/16MHz Header

Arduino mini 5V 16MHz 14 8 6 1 FTDICompatible


05 Header

Arduino Pro 3.3V 8MHz 14 8 6 1 FTDICompatible


mini Header
3.3v/8mhz
3
Getting Started with Arduino Lab 2
Arduino Pro 5V 16MHz 14 8 6 1 FTDICompatible
mini Header
5v/16mhz
Arduino 5V 16MHz 14 6 6 1 FTDICompatible
Ethernet Header

Arduino Fio 3.3V 8MHz 14 8 6 1 FTDICompatible


Header

LilyPad Arduino 3.3V 8MHz 14 6 6 1 FTDICompatible


328 main board Header

LilyPad Arduino 3.3V 8MHz 9 4 5 0 FTDICompatible


simply board Header

Arduino boards based on ATMEGA2560 microcontroller


Board Name Operating Clock Digital i/o Analog PWM UART Programming
Volt Speed Inputs Interface

Arduino 5V 16MHz 54 16 14 4 USB via


Mega 2560 ATMega16U2
R3

Mega Pro 3.3V 8MHz 54 16 14 4 FTDICompatible


3.3V Header

Mega Pro 5V 16MHz 54 16 14 4 FTDICompatible


5V Header

Mega Pro Mini 3.3V 8MHz 54 16 14 4 FTDICompatible


Header
3.3V

Arduino boards based on AT91SAM3X8E microcontroller


Board Name Operating Clock Digital i/o Analog PWM UART Programming
Volt Speed Inputs Interface

Arduino 3.3V 84MHz 54 12 12 4 USB native


Due

Arduino Uno
One of the most popular Arduino boards out there is the Arduino Uno. While it was not actually
the first board to be released, it remains to be the most actively used in the market.

4
Getting Started with Arduino Lab 2

Board Breakdown
Here are the components that make up an Arduino board and what each of their functions are.
1. Reset Button – This will restart any code that is loaded to the Arduino board
2. AREF – Stands for “Analog Reference” and is used to set an external reference voltage
3. Ground Pin – There are a few ground pins on the Arduino and they all work the same
4. Digital Input/Output – Pins 0-13 can be used for digital input or output
5. PWM – The pins marked with the (~) symbol can simulate analog output
6. USB Connection – Used for powering up your Arduino and uploading sketches
7. TX/RX – Transmit and receive data indication LEDs
8. ATmega Microcontroller – This is the brains and is where the programs are stored
9. Power LED Indicator – This LED lights up anytime the board is plugged in a power source
10. Voltage Regulator – This controls the amount of voltage going into the Arduino board
11. DC Power Barrel Jack – This is used for powering your Arduino with a power supply
12. 3.3V Pin – This pin supplies 3.3 volts of power to your projects
13. 5V Pin – This pin supplies 5 volts of power to your projects
14. Ground Pins – There are a few ground pins on the Arduino and they all work the same

15. Analog Pins – These pins can read the signal from an analog sensor and convert it to digital.

Arduino Power Supply


5
Getting Started with Arduino Lab 2
The Arduino Uno needs a power source in order for it to operate and can be powered in a variety
of ways. You can do what most people do and connect the board directly to your computer via a
USB cable. If you want your project to be mobile, consider using a 9V battery pack to give it
juice. The last method would be to use a 9V AC power supply. You can also attach your battery
positive pin to Vin and negative to ground but the range should be no more than 9V.

Here is a visual of what a completed Arduino circuit looks like when connected to a breadboard.

How to Program Arduino


Once the circuit has been created on the breadboard, you’ll need to upload the program (known as
a sketch) to the Arduino. The sketch is a set of instructions that tells the board what functions it
needs to perform. An Arduino board can only hold and perform one sketch at a time. The
software used to create Arduino sketches is called the IDE which stands for Integrated
Development Environment. The software is free to download and can be found at
https://www.arduino.cc/en/Main/Software
Steps to follow
1. Create project
To create a new project, select File --> New.
6
Getting Started with Arduino Lab 2

To open an existing project example, select File -> Example -> Basics -> Blink.

Here, we are selecting just one of the examples with the name Blink. It turns the LED on and off
with some time delay. You can select any other example from the list.
7
Getting Started with Arduino Lab 2

2. Select your Arduino board


To avoid any error while uploading your program to the board, you must select the correct Arduino
board name, which matches with the board connected to your computer.
Go to Tools -> Board and select your board.

Here, we have selected Arduino Uno board according to our tutorial, but you must select the name
matching the board that you are using.

3. Select serial port


Select the serial device of the Arduino board. Go to Tools -> Serial Port menu. This is likely to be
COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out,
you can disconnect your Arduino board and re-open the menu, the entry that disappears should be
of the Arduino board. Reconnect the board and select that serial port.

8
Getting Started with Arduino Lab 2

4. Upload the program to your board


Before explaining how we can upload our program to the board, we must demonstrate the function
of each symbol appearing in the Arduino IDE toolbar.

A- Used to check if there is any compilation error.


B- Used to upload a program to the Arduino board.

9
Getting Started with Arduino Lab 2
C- Shortcut used to create a new sketch.
D- Used to directly open one of the example sketch.
E- Used to save your sketch.
F- Serial monitor used to receive serial data from the board and send the serial data to the board.

Now, simply click the "Upload" button in the environment. Wait a few seconds; you will see the
RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done uploading"
will appear in the status bar.

Note: If you have an Arduino Mini, NG, or other board, you need to press the reset button
physically on the board, immediately before clicking the upload button on the Arduino Software.
Arduino Shields
If you want to add a very specific functionality to your Arduino, you will need to use a shield.
Arduino shields plug into the top of the Arduino board and can add capabilities such as WiFi,
Bluetooth, GPS and much more. There are literally hundreds of shields to choose from and here
are a few examples.
 WiFi Shield
 LCD Shield
 GPS Logger Shield
 MP3 Music Maker Shield
 Ethernet Shield
 Motor/Stepper/Servo Shield

Arduino Sensors
If you want your Arduino to sense the world around it, you will need to add a sensor. There are
a wide range of sensors to choose from and they each have a specific purpose. Below you will
find some of the commonly used sensors in projects.
 Distance Ranging Sensor
 PIR Motion Sensor
 Light Sensor
 Degree of Flex Sensor
 Pressure Sensor
 Proximity Sensor
 Sound Detecting Sensor
 RGB and Gesture Sensor
 Humidity and Temperature Sensor

10
Getting Started with Arduino Lab 2
Examples of Arduino Sensors

Arduino Projects
You may be wondering what an Arduino board can do besides blink an LED. Below are some example
projects which help to showcase how truly amazing this board is and the capabilities of it.
1. Autonomous car
2. Smart Drone
3. Led cube
4. Smart GPS Tracker Using Arduino
5. Flash Twenty LEDs Using Arduino
6. Alarm Clock Radio Using Arduino
7. Make An Arduino-Based Wireless Frequency Meter
8. Temperature Based Fan Speed Control And Monitoring Using Arduino
9. Arduino Based RF Controlled Robot
10. Automated plant watering system
11. Home Automation Using an Android Device

11
Getting Started with Arduino Lab 2

Example Program 1
This example blink the 13 pin led
int ledpin=13;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(ledpin, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(ledpin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledpin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Example 2
This example blink the 13 pin led with button
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

12
Getting Started with Arduino Lab 2

Lab Tasks
1. Connect 4 leds with any pins on Arduino and make them glow simultaneously.
2. Make a car central locking indication led. (Hint: On time will be 500ms and off time will
be 5000ms)
3. With the help of two leds make police siren system.
4. Write a Programing for Fading the LED by using PWM pins.
a. Set three ranges for LED brightness which will change after every second.
b. The LED should fade in and fade out completely using loop.

Home Assignment
1. Learn an SOS pattern and make a project with single LED to display SOS pattern for
emergency purpose.
int redLED = 13; // Setting Value of redLED as 13
int dit = 150; // Setting Value of dit as 150
int dah = 500; // settiing Value of dah as 500
int longWait = 1000; // setting value of longW as 1000
void setup() {
pinMode (redLED,OUTPUT); // defining RedLED as OUTPUT
}
void loop() {
digitalWrite (redLED,HIGH);
delay(dit);
digitalWrite (redLED,LOW);
delay(dit);
digitalWrite (redLED,HIGH);
delay(dit);
digitalWrite (redLED,LOW);
delay(dit);
digitalWrite (redLED,HIGH);
delay(dit);
digitalWrite (redLED,LOW);
delay(dah);
digitalWrite (redLED,HIGH);
delay(dah);
digitalWrite (redLED,LOW);
delay(dah);
digitalWrite (redLED,HIGH);
delay(dah);
digitalWrite (redLED,LOW);
delay(dah);
digitalWrite (redLED,HIGH);
delay(dah);
digitalWrite (redLED,LOW);
delay(dah);

13
Getting Started with Arduino Lab 2
2. Connect the buzzer and with the help of PWM change its sound.

const int buzzer = 9; //buzzer to arduino pin 9

void setup(){

pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output

void loop(){

tone(buzzer, 1000); // Send 1KHz sound signal...


delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec

14
Getting Started with Arduino Lab 2

Observations:
In Microcontrollers this lab we learned about and their

applications in Various domains. Microcontrollers used for

automation are sent applications where there is need to control

Digital/Analogue a multiple inputs for desired output. In this lab

we learned the basics of Arduino UNO board and also learned

about Arduino Mega and Nano, along few other variations of

boards that are available in with readily market. In the basics of

Arduino.

In the basics of Arduino in UNO we discovered that it has 14 pins

for digital input/output from which 6 can be used to simulate

PWM analogue signal. The UNO board has 6 analogue

input/output pins and an ATMEG A controller which is the brain

of the board. The Arduino Uno has only 1 UART port but multiple

serial communications can be performed through programming.

15

You might also like