Sie sind auf Seite 1von 8

FUNDAMENTALS of ARDUINO

A Guide to Arduino for Beginners


EXERCISE NO.1
FAMILIARIZATION OF ARDUINO: HARDWARE & SOFTWARE

_______________________________ _______________________________
Name Course & Year
_______________________________ _______________________________
Instructor Date

I. OBJECTIVES
1. To be able to identify the hardware parts of Arduino Uno
2. To be able to familiar with the Arduino programming environment
3. To be able to know the programming structure of Arduino and the basic commands

II. MATERIALS & DEVICES


- Arduino Uno w/ USB cable - Connectors
- LEDs - Breadboard
- Resistors - Power Supply
- Computer - Proteus (ISIS)

III. DISCUSSION
Arduino is an open source physical computing platform based on simple input / output
(I/O) board and a development environment that implements the Processing Language. Arduino
can be used to develop stand-alone interactive objects or can be connected to software on your
computer. The following are the advantages of Arduino:
1. Inexpensive
2. Cross-platform
3. Simple, clear programming environment
4. Open source and extensible software
5. Open source and extensible hardware
Below are the various types of Arduino board:

Arduino Uno Arduino Leonardo Arduino Diecimila

Arduino Nano Arduino Mega

HARDWARE: Arduino UNO

Arduino Uno is a microcontroller board based on ATmega328. It has 14 digital


input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic
resonator, a USB connection, a power jack, an ICSP header, an I2C bus, and a reset button. It

PREPARED BY: ENGR. JPKAQUILALA 1


contains everything needed to support the microcontroller. You can simply connect it to a
computer with a USB cable or power it with AC-DC adapter or battery to get started.

Arduino Uno Specifications


Microcontroller ATmega328
Operating Voltage 5V
Input Voltage (Recommended) 7V ~ 12V
Input Voltage (Limits) 6V ~ 20V
Digital I/O Pins 14 (digital pin 0 ~ pin 13)
PWM Outputs 6 (digital pin 3, 5, 6, 9, 10, 11)
Analog Inputs 6 (A0 ~ A5)
DC Current per I/O pin 40 Ma
DC Current for 3.3V per I/O Pins 50 mA
Flash Memory 32 KB
SRAM 2 KB
EEPROM 1 KB
Clock Speed 16 MHz

SOFTWARE: Arduino Software IDE

Arduino Integrated Development Environment (or Arduino Software IDE) contains a text
editor for writing code, a message area, a text console, a toolbar with buttons for common functions
and a series of menus. It connects to the Arduino hardware to upload programs and communicate
with them. Below is the screenshot of the environment of Arduino Software IDE.

Writing Sketches
Programs written using
Arduino Software IDE are called
sketches. These sketches are written in
the text editor and are saved with the
file extension .ino. The message area
gives feedback while saving and
exporting and also display errors. The
console displays text output by the
Arduino Software, including complete
error messages and other information.
The bottom righthand corner of the
window displays the configured board
and serial port. The toolbar buttons
allow you to verify and upload
programs, create, open, and save
sketches, and open the serial monitor.

Two required functions in writing Arduino program


void setup()
{
statements;
}
void loop()
{
statements;
}

PREPARED BY: ENGR. JPKAQUILALA 2


void setup(){ }
All the code between the two curly brackets will be run once when the Arduino program first run.
This function is used for initialization such as serial communication, digital I/O pins, and etc.

void loop() { }
This function is run after setup has finished. After it has run once it will be run again, and again,
until power is removed. This function is used for the operation of the Arduino.

Skeleton / Structure of Arduino Program


declaration of libraries used
declaration of variables

void setup()
{
statements;
}
void loop()
{
statements;
}
user-defined functions

Getting started with Arduino


1. Write a program using Arduino software IDE
- Double click the Arduino Sofware IDE to open the application

2. Set the right Arduino board used


- Click Tools > Board

PREPARED BY: ENGR. JPKAQUILALA 3


3. Verify / Compile the program

- Click “Verify” button in the Arduino software IDE environment:


- If the status area displays “Done compiling”, it means no error found in the program otherwise,
the program contains error.
4. Connect the Arduino board using USB cable
- The Arduino board automatically draw power from the USB connection to the computer. The
green power LED should go on.
5. Set the Arduino port connection in the Arduino software IDE environment
- Click Tools > Port
- Note: To determine the Arduino COM Port please see the device manager

6. Upload the code to Arduino board


