You are on page 1of 14

FACULTY OF ELECTRICAL

ENGINEERINGTECHNOLOGY
UNIVERSITI MALAYSIAPERLIS

EDJ12002
ELECTRICAL ENGINEERINGSKILLS

LAB MODULE1

INTRODUCTIONTO
ARDUINO

CO6: ARDUINO PROGRAMMING


Lecturer:
Ts. Mohd Nazri B Abu Bakar
EDJ12002: ELECTRICAL ENGINEERING SKILL ARDUINO
PROGRAMMING : MODULE 1

1. INTRODUCTION TO ARDUINO

1.1 OBJECTIVES

1. To introduce the Arduino IDE.


2. To understand the Arduino installation and setup.
3. To apply basic of programming, the structure of programming and howto start anArduino program.

1.2 EQUIPMENT / COMPONENTS

1.2.1 Arduino Maker Uno

Arduino is an open-source electronics platform based on easy-to-use hardware andsoftware. Arduino boards
are able to read inputs - light on a sensor, a finger onabutton, or a Twitter message and turn it into an output -
activating a motor, turningonan LED, publishing something online. You can tell your board what to do by
sendinga set of instructions to the microcontroller on the board. To do so you use the Arduinoprogramming
language (based on Wiring), and the Arduino Software (IDE), basedonProcessing. This Arduino Maker UNO
is an Arduino UNO compatible board designedand developed specially for students to learn coding and
microcontroller canbeprogrammed via Arduino IDE and compatible with all the example code and libraries
for Arduino UNO.

Features:

● SMD ATmega328P microcontroller (the same microcontroller on Arduino UNO) with Optiboot (UNO)
Bootloader.
● USB Programming facilitated by the CH340.
● Input voltage: USB 5V, from computer, power bank or standard USBadapter. ● 500mA
(maximum) 3.3V voltage regulator.
● 0-5V outputs with 3.3V compatible inputs.
● 14 Digital I/O Pins (6 PWM outputs).
● 6 Analog Inputs.
● ISP 6-pin Header.
● 32k Flash Memory.
● 16MHz Clock Speed.
● R3 Shield Compatible.
● LED array for 5V, 3.3V, TX, RX and all digital pins.
● On board programmable push button (pin 2, need to configure as INPUT_PULLUP).

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


1
EDJ12002: ELECTRICAL ENGINEERING SKILL ARDUINO
PROGRAMMING : MODULE 1
● On board piezo buzzer (pin 8).
A Piezo buzzer is connec
● Utilize USB Micro-B socket.
B PIEZO BUZZER SLIDE SWITCH Slide
Board Layout: buzzer (labeled A). Tousepiezo buzzer, slide
use pinother purpose, slide the switch off.

C VOLTAGE REGULATOR 3.3V Voltage r


and connected to pin 3.3V (labeled I).

D LED INDICATOR FOR USB-SERIAL In


process or debug purposeMonitor)

E USB MICRO B CONNECTOR Main supp


debug purposeMonitor) too.

