0% found this document useful (0 votes)
20 views78 pages

Basic Arduino Workbook Guide

The document is a workbook on Arduino programming, designed for beginners to understand and utilize Arduino technology. It covers the basics of Arduino, installation of the Arduino IDE, and provides step-by-step guides for various projects, including wiring diagrams and programming instructions. The authors, both Mechatronics Engineering lecturers, aim to make learning Arduino fun and accessible, with a focus on practical applications.

Uploaded by

amir
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views78 pages

Basic Arduino Workbook Guide

The document is a workbook on Arduino programming, designed for beginners to understand and utilize Arduino technology. It covers the basics of Arduino, installation of the Arduino IDE, and provides step-by-step guides for various projects, including wiring diagrams and programming instructions. The authors, both Mechatronics Engineering lecturers, aim to make learning Arduino fun and accessible, with a focus on practical applications.

Uploaded by

amir
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

POLITEK

KNIK KOTA KIINABALU


No 4, Jalan Politeknik, KKIP
K Barat
Kota Kinabalu Industriial Park,
88460, Kota Kinabalu, Sabah

Firrst published 20
020

Editor: Noor Azlyn Binti Ab Ghafar,, Raizizan Bin Raahim


Desig
gner: Shairul Bin
n Ludin

A right reserved.
All

N
No part of this publication
p mayy be reproduced d, stored in a rettrieval system or
o
T
Transmitted in any
a form by anyy means, electro onic, mechanicaal, photocopying g,
recording or otherwise,
o with
hout the prior pe
ermission of Copyright owner

ii
PREFACE
In the name of Allah, the Most Gracius and the Most Merciful
Please and blessings of Allah be upon His Messenger, Muhammad, and all his family and companions

Alhamdullillah, all praises to Allah for the blessing and guidance upon completing this book.

The contents of this book were tailored to the needs of technology-driven world today. Learning to program gives
you a much better understanding of this world as all ‘things’ nowadays can be programmed, autonomous and
intelligent. This book will uses Arduino as a microcontroller. Arduino board is a popular board for embedded
development. This book helps you to get started with Arduino Uno development. Several basic samples projects are
provided to accelerate your learning process. Most importantly it is shown by step by step procedure which make
learning Arduino is fun, simple and interesting.

This book have been written by Mrs. Noor Azlyn Binti Ab Ghafar and Mr. Raizizan Bin Rahim which both are
Mechatronics Engineering lecturers at Mechanical Engineering Department, Politeknik Kota Kinabalu. We are both
graduated from International Islamic University of Malaysia in Mechatronics Engineering.

Lastly we would like to take this oppurtunity to express our gratitude especially to our leader Mr Muhammad Izani
bin Sahak, Mr Julkifli Bin Awang Besar and Mr Philips Dharmaraj for inspiring, motivating and continuously
supporting us with ideas, knowledge and oppurtunities. Not to be forgotten, our lovely family members, colleagues,
and students. May this book will benefit us all and any feedback or improvement is highly welcome.

Perpustakaan Negara Malaysia Catalogue-in-Publication Data

BASIC ARDUINO WORKBOOK / Editor: Noor Azlyn Binti Ab Ghafar,


Raizizan Bin Rahim.
ISBN 978-967-2318-07-1
1. Arduino (Programmable controller).
2. Programmable controllers.
3. Government publications--Malaysia.
I. Noor Azlyn Ab Ghafar.
II. Raizizan Rahim.
006.22
ii
Basic Arduino Workbook
CONTENT

Preface ii
Content iii
Chapter 1 - Introduction
- What is Arduino? 2
- Type of Arduino 3
- Arduino board pinout 4

Chapter 2 – Getting Started


- Installing Arduino IDE 6
- Arduino IDE interfacing 8
- Connecting Arduino Board 9

Chapter 3 – Project 1 (Testing… Testing… )


- Component required 12
- Wiring diagram 13
- Programming 14

Chapter 4 – Basic Arduino Programming


- Basic structure 16
- Basic input output function 17
- Variable 18
- Data type 18

iii

Basic Arduino Workbook


- Operator 18
- Control structure 20
- Serial monitor 21
- Other syntax 21

