Professional Documents
Culture Documents
on
Introduction to Microcontroller
Hasan Alqaraghuli
pc_hssn@icloud.com
1
Outlines:
i. What is microcontroller (μC) and its application?
ii. Sensor and Actuator – interfaced to μC
iii. Installation of Arduino IDE and ArduBlock
iv. Introduction to Arduino – Example 1
v. Programming with ArduBlock
vi. Example 2: Two LEDs Blinking
vii. Example 3: Arrays of LEDs Blinking in Pattern
viii. Example 4: Push button and limit switch as inputs
ix. Example 5: Switches and activation for LEDs running
pattern
x. Example 6: Potentiometer as input – analog input
xi. Example 7: Relay control
xii. Example 8: Light sensor and relay to control 12V LEDs
xiii. Demo on Simulator – offline and Online solution
2
What is microcontrollers ?
4
List down 10 devices around you
that contain microcontrollers?
5
Applications
Automotive Energy
Simplest development
tools
Cost-effective
10
Sensor and Actuator – Interfaced to μC
Sensor A Actuator X
Physical Actuator Y
Sensor B Microcontroller
signals
. .
. .
Sensor Ni Actuator Zi
Solar panel will be rotated in such a way that the panel will get
‘maximum’ concentrated sunlight for optimum power generation.
13
Steps in using μC
14
Introduction to Arduino
15
Family of Arduino
16
17
Development tool
Integrated Development Environment (IDE) – coding,
compiling, debugging.
18
Development tool
Editor – hard coding to be done
19
Development tool
• We choose a lot simpler approach – graphical
programming
• The are many tools available online and most of them are
free
• ArduBlock
20
Development tool
21
Development tool
23
Step 3 : Installation directory Step 4 : Installation running
Step 6
After finishing the installation
procedure, Run the program.
Introduction of Arduino™ IDE
25
Setting-up configuration
26
ArduBlock Installation
• Download the ArduBlock from website:
https://sourceforge.net/projects/ardublock/files/ardublock-beta-
20140702.jar/download
• Create folder on desktop named as “tools”
Inside this folder, create another folder “ArduBlockTool”
Inside this folder, create another folder “tool”.
Finally copy the downloaded file into this directory.
“tools\ArduBlockTool\tool\”ArduBlock filename”.
• Copy the whole “tools” folder to this directory
“C:\Users\xxxxx\Documents\Arduino”
• Now open Arduino IDE and go to “Tools/ArduBlock”.
27
Now open Arduino IDE and go to “Tools/ArduBlock”.
28
Example 0: Turn ON one LED
Function
buttons Programming space
A few important functions in ArduBlock are:
i. Control button
Control
Loop - do
Delay function
Test
Comparing two digital values
LOW
HIGH
A few important functions in ArduBlock are:
v. Math Operators
Math Operators
map
Example 1: LED Blinking
- Writing code in ArduBlock
43
Example 2: Two LED Blinking
44
Example 2: Two LED Blinking
45
Example 3: Arrays of LEDs Blinking
with patterns.
- Four LEDs will be blinking in pattern.
- Connect four LEDs to pin 3 to pin 6 as
shown in the figure.
- Choose a blinking pattern and write
down the sequence to perform this
operation.
- Write the code in ArduBlock and
upload to Arduino block to check the
blinking pattern.
46
Example 3: Arrays of LEDs Blinking
with patterns.
47
Example 3: Arrays of LEDs Blinking
with patterns.
48
Example 4: Push button and limit switch
as input
- Push button and limit switch acts
as input to the Arduino when it is
connected to HIGH or LOW
- Connect one LED at pin 13, and
push button to pin 8.
- Pin 13 (LED) is the ‘output’ pin
while pin 8 (push button) is the
input.
- In this example, the LED will only
be blinking IF the button is
pressed, which becomes a
condition in the program.
- Write the program flow chart.
49
Example 4: Push button and limit switch
as input
51
Example 5: Switch to activate LEDs
pattern
- Signal from Push button will be used to
activate array of LEDs blinking pattern.
- Connect four LEDs to pin 2 to pin 5 as
and push button at pin 1
- This is the combination of Example 3
and Example 4.
- In this example, if button is pressed,
then LEDs will blink according to certain
pattern.
- If button is not pressed, then, LEDs will
be OFF
- Write the program flow chart.
52
Example 5: Switch to activate LEDs
pattern
53
Example 5: Switch to activate LEDs
pattern
54
Example 6: Potentiometer as analog
input
- Potentiometer is a variable resistor
where the voltage read varies according
to the position of the knob
- The varying resistor will vary the voltage
input.
- This varying voltage is an analog signal
and will be scaled to digital values.
- Connect the circuit as shown with the
middle pin of potentiometer is
connected to pin A0 (analog input 0)
- By varying the knob slowly, the LED will
turn ON one by one until all LEDs are
ON.
55
Example 6: Potentiometer as analog
input
- Since potentiometer will vary the voltage
(analog input), the voltage level will be
partitioned to 5 level which are:
ANALOG DIGITAL
0
0V 1024 <1
0 = 256
4 256
5V
1024 <2
512
- map block from math operator is used to
<3
do this operation 768
<4
1024
=4
56
Example 6: Potentiometer as analog
input
57
Example 6: Potentiometer as analog
input
58
Example 6: Potentiometer as analog
input
59
Example 6: Potentiometer as analog
input
60
Example 7: Relay control
62
Demo on Simulator - Tinkercad
63
Simulator
64
Create WA group and
we are Arduino family!
-Terima kasih-
65