F USB-SERIAL IC CONVERTER (CH340G


program and debug purpose(Serial Monitor)

G RESET BUTTON
Button to restart Maker UNO program.

LABEL FUNCTION
H PROGRAMMABLE BUTTON This button is connected I ARDUINO
to pin 2 andUNO
GND.R3
ToSTANDARD FEMA
use it, user needtoconfigure it as INPUT_PULLUP. pin follows Arduino UNO R3 standard. Theo
Vin.
MAIN MICROCONTROLLER (ATMEGA328P) (Serial
J
Maker Uno is ATmega328P, same as Arduino

(Serial
K SERIES OF MOSFET
These series of MOSFET is a ‘secret’ why you can control LEDor makeit

8for

UnoR3.

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


2
EDJ12002: ELECTRICAL ENGINEERING SKILL
ARDUINO PROGRAMMING : MODULE 1
as indicator for input, even for pull-up input.

L SERIES OF LED FOR DIGITAL I/OEvery digital IO is equipped with LED,


where you can control it or makeitas indicator for input.

M ARDUINO UNO STANDARD ISP PIN HEADERThese are 2x3 header


pins, standard for loading programviaprogrammer. Some uses it for SPI
communication too.

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


3

AVR

1.2.2 Arduino IDE Software

The Arduino IDE is an open-source software, which is used to write and upload codeto the Arduino boards.
It supports the programming languages C and C++. ArduinoIDE is an open source software that allows you
to download and use it for free.

Task 1 : Setting Up Hardware and Software

1. Log on to https://www.arduino.cc/en/main/software.
2. Choose your OS to proceed.
3. Double click on the downloaded to proceed. You are encouraged to make a monetary contribution to
help them to continue to fund their development. Anyway, you are free to click “JUST DOWNLOAD”.
EDJ12002: ELECTRICAL ENGINEERING SKILL ARDUINO
PROGRAMMING : MODULE 1

4. Once installation is completed, the Arduino’s icon will appear. Double click the icon to launch the
Arduino IDE.

The Integrated Development Environment of Arduino (IDE) is displayed by the IDEcontrol menu (see the
image below).
Toolbar Button - The icons displayed on the toolbar are New, Open, Save, Upload, and Verify. It
is shown below:

5. Connect your Maker UNO to your PC


6. Select the right com port. Tools >Ports >COM ?

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


4
EDJ12002: ELECTRICAL ENGINEERING SKILL ARDUINO
PROGRAMMING : MODULE 1

7. Now, you have successfully setup Maker UNO and will start making somethinginthe next
lesson.

2.0 INTERNAL DIGITAL I/O


The digital inputs and outputs (digital I/O) on the Arduino are what allowwe toconnect the Arduino sensors,
actuators, and other ICs. Learning how to use themwill allow we to use the Arduino to do some really useful
things, such as reading switchinputs, lighting indicators, and controlling relay outputs

2.1 Digital Output

Digital output means when we are taking HIGH/1/+5V or LOW/0/GNDfromtheArduino.

TASK 2: Turn On An LED

This is a very simple practice sketch that you will use to become familiar with the basic concepts of
Arduino.

1. Connect your Maker UNO with your PC with a USB cable. 2. Launch Arduino IDE.
3. From the application menu choose File > New file. 4. Write the program below and
save as the file named Task_2

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


5
EDJ12002: ELECTRICAL ENGINEERING SKILL ARDUINO
PROGRAMMING : MODULE 1

5. Click compile , wait for a few seconds until you see “Done Compiling” appear at the bottom of the
sketch.
6. Then click upload . Wait for a few seconds and you will see “Done uploading”appear at the
bottom of the sketch.
7. Check your result.

Exercise M1_1

Write a program to turn on on-board LED 2 to 13.

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


6
EDJ12002: ELECTRICAL ENGINEERING SKILL ARDUINO
PROGRAMMING : MODULE 1
TASK 3: Blind LED

1. Modify your previous codes into this and save as Task_3.


2. Click compile , wait for a few seconds until you see “Done Compiling” appear at the bottom of the sketch.
3. Then click upload . Wait for a few seconds and you will see “Done uploading”appear at the bottom of the
sketch.
4. Check your result.
5. Change the delay value to 1000 then upload it to your board again. 6. Observe the result and compare with the
previous program. What is the different? Explain.

Exercise M1_2

a) Blink LED 2, LED 3, LED 4, LED 5, LED 6 and LED 7 ON and OFF together with 1s delay.
b) Blink LED 2, LED 3, LED 4, LED 5, LED 6 and LED 7 in sequence with 1s delay.
c) Blink LED 2 to LED 13 in sequence then blink together ON and OFF 3 times with 1s delay.

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


7
EDJ12002: ELECTRICAL ENGINEERING SKILL ARDUINO
PROGRAMMING : MODULE 1
2.2 Digital Input

Digital input means when we are supplying HIGH/1/+5V or LOW/0/GNDtotheArduino board.

TASK 4: On Board Push Button Switch