Chapter 5 – Project 2 (Input and Output)


- Component required 23
- Wiring diagram 24
- Programming 25

Chapter 6 – Project 3 (Sensor)


- Component required 30
- Wiring diagram 32
- Programming 33

Chapter 7 – Project 4 (Advanced sensor)


- Component required 39
- Wiring diagram 40
- Programming 41

Chapter 8 – Project 5 (Mini project)


- Component required 52
- Wiring diagram 53
- Programming 54

References 70

iv

Basic Arduino Workbook


WHAT IS ARDUINO?

ARDUINO is an open source single board based microcontroller that is easy-to-use


hardware and software.

“Open source” term means that the code, schematic, design etc. can be taken freely
by anyone to do what they like it.

Inexpensive - affordable for students, makers, artists and hobbiest.

Compose of 2 major parts


- Arduino board as a hardware to build up your object or project. It is the microcontroller or a brain that will control and make all
the decision.

- Arduino Integrated Development (IDE) software to run on computer. It is a software used for writing the programming code
and then will be uploaded to the Arduino board.

Basic Arduino Workbook


TYPES OF ARDUINO

There are many types of Arduino board in the market you can choose. You can choose which Arduino board to be used depending on the
need of your own project. In addition, the price of each board is also different.

ARDUINO UNO
Most famous and complete board for user
Dimension: 2.7 inch x 2.1 inch
Digital input = 14 pin
Analog in = 6 pin
Pwm = 6 pin

ARDUINO LILYPAD ARDUINO MEGA


For wearable project as cloth. Has many input and output pin
Washable compare to UNO. For large project
Dimension: 2 inch diameter Dimension: 4 inch x 2.1 inch
Digital input = 14 pin Digital input = 54 pin
Analog in = 6 pin Analog in = 16 pin
Pwm = 6 pin Pwm = 14 pin

ARDUINO NANO ARDUINO MINI


Small but complete. Breadboard Smaller than NANO
friendly. For small project Dimension: 0.7 inch x 1.3 inch
Dimension: 0.73 inch x 1.7 inch Digital input = 14 pin
Digital input = 14 pin Analog in = 8 pin
Analog in = 8 pin Pwm = 6 pin
Pwm = 6 pin

Basic Arduino Workbook


ARDUINO UNO PINOUT
Main IC
1 USB Port (type B) 6
v - The brain of Arduino board
- Supply voltage to Arduino (5V) 1
- Use to upload programming Analog In pin
2
code from computer 7 - Reading voltage measurement for
Barrel jack analog sensor
2
- Supply voltage to Arduino Digital input output pin
3
- Do not supply more than 20V 8 - Can be either input or output
- Recommended 6V ~12V depending on your programming
Reset button code using Arduino IDE
3 - Digital input can only read one of
- Restart any code that is loaded 5 two values and digital output can
on the Arduino but not deleting only output one of two value
all code. 4 (LOW or HIGH)
9
- Six digital pins that have 3
LED Indicator
4 8 function (digital in/digital
- Should light up whenever you output/analog out) are labelled
plug Arduino into a power with “~pwm” sign (pin 3, 5, 6, 9,
source 7 6 10 and 11)
5
RX and TX LED Indicator 9 Power pin

- Should light up whenever - Consists of GND (ground), 5V out,


Arduino is receiving and 3.3V out, Vin (input voltage) and
transmitting data through serial reset
communication - Connect positif supply to Vin and
negative supply to GND will
power up Arduino
4

Basic Arduino Workbook


INSTALLING ARDUINO IDE
- Let’s install Arduino IDE to your computer. This is a software that is specially used to write, compile and upload programming code
to Arduino board.
- Open your internet browser (Google chrome, Firefox, Safari, Internet Explorer and etc.)
- Search Arduino website ([Link])
- Click SOFTWARE -> DOWNLOAD

Basic Arduino Workbook


- Scroll down and click Windows installer for window if you are using Windows
-

- The installer will be downloaded automatically. When finished, run the installer.
- After that, open your Arduino IDE by clicking the icon on your desktop.

Basic Arduino Workbook


ARDUINO IDE INTERFACING
- When you open your Arduino IDE, this will appear

