Sie sind auf Seite 1von 27

PREPARED BY

OOI YOONG KHANG

Copyright © USM IEEE R&D


Updated 8th January 2017
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

Contents

1.0 Basic Circuit Theory ..................................................................................................... 1


1.1 Identify the Node ....................................................................................................... 1
2.0 Introduction to Electronic Components ....................................................................... 3
2.1 Arduino ...................................................................................................................... 5
2.2 Breadboard ................................................................................................................ 5
2.3 Resistor ...................................................................................................................... 7
3.0 Projects .......................................................................................................................... 8
3.1 Insert Library ............................................................................................................ 8
3.2 Uploading a Program ................................................................................................ 9
3.3 Torch Light .............................................................................................................. 11
3.4 Blinking LED ........................................................................................................... 12
3.5 Intelligent Switch ..................................................................................................... 13
3.6 Toggle Switch ........................................................................................................... 14
3.7 Mood Lightning ....................................................................................................... 15
3.8 Music Player ............................................................................................................ 16
3.9 Karaoke.................................................................................................................... 17
3.10 Proximity Detector ................................................................................................ 18
3.11 Capacitive Sensor .................................................................................................. 19
3.12 Electrical Piano ...................................................................................................... 20
3.13 LCD ........................................................................................................................ 21
3.14 Timer ...................................................................................................................... 22
4.0 Solution for “Try This” ............................................................................................... 23

Copyright © USM IEEE R&D


Updated 8th January 2017
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

1.0 Basic Circuit Theory


Before we start with Arduino, there are a few basic circuit theory you have to understand.

1.1 Identify the Node


Node is defined as any point on a circuit where two or more circuit elements meet.

Example 1:
A R1 B R2 C

1k 1k

5V
R3
1k

0
Figure 1.1.1: Schematic 1

Based on Figure 1.1.1, there are total of 4 nodes. They are node A, node B, node C and GND.

Example 2:

A R1 B R2 C

1k 1k

5V
C1 1uF L1 10uH

0
Figure 1.1.2: Schematic 2

Based on Figure 1.1.2, there are total of 4 nodes. They are node A, node B, node C and GND.
It is noticed that a point is counted as a node regardless what kind of components connected to
the point.
Copyright © USM IEEE R&D
Updated 8th January 2017 1
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

TRY THIS!
Find the number of nodes of the following circuits:

(i)
R1 R2

1k 1k

5V

R3 R4

1k 1k
R5

3.3V 1k

0
Figure 1.1.3: Schematic 3

Answer: ____________________

(ii)
R1 R2

1k 1k

V1
5V R3
1k
R4

1k

V2
5V R5
1k
R6

1k

0
Figure 1.1.4: Schematic 4

Answer: ____________________

Copyright © USM IEEE R&D


Updated 8th January 2017 2
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

2.0 Introduction to Electronic Components


Electronic Components Quantity Description
Arduino is a kind of microcontroller that can
be used to perform a specific function based
Arduino
on instruction given. A programming which is
1 in C++ language is used to write an instruction
to the board.

A platform to connect components to form a


circuit. There is no soldering required to
Breadboard
connect the components.
1

LED LED stands for Light Emitting Diode in which


it will lights up when current flows in the
correct direction.
Red × 2
Yellow × 2
Green × 2 Longer leg
White × x

Shorter leg

Jumper A kind of wire that can be inserted into the


breadboard without soldering.

65

Copyright © USM IEEE R&D


Updated 8th January 2017 3
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

Resistor Restricts the amount of current flows through

100Ω × 10 it.
150Ω × 10
1kΩ × 10
10kΩ × 10
100kΩ × 10
1MΩ × 10

LCD LCD stands for Liquid Crystal Display which


used to display alphanumeric characters based
in digital input signal.
1

IR LED It is similar to LED but the light is not visible.


Infra is like heat, not visible to the naked eye.
You can check infra through your camera on
1 your phone and a red light will be seen.

IR Phototransistor A transistor which current depends on the


amount of IR light.

Speaker Produces sound in response to an electrical


audio signal input.

Copyright © USM IEEE R&D


Updated 8th January 2017 4
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

2.1 Arduino