In this project, we want to control an LED using the on-board push button switch.Touse the on-board push
button switch, we need to set it as “internal pullup input”. Example: pinMode(2, INPUT_PULLUP). The
on-board LED at Pin 2 will act as aninput indicator. It will turn o- if the on-board switch is pressed. The
on-board switchis internally connected to Pin 2. Meaning it is occupied and cannot be connectedtoany
other external components anymore if you would like to use it.

1. Open a new sketch then write these codes into the sketch and save as the file named Task_4.
2. Compile and upload the program.
3. Check your result.

Exercise M1_3

By using on-board switch, write a code. When the switch is pressed for the 1st time, LED 4 is turn ON.
When the switch is pressed for the 2nd time, LED4 is turn OFFand LED 5 is turn ON. When the switch is
pressed for the 3rd time, LED5 is turnOFF.

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


8
EDJ12002: ELECTRICAL ENGINEERING SKILL ARDUINO
PROGRAMMING : MODULE 1

2.3 Piezo Buzzer

The on-board piezo buzzer is connected to Pin 8. The tone() function works withtwoarguments, but can take
up to three arguments. Let’s address the three required items first:
tone( pin number, frequency, duration);

1. pin: The pin that connected with a piezo buzzer


2. frequency: the frequency of the tone in hertz
3. duration: the duration of the tone in miliseconds (whether it is 1 beat, 2 beats or etc.)

There is always a delay after tone. The delay has to drag 30% longer than the toneduration to ensure the
tone is completed.

TASK 5:
1. Open a new sketch, write these codes into the sketch then upload to your board.

2. Check your result.

Exercise M1_4

Using the on-board push button switch SW1 and compose the fist line of the “HappyBirthday To You”
song by using information below. If the SW1 is pressed, the on- board buzzer is on for three time with
1s delay.

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


9
EDJ12002: ELECTRICAL ENGINEERING SKILL
ARDUINO PROGRAMMING : MODULE 1

Exercise M1_1: Turn ON LED


Programming writing Demonstration with Q&A[2 Marks]
[2 Marks]

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


10
EDJ12002: ELECTRICAL ENGINEERING SKILL
ARDUINO PROGRAMMING : MODULE 1

Exercise M 1_2a: Blind LED


Programming writing Demonstration with Q&A[2 Marks]
[2 Marks]

Instructor Approval:

Exercise M 1_2b: Blind LED


Programming writing Demonstration with Q&A2 Marks]
[3 Marks]

Instructor Approval:

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


11
EDJ12002: ELECTRICAL ENGINEERING SKILL
ARDUINO PROGRAMMING : MODULE 1

Exercise M 1_2c: Blind LED


Programming writing Demonstration with Q&A[2 Marks]
[3 Marks]

Instructor Approval:

Exercise M 1_3: Digital Input


Programming writing Demonstration with Q&A[2 Marks]
[3 Marks]

Instructor Approval:

© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022


12
EDJ12002: ELECTRICAL ENGINEERING SKILL
ARDUINO PROGRAMMING : MODULE 1

Exercise M 1_4: Piezo Buzzer


Programming writing Demonstration with Q&A[2 Marks]
[5 Marks]

Instructor Approval:
© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022
13
EDJ12002: ELECTRICAL ENGINEERING SKILL
ARDUINO PROGRAMMING : MODULE 1

Rubric:
Content 5 4
NAME STUDENT
programming Student has Student has Student
made correct equipment /
writing made correct
componentconnections needed guidancemake correct
equipment
without /
guidanceper component equipment/
standarddiagram
performance connections component
as
a program.
with less guidance circuit at
connections
per standard effort
standard
and circuit
excell diagrams
ent
Satisfactory
diagrams and in writing
good performancewritingperformance
a
program. a program.

Demonstration with Demonstrates Demonstrates


Effectively identify
Q&A commitment
goals and commitment
works
efficiently tothe achieving
achieving
task. meet all at all.
carries out assigned
performing
task effectively^
© Copyright Faculty of Electrical Engineering Technology, UniMAP. 2022
14

You might also like