New – Create new blank Open – Show a list of Save – Save the current
sketch saved code to open code
Verify – Check the
code for errors Serial Monitor – Display
serial data being sent and
received to computer
Upload – Upload
current code to the
Arduino board

Editor – Code editor


area. Write your code in
this area

Error console – Warning


Message – IDE
or error will displayed
reports success or
here
failure message here

Show selected board


type and COM port
8

Basic Arduino Workbook


CONNECTING ARDUINO BOARD

- Now let’s connect Arduino board to your computer.


- Connect USB cable to your Arduino board and then connect to your computer

- In your Arduino IDE, click Tools -> Board -> Arduino/Genuino Uno

Basic Arduino Workbook


- After that, click Tools -> Port -> select your com port. The COM port is different from one computer to other.

- You have to repeat these steps everytime you plug in your Arduino board to your computer. If you skip these steps, your code will
not successfully uploaded to your Arduino board.

10

Basic Arduino Workbook


In this chapter we will be testing the connection between our computer and Arduino board. This can be done by uploading simple code
that will turn on and off a LED.

COMPONENT REQUIRED
Arduino Uno USB cable Breadboard

- As a microcontroller for this project - To connect between computer and Arduino - Components will be connected
board. here in the breadboard.
- Bidirectional
Jumper wire (Male to male) LED (Light Emitting Diode) Resistor

- A conducting wire that establishes - A component which emits light when - A component that is used to
an electrical connection between current flows through it. reduce current flow
two points in a circuit - Longer leg is anode while shorter leg is - No polarity
cathode
12

Basic Arduino Workbook


Wiring Diagram
- Let’s connect all the component as circuit below. Make sure the polarity of of your LED is correct.

LED anode pin – Arduino Digital Pin 13

13

Basic Arduino Workbook


PROGRAMMING
- In Arduino IDE, click FILE -> Example -> [Link] -> Blink

- Programming code will appear in a new window as below.


14

Basic Arduino Workbook


- Then you can click upload button and wait for the the computer to finish uploading until u see “Done uploading” at the
bottom of your screen

- Observe your LED. Does it blinking?


15

Basic Arduino Workbook


BASIC STRUCTURE
- Software structure in Arduino IDE consists of two main function
o setup() function
o loop() function

- void setup() function is called when the code starts. It only run once. It is use to initialize the variables, pin modes, instruction to
start using library etc.

- void loop() will run code and loops consecutively, allowing program to change and response. It is use to actively control Arduino
board. This is where your important code like reading sensor, making decision and running output will be executed.

16

Basic Arduino Workbook


BASIC INPUT OUTPUT FUNCTION
1. pinMode ()
- Arduino pin need to be configurated as either Input/Output depending on your circuit.
- This is done in void setup() function
- It is case sensitive. You should type pinMode not pinmode
- Let’s say you connect a sensor signal pin to analog pin A0, your coding will be as below:

2. digitalWrite() / analogWrite()
- Use to write a HIGH or a LOW value to digital pin.
- If HIGH, voltage will be set to the corresponding pin to be outputed 5V and 0V for LOW.
- For example, if you want the LED to turn on, you need to set pin connected to LED to 5V (HIGH)
- Your code should be like below:

3. analogRead() / digitalRead()
- analogRead() is use to read sensor value for analog sensor. The value will read up to 1023 (5V)
- While for digitalRead() will read from digital sensor the digital value which is HIGH or LOW only

17

Basic Arduino Workbook


VARIABLE
- A space or storage in the Arduino memory use to store data.
- For example if your read value for sensor, the reading value must be store in a spesific space called variable.
- You can name your variable as you like but it is case sensitive.

DATA TYPE
- In order for you to be able to use variable, first you need to know what is type of data you want to store.
- In Arduino, there are 3 basic daya type used namely:
o char – for character or alphabet. Written in single quote for single character ‘A’ and double quote for string
“ABC”
o int – for integer number. Example 12, 4, 56782
o float/double – for number that has a decimal point. Example 2.345, 3.142, 345.3

OPERATOR
- Tell the compiler to perform specific mathematical or logical functions.

o Arithmetic operators - Normal mathematical operators