Figure 2.1.1: Structure of Arduino

2.2 Breadboard

Figure 2.2.1: Internal Structure of Breadboard

Copyright © USM IEEE R&D


Updated 8th January 2017 5
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

TRY THIS!

1. Identify the voltage of each of the following based on Figure 2.2.2.

Figure 2.2.2: Schematic Diagram 5

A: _________________________

B: _________________________

C: _________________________

D: _________________________

E: _________________________

Copyright © USM IEEE R&D


Updated 8th January 2017 6
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

2.3 Resistor

Figure 2.3.1: Resistor Reading Corresponding to Colour

Copyright © USM IEEE R&D


Updated 8th January 2017 7
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.0 Projects
3.1 Insert Library
1. Open the CapacitiveSensor.rar file and click “Extract To” as shown in Figure 3.1.1.

Figure 3.1.1: WinRAR

2. Select the location of your libraries folder in Arduino folder installed. The location will
be in C:\Program Files(x86)\Arduino\libraries. Press “OK” after the folder is selected.

Figure 3.1.2: Location of Libraries Folder in Arduino

Copyright © USM IEEE R&D


Updated 8th January 2017 8
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.2 Uploading a Program


1. There are two things have to take note you send the program to the board.
(i) Ensure the board type is selected correctly in the software.
(ii) Ensure the USB port connect to Arduino is selected correctly in the software.

Click “Tools” on Menu bar and check for the “Board” and “Port” are selected correctly.

Figure 3.2.1: Board and Port Selection

Copyright © USM IEEE R&D


Updated 8th January 2017 9
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

2. Inside the program, there are 2 functions must be exists:


(i) void setup() – used to declare digital pin as INPUT/OUTPUT
(ii) void loop() – used to run program repeatedly

Figure 3.2.2: setup() and loop() Function

3. Do take note that the character/alphabet used in the programming is case sensitive. For
example, setup() and Setup() are two different things. If your program is written with void
Setup() or void Loop(), an error will be occurred when you compile your program.

Copyright © USM IEEE R&D


Updated 8th January 2017 10
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.3 Torch Light


1. Build the circuit according to the schematic shown below.

Figure 3.3.1: Torch Light Schematic Diagram

2. Press on tact switch and observe what happen to the LED.

Copyright © USM IEEE R&D


Updated 8th January 2017 11
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.4 Blinking LED


1. Build the circuit according to the schematic shown below.

Figure 3.4.1: Blinking LED Schematic Diagram

2. Write the program as shown below and upload into Arduino board.

Assign variable “pinLED” to be pin number 8

Assign variable “pinLED” as OUTPUT PORT

digitalWrite (pin8, HIGH) command pin 8 to output 5V

digitalWrite (pin8, LOW) command pin 8 to output 0V

delay (1000) means program stay here for 1000


milliseconds doing nothing

Copyright © USM IEEE R&D


Updated 8th January 2017 12
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.5 Intelligent Switch


1. Build the circuit according to the schematic shown below.

Figure 3.5.1: Intelligent Switch Schematic Diagram

2. Write the program as shown below and upload into Arduino board.

Assign variable “pinSwitch” as INPUT PORT

digitalRead (pinSwitch) command to take in the input


DIGITALLY from pin5
then it stores the data to variable “switchStatus”

This statement will be executed if switchStatus is


‘HIGH’

This statement will be executed if switchStatus is ‘LOW’

Copyright © USM IEEE R&D


Updated 8th January 2017 13
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.6 Toggle Switch

TRY THIS!

1. Set pin 5 as INPUT for tact switch and pin 8 as OUTPUT for LED.
2. Write a program that when user press the tact switch and release hand, the LED will light
ON. When user press again the tact switch and release hand, the LED will light OFF.

Figure 3.6.1: Toggle Schematic Diagram


HINT: Set a variable as a Boolean to indicate LED ON/OFF status.

Copyright © USM IEEE R&D


Updated 8th January 2017 14
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.7 Mood Lightning


1. Build the circuit according to the schematic shown below.

Figure 3.7.1: Mood Lightning Schematic Diagram

2. Write the program as shown below and upload into Arduino board.

Copyright © USM IEEE R&D