- Click the “Upload” button in the Arduino software IDE environment:
- During uploading, the RX and TX leds on the board are flashing. If the upload is successful, the
message “Done uploading” will appear in the status area.

Common terms
“sketch” – a program you write to run on an Arduino board
“pin” – an input or output connected to input / output device
“digital” – values either HIGH or LOW
“analog” – for PWM output, value ranges from 0 up to 255

Basic Commands
1. pinMode()
- Configures the specified pin to behave either as an input or an output
Syntax: pinMode(pinNumber,mode)
where:
pinNumber – the number of digital pin
mode – INPUT, OUTPUT, or INPUT_PULLUP
Example: pinMode(13,OUTPUT);

2. digitalWrite()
- Write a HIGH or a LOW value to a digital pin
Syntax: digitalWrite(pinNumber, value)
where:
pinNumber – the number of digital pin
value – HIGH or LOW
Example: digitalWrite(13,HIGH);

PREPARED BY: ENGR. JPKAQUILALA 4


3. delay()
- Pauses the program for the amount of time (in milliseconds)
Syntax: delay(ms)
where:
ms = the number of milliseconds to pause (unsigned long)
Example: delay(1000);

IV. PROCEDURE
A. Blinking LED with Arduino Uno
1. Open the Arduino software IDE
2. Type the given program below to the text editor of the Arduino software IDE
/*
* Sample No. 1: Blinking LED
*/
void setup()
{
// digital pin 2 ~ 5 = used as output pins
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
}
void loop()
{
// LEDs 1 ~ 4 = ON
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
delay(1000); // pause (1000ms = 1 second)
// LEDs 1 ~ 4 = OFF
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
delay(1000); // pause (1000ms = 1 second)
}
3. Set the board in the Arduino software IDE – used Arduino Uno
4. Save the program – File Name: Exercise1Sample1LastName
5. Compile the program by clicking the “Verify” button
6. Connect the Arduino Uno to the computer using USB cable
7. Set the port in the Arduino software IDE (Make sure that the set port match COM Port number
seen in the device manager)
8. Upload the program by clicking the “Upload” button
9. Remove the USB cable to the computer
10. Connect the circuit shown below

11. Connect the USB cable to the computer and observe the output

PREPARED BY: ENGR. JPKAQUILALA 5


B. Simulation of Blinking LED w/ Arduino Uno using Proteus-ISIS
1. Open the Arduino software IDE
2. Copy the program on the above example
3. Set the board in the Arduino software IDE – used Arduino Uno
4. Save the program – File Name: Exercise1Sample2LastName
5. Compile the program by clicking the “Verify” button
6. In the search windows of the computer, type %temp% then, open the folder
7. Open the folder arduino_build and copy the hex file of the program then paste it to the folder
where the program is located
8. Open the Proteus – ISIS and draw the circuit below

9. Double click the Arduino Uno (window will appear) and load the hex file

10. Click the play button and observe the output

PREPARED BY: ENGR. JPKAQUILALA 6


V. EVALUATION / EXERCISE QUESTIONS
1. Identify the parts of the Arduino Uno based on the figure below.

2. Identify the parts of the Arduino software IDE based on the figure below.

1. ______________________ 7. ________________________

2. ______________________ 8. ________________________

3. ______________________ 9. ________________________

4. ______________________ 10. ________________________

5. ______________________ 11. ________________________

6. ______________________ 12. ________________________

PREPARED BY: ENGR. JPKAQUILALA 7


3. Running Lights
Create a program that would perform the following operations:
- Initialize the output pins used in the circuit
- LED output sequence:
1st: LED4 & 5 = ON, others are OFF
2nd: LED3 & 6 = ON, others are OFF
3rd: LED2 & 7 = ON, others are OFF
4th: LED1 & 8 = ON, others are OFF
5th: LED2 & 7 = ON, others are OFF
6th: LED3 & 6 = ON, others are OFF
- Use 1 second delay
Circuit:
- Simulate and implement your
design program
- Save your design program and
simulation
- File Name:
Exercise1RunningLightsLastName

4. Controlling 12-V Lamp using Arduino Uno with Relay


Create a program that would perform the following operations:
- Initialize the output pins used in the circuit
- Switch ON and OFF the relay
- Use 2 seconds delay

Circuit Block Diagram:

Arduino Switching
Relay 12-V Lamp
Uno Circuit

Design your own circuit and simulate your design program.

File Name: Exercise1ArduinoUnowRelayLastName

PREPARED BY: ENGR. JPKAQUILALA 8

Das könnte Ihnen auch gefallen