= Store value * Multiplication
+ Addition / Division
- Substraction % Remainder

18

Basic Arduino Workbook


- Comparison operators - Will only return true(1) or false(0) value
== Check value is equal or not.
!= Check value is equal or not.
< Check value less than
> Check value more than
<= Check value less than or equal to
>= Check value more than or equal to

- Boolean operators - Will only return true(1) or false(0) value


AND && Both left and right expression is true, then will return true value
OR || Any of the two expression is true, then will return true value
NOT ! Use to reverse the original state of its expression

The above expression means that, temperature read by sensor MUST be between 0 until 19 so that the output will be true (1).

The above expression means that, any of the push button (pushButton1 OR pushButton2) is pressed, the output will be true (1).

19

Basic Arduino Workbook


CONTROL STRUCTURE
- Important for decision making structure. There are 2 commonly used control structure.
o If …else – takes an expression in parenthesis and a statement or block of statements. If expression is true, then
the statement is executed. Otherwise it will execute else statement

The above if…else statement will work as follows. If temperature is more than 50˚C, fan will on. However is the temperature is not more than
50˚C(less than 50˚C) , the fan will be off

o For loop - executes statements a predetermined number of times. The control expression for the loop is
initialized, tested and manipulated entirely within the for loop parentheses.

The above for loop will start counting from 0 until 3. Means there will be 3 loops. Count++ indicates the increment by 1. Thus, the buzzer will
turn on for 0.5 second and then off for 0.5 second for 3 times.
20

Basic Arduino Workbook


SERIAL MONITOR
- Used for communication between the Arduino board and a computer.
- Normally serial monitor is used for us to know what is the value read from sensor.

- This is done by clicking the magnifing glass icon at the top right corner of the Arduino IDE
- The instruction for enable serial monitor is as below:

OTHER SYNTAX
- Comments are lines in the program that are used to inform yourself or others about the way the program works.
- Comments' only purpose is to help you understand (or remember), or to inform others about how your program
works.
- There are 2 types of comment
o Block comment – start from /* symbol until */ symbol. All inside these symbols are comments
o Single line comment – start from // symbol unill the end of a line is comment.

21

Basic Arduino Workbook


In this chapter, we will be using the same circuit as project 2. But, we add one more component known as push button. Push button is
commonly use in all electronic equipment. Push button is one of type of switch. What is switch? Switch is an electrical component that can
disconnect or connect the conducting path in an electrical circuit, interrupting the electric current or diverting it from one conductor to
another. There are many types of switch namely toggle switch, rocker switch, slide switch and many more.

COMPONENT REQUIRED
• As mention before, we will still using Arduino UNO, USB cable, Jumper wire, LED and resistor as project 1. But now we will add the
push button to our circuit.
Push Button

- Push button is a component that is designed to close or open an electric circuit when a button or knob is depressed, and to
return to a normal position when it is released.
- It has 4 legs. But actually only 2 legs is required when wiring. The other 2 legs are internally connected

23

Basic Arduino Workbook


WIRING DIAGRAM

Push button 1 leg – Arduino VCC pin


Push button 2 leg – Arduino digital pin 7

24

Basic Arduino Workbook


PROGRAMMING

25

Basic Arduino Workbook


- Rewrite the code above and try to understand based on what you have learn in chapter 4.
- You can check the value of push button by clicking the serial monitor. This is done by clicking the magnifing glass icon at the

top right corner of the Arduino IDE


- If you do not press the push button, your serial monitor will appear as below:

26

Basic Arduino Workbook


- On the other hand, if you press the push button, your serial monitor will appear as below:

27

Basic Arduino Workbook


- Your program should works as below:

Start

Read push button

Yes
If push button is LED on
pressed

No

LED off

End

- If you press the push button, the LED will be turned on. While if you do not press the push button, LED will be off.
- Observe your LED. Does it light up when you press the push button?

28

Basic Arduino Workbook


In this chapter, we will be using sensor as an input. What is sensor? Sensor is a device or component that will measure or detect events or
changes in its environment and send the information to other electronics. In human body, there are 5 basic sense which are touch,
hearing, sight, taste and smell. What are the organ (sensors) that is use to sense? They are skin, ears, eyes, tongue and nose respectively.