Updated 8th January 2017 15
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.8 Music Player


1. Build the circuit according to the schematic shown below.

Figure 3.8.1: Music Player Schematic Diagram

2. Write the program as shown below and upload into Arduino board.

tone (pin, frequency, duration);

Off speaker

Copyright © USM IEEE R&D


Updated 8th January 2017 16
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.9 Karaoke

TRY THIS!

1. Set pin 8, pin 9 and pin 10 as OUTPUT for LEDs and set pin 11 as OUTPUT for speaker.
2. Write a program to play a music and blink the LEDs together.

Figure 3.9.1: Karaoke Schematic Diagram

Copyright © USM IEEE R&D


Updated 8th January 2017 17
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.10 Proximity Detector


1. Build the circuit according to the schematic shown below.

Figure 3.10.1: Proximity Detector Schematic Diagram

2. Write the program as shown below and upload into Arduino board.

Serial.begin (baud rate) means activate “serial


communication” and baud rate is “communication speed”

analogRead (pin “A1”) command to take in the


ANALOG input from pin A1
then it stores the data to variable “analogvalue”

Serial.println (something) means display the “something”


on the serial monitor then the cursor move to next line.
Serial.print (something) means display “something” on
serial monitor and the cursor stay on the same line

Copyright © USM IEEE R&D


Updated 8th January 2017 18
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.11 Capacitive Sensor


1. Ensure there is “CapacitiveSensor” library inside your Arduino libraries folder.
2. Build the circuit according to the schematic shown below.

Figure 3.11.1: Capacitive Sensor Schematic Diagram

3. Write the program as shown below and upload into Arduino board.

Include external library

Copyright © USM IEEE R&D


Updated 8th January 2017 19
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.12 Electrical Piano

TRY THIS!

1. Set pin 2 as OUTPUT source and pin 4 and pin 6 as INPUT source. Set pin 11 as OUTPUT
for speaker.
2. Write a program to play a sound when touch each wire.

Figure 3.12.1: Electrical Piano Schematic Diagram

Copyright © USM IEEE R&D


Updated 8th January 2017 20
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

3.13 LCD
1. Build the circuit according to the schematic shown below.

Figure 3.13.1: LCD Schematic Diagram

Table 3.12.1: The function of pins in LCD


Pin Name Function
1 Vss Ground
2 Vcc +3.3 to +5 V
3 Vo Contrast. GND (high contrast) to Vcc (low
contrast)
4 RS Register Select.
0: Command
1: Data
5 R/W Read/Write.
0: Write
1: Read
6 E Clock, Falling edge triggered
7 DB0 Bit 0 (not used in 4-bit operation)
8 DB1 Bit 1 (not used in 4-bit operation)
9 DB2 Bit 2 (not used in 4-bit operation)
10 DB3 Bit 3 (not used in 4-bit operation)
11 DB4 Bit 4
12 DB5 Bit 5
13 DB6 Bit 6
14 DB7 Bit 7
15 LED+ LCD light (+ve)
16 LED- LCD light (-ve)
Copyright © USM IEEE R&D
Updated 8th January 2017 21
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

2. Write the program as shown below and upload into Arduino board.

INITIALIZE the LCD with 16 columns, 2 rows

Bring the cursor to column0 and row0

Bring the cursor to column0 and row1

Clear the display

3.14 Timer

TRY THIS!

1. By using LCD, display a timer that count from 30 seconds to 0 and keep repeat count
from 30 seconds again.

Figure 3.14.1: LCD Schematic Diagram


HINT: Use for loop to count the time.

Copyright © USM IEEE R&D


Updated 8th January 2017 22
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

4.0 Solution for “Try This”


Section 1.1
(i) 4
(ii) 6

Section 2.2
A: 5 V
B: No Voltage
C: 3.3 V
D: No Voltage
E: 0 V

Section 3.6

Copyright © USM IEEE R&D


Updated 8th January 2017 23
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

Section 3.9

Copyright © USM IEEE R&D


Updated 8th January 2017 24
ARDUINO MODULE (BEGINEER) OOI YOONG KHANG

Section 3.12

Section 3.14

Copyright © USM IEEE R&D


Updated 8th January 2017 25