COMPONENT REQUIRED
• Please take note that we will still using Arduino UNO, USB cable, Jumper wire, LED and resistor as project 1. Now we will change
the push button to Ultrasonic sensor.

Ultrasonic Sensor HC-SR04

- Ultra sonic sensor is a sensor that is used to measure distance by emitting ultrasonic sound waves, and converts the
reflected sound into an electrical signal
- This sensor 2 main components which are TRIGGER and ECHO. Trigger will emit the sound wave and when there are
object in front of it, the sound wave will be refected back and received by Echo.

30

Basic Arduino Workbook


- The time taken starting from sound wave emit until the sound wave received back is then calculated to distance.

- Example of animals that uses this type of sound wave are bat and whale.

31

Basic Arduino Workbook


WIRING DIAGRAM

Ultrasonic Sensor Trig pin – Arduino Digital Pin 9


Ultrasonic Sensor Echo pin – Arduino Digital Pin 8
32

Basic Arduino Workbook


PROGRAMMING
- First, we will read the sensor reading using serial monitor. Retype the code below and upload it.

33

Basic Arduino Workbook


- After done uploading, open serial monitor. This is done by clicking the magnifing glass icon at the top right corner of the

Arduino IDE
- Make sure the baud rate is 9600 and observe the reading of your sensor. Place an object in front of the ultrasonic sensor
and move it toward and outward the sensor. The value will change accordingly.

34

Basic Arduino Workbook


- Next, we will use LED as an output. The code should be working as below

Start

Read distance

Yes
If distance < 50cm LED on

No

LED off

End

- Based on the flowchart above, if the Ultrasonic sensor sense an object located less than 50cm from the sensor, the LED
will be turn on. This indicate that the object is near to the sensor
- If the object is more than 50cm from the sensor (far from sensor), the LED will be turn off.
- The code is as below. Please observe what has been added to the previous code.

35

Basic Arduino Workbook


36

Basic Arduino Workbook


- Observe the output. Does your LED turn on when the object is near the Ultrasonic sensor and turn off when the object is
far from the Ultrasonic sensor.
- We already added declaration for LED which are connected to Arduino digital pin 13. Moreover, in void setup, we define
LedPin as an OUTPUT.

- As for the decision part, we added if .. else statement. If the distance is less than 50cm, LED will on. Other than that
(>50) LED is off.

37

Basic Arduino Workbook


In this chapter, we will be using more advanced sensor. Why advance? Because in order for us to use it, we need to download a library and
upload to our Arduino IDE. So , prepare your computer with internet connection.

COMPONENT REQUIRED
• We will using same circuit as previous project but we will change Ultrasonic sensor with DHT 11 sensor

DHT 11 Temperature Sensor

- The DHT11 a sensor that is use to measure temperature and [Link] is small, low cost and easy to use.
- It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data
pin.
- Its temperature range is from 0 to 50 degrees Celsius with +-2 degrees accuracy. Its humidity range is from 20 to 80 percent
with 5 percent accuracy.

39

Basic Arduino Workbook


WIRING DIAGRAM

Signal Out DHT11 – Arduino Digital Pin 6

40

Basic Arduino Workbook


PROGRAMMING
- Open your internet browser (Google chrome, Firefox, Safari, Internet Explorer and etc.)
- Type “DHT 11 Library”

- Click the [Link] website. [Link] is a website that compile all code, library, projects, and build software alongside 40
million developers. It is an open source website.

41

Basic Arduino Workbook


- Then click the Clone or Download button and click Downlod ZIP. The zip folder will be automatically
downloaded. Wait until it finished downloading. Normally all the downloaded item will be store in the Download file
- Next we need to install another library which is ‘Adafruit sensor’
42

Basic Arduino Workbook


- Using same step, search ‘Adafruit sensor library’ and download from [Link]

- Open Arduino IDE.


- Click Sketch -> Include Library -> Add .ZIP Library

43

Basic Arduino Workbook


- New window will appear. You have to select zip files that we already downloaded. You have to do this one by one.

- Next, click File -> Examples -> DHT sensor library ->DHTtester
44

Basic Arduino Workbook


- Note that all library you downloaded will have example code for your reference.
- Change #define DHTPIN 2 to #define DHTPIN 6. Why? Because in our circuit, we connect DHT signal out to Arduino Digital Pin 6
- In addition, you need to uncomment the #define DHTTYPE DHT11 and uncomment #define DHTTYPE DHT22. This is because we
are using DHT11 and not DHT22

45

Basic Arduino Workbook


- Upload the code by clicking upload button . Open serial monitor by clicking magnifing glass icon and observe the
reading. Wrap your palm around DHT11 and observe the value increasing.
46

Basic Arduino Workbook


- Next we will use LED as an output. The code should be working as below

Start

Read temperature

Yes
If temperature>30 50cm
LED on

No

LED off

End

47

Basic Arduino Workbook


- Based on the flowchart above, if temperature measured by DHT11 is bigger than 30 ◦C, LED will turn on indicating the
temperature is high. If temperature is low (less than 30 ◦C), LED will off.
- We have to modified our programming code as below:

- In order for us to be able to use LED, first we must declare the pin number of LED connected to Arduino Digital Pin 13.
- Next, in void setup, we must define LedPin as an output.
- Lastly at the last part of the code, we add if.. else statement

48

Basic Arduino Workbook


- Let’s try harder situation. As mentioned before DHT11 is capable of measuring temperature and humidity. Now we have 2
conditions.
- If temperature is bigger than 30 ◦C and humidity less than 60 %, LED will turned on
- Likewise, if temperature is less than 30 ◦C and humidity is more than 60%, LED will turn off.
- The LED will also be turn off if the first condition is not met. (temp >30 and humidity<60)
- Take note that both condition needed to be met. Consider example below:

Condition Output Reason


Temperature 31◦C LED turn on Temperature is bigger than 30 ◦C √
Humidity 58% Humidity less than 60 % √
Temperature 28◦C LED turn off Temperature is less than 30 ◦C √
Humidity 63% Humidity bigger than 60 % √
Temperature 28◦C LED turn off Temperature is less than 30 ◦C √
Humidity 58% Humidity bigger than 60 % X
Temperature 31◦C LED turn off Temperature is less than 30 ◦C X
Humidity 63% Humidity bigger than 60 % √
49

Basic Arduino Workbook


- The flowchart will be as below:
Start

Read temperature and humidity

Yes
If temperature >30 and
humidity <60 LED on

No

LED off

End

- Let’s modified our programming code


- We just need to modified the if.. else condition. Run your program. Open serial monitor and observe your LED.

50

Basic Arduino Workbook


In this chapter we will learn how to combine more than one output for one sensor. We will use DHT11 temperature sensor, OLED as a display
and DC motor as a fan. This project can be implemented in your own room. Temperature sensor will sense surrounding temperature and
display the value at OLED. So you do not need your serial monitor at your computer anymore. This means that this project will be running
without the computer connected to it. In addition if surrounding temperature is hot, fan will turn on. Conversely, if surrounding temperature is
cold, fan will be off. This project is save energy right?

COMPONENT REQUIRED
OLED

- We will be using 0.96 inch OLED SSD1306 with 128x68 pixel


- It is used as a display or monitor.
- Easy and interesting to use as you can customize the font size and you can display logo and icon

5V DC Motor

- There are many types of motor in the market. 3 basic type of motor that are commonly used are DC
motor, Servo Motor and Stepper Motor. But in this mini project, we will be using DC Motor
- This DC motor need to be supplied with 5v in order for it to turn on.
- If you wish to control the direction (clockwise or anti clockwise) and the speed, you need to use Motor
Driver Module. However for this mini project, we just want it to rotate any direction with only one
speed.

52

Basic Arduino Workbook


WIRING DIAGRAM

DC Motor – Arduino Digital Pin 11


OLED SCL Pin – Arduino Analog Pin A5
OLED SDA Pin – Arduino Analog Pin A4

53

Basic Arduino Workbook


PROGRAMMING
- First let’s us learn how to use OLED.
- Open your internet browser (Goggle chrome, Firefox, Safari, Internet Explorer and etc.)
- Type “Adafruit_SSD1306 library”
- Click [Link] website

54

Basic Arduino Workbook


- Then click the Clone or Download button and click Downlod ZIP. The zip folder will be automatically
downloaded.
- Wait until it finished downloading. Normally all the downloaded item will be store in the Download file

- In your internet browser, Type “Adafruit_GFX library”


55

Basic Arduino Workbook


- Click [Link] website

- Same as step before, click the Clone or Download button and click Downlod ZIP. The zip folder will be
automatically downloaded.
- Wait until it finished downloading. Normally all the downloaded item will be store in the Download file
- Open Arduino IDE
- Click Sketch -> Include Library -> Add .ZIP Library

56

Basic Arduino Workbook


- New window will appear. You have to select zip file that we already downloaded. Note that we already download 2 new zip
files. So you have to add both file.

57

Basic Arduino Workbook


- Next, click File -> Examples ->ADAFRUIT SSD1306 ->ssd1306_128x64_i2c

- Then, u can upload your code and observe what appear in your OLED

58

Basic Arduino Workbook


- If your OLED is showing nothing, you can change the code as below (Ox3C)

- Did you go through the code? Did you find it difficult and complicated? Don’t worry. For beginner, just retype the coding as
below
- Before that, open DHTTester programming code side by side of ssd1306_128x64_i2c programming code
- First, in DHTtester, uncomment #define DHTTYPE DHT11 and comment #define DHTTYPE DHT22. Moreover because we connect
DHT11 signal pin to Arduino Digital Pin 6, thus, we need to change to #define DHTPIN 6

59

Basic Arduino Workbook


- We will copy and paste or retype the coding to combine both program
- Refer to the picture below, the left side is programming code for OLED and right side is DHT11
- Copy and paste the yellow code from OLED to DHT11
- It should be paste BEFORE void setup area

60

Basic Arduino Workbook


- Next, in the void setup area in OLED program, copy the yellow programming code and paste at void setup in DHT11 program

61

Basic Arduino Workbook


- Lastly, type programming code below at the last part of your DHT11 program

- Upload the coding to your Arduino Board and observe the display at your OLED.

62

Basic Arduino Workbook


- Lastly, we will add programming code for fan. As mention before, if temperature is bigger than 30 ◦C, motor will turn on. When
the surrounding temperature is cold, less than 30 ◦C, motor will be off.
- Below is the full flowchart of our mini project.

Start

Read temperature

Display temperature value

Yes
If temperature >30 50cm Motor on

No

Motor off

End

- So we need to declare Arduino digital pin for motor, define pin for output and add if…else statement.
- Below is the full coding for this mini project

63

Basic Arduino Workbook


64

Basic Arduino Workbook


65

Basic Arduino Workbook


66

Basic Arduino Workbook


67

Basic Arduino Workbook


68

Basic Arduino Workbook


- We have finish basic Arduino programming now. But you can still learn many other sensor, actuator, motor and display through
internet. It is because Arduino is open source and you can easily learn and try new things without any charge.
- Don’t stop learning because learning is FUN

SEE YOU IN NEXT EDITION

69

Basic Arduino Workbook


References

• Arduino, S. A. (2015). Arduino. Arduino LLC.


• Badamasi, Y. A. (2014, September). The working principle of an Arduino. In 2014 11th international
conference on electronics, computer and computation (ICECCO) (pp. 1-4). IEEE.
• Monk, S. (2016). Programming Arduino: Getting Started with Sketches, (Tab). McGraw-Hill
Education TAB.
• McRoberts, M. (2011). Beginning Arduino. Apress.
• Evans, B. (2011). Beginning Arduino Programming (Vol. 6). New York, NY, USA:: Apress.
• [Link]
• [Link]
• Smith, A. G. (2011). Introduction to Arduino. Alan G. Smith.
• Louis, L. (2016). WORKING PRINCIPLE OF ARDUINO AND U SING IT. Int. J. Control. Autom.
Commun. Syst, 1, 21-29.

70

Basic Arduino Workbook


POLITEKNIK KOTA KINABALU
No 4, Jalan Politeknik, KKIP Barat
Kota Kinabalu Industrial Park,
88460, Kota Kinabalu, Sabah

You might also like