Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 51

INTRODUCTION TO ARDUINO

Embedded System
Agenda
Day Time Agenda

2.30pm Tinkercad Classroom


2.50pm Tinkercad Circuit Interface
3.10pm Introduction to Arduino
Day 1 Arduino with Tinkercad
3.15pm Project 1
3.45pm Project 2
4.15pm Closing
10.00am Project 3
Day 2 10.30am Project 4
11.00pm Project 5
11.30am Closing (LADAP Survey & Project Ignite)
Boleh “turn on” Test microphone
camera anda

ANDA SUDAH BERSEDIA?

perkongsian link Ubah fon anda ke


menerusi rangan mod senyap
chat
Portal - PSC Panduan Guru
http://bit.ly/pscteachers
RBT > Maker UNO/Arduino > Introduction to Arduino Module
Activities
1 Strobe Light
2 Running LEDs
3 Running Musical LEDs
4 Touch Musical LEDs
5 Touch Musical Fan & LED
Tinkercad interface
Dashboard

New project

Past project
Project name Tinkercad interface
Building components

1 Rotate

2 Delete

3 Undo/Redo

4 Comment

5 View/Hide

6 Wire Color
7 Wire Type

Open building area


Tinkercad interface

Programming area
Arduino type
3 STEPS TO PROGRAM AN ARDUINO:

1 Build the Hardware

2 Type the Code

3 Start Simulation
ARDUINO UNO
EMBEDDED SYSTEM
INTRODUCTION
COMPONENTS

1 Jumper Wires 6 Pushbutton

2 Light Emitting Diode (LED) 7 NPN Transistor

3 Resistor 220Ω 6 DC Motor

4 Resistor 10kΩ

5 Piezo (Buzzer)
INTRODUCTION
OHM’S LAW
INTRODUCTION
HOW TO USE A BREADBOARD
INTRODUCTION
LED POLARITY
PROJECT 1: STROBE LIGHT
Troubleshooting Tips
Project 1:
Red Red Brown or 220 Ω

strobe light
Short Leg
Lets do it together…

Light up an LED using a digital output…


void setup ()

• "setup" has a () , means it is a function.

• Usually this function is for us to initialize pinMode and other initial


setup.
void loop ()

• loop is function and has (), is void function.

• Special function used by Arduino to always loop program after start().

• To break this loop, click Stop Simulation.


semicolon

• Semicolon(;) is to end line of code.

• Notify computer stop code in each line.

• Program cannot compile properly without ;


curly brackets

• Curly braces are used to enclose further instructions carried out


by a function

• There is always an opening curly bracket and a closing curly


bracket.
Project 1: Strobe light
Try changing different ‘delay’
(10 minutes)
values and observe the
behaviour of the LED
Software
Your First Program
Start

Turn on LED at Pin 7

Wait 1 second

Turn off LED at Pin 7

Wait 0.5 second

End
Setup
OUTPUT tells Arduino that this
pin is an output pin

Don’t forget to end the line with


a semicolon (;)
{

7 is the target pin for this function

{} pinMode is a function that tells


the Arduino the mode of a pin
(either INPUT or OUTPUT)
Curly bracket marks the beginning and
the end of a function.
Loop
Pin 7 is the target pin of the digitalWrite function

The signal sent is HIGH (ON)

digitalWrite is a function that sends signal to a pin


turning it on or off

The signal sent is LOW (OFF)

Time is measured in miliseconds.


{} Delay is a function that tells Arduino to wait for a particular period of
time.
Red Red Brown or 220 Ω

Does it work? Short Leg


What’s the problem?

Programming error

Hardware error
PROGRAMMING ERROR Source of
Error indication error

Error indication

HARDWARE ERROR
No orange line appears, but still your project does not work
Refer back to your circuit
Quiz Time! Let’s play Kahoot!
1. Get another device and go to www.kahoot.it
2. Select Play
3. Key in the Game PIN
4. Questions will appear on the laptop screen.
5. You need to answer the quiz through your another device.
PROJECT 2: RUNNING LED
Resistors
Light up the LED in sequence...
Project 2: Running LEDs
(20 minutes)

Red Red Brown or 220 Ω Hold it! Do not remove


the circuit from
Project 1! Just add two
more LEDs to your
existing circuit
Project 2: Running LEDs
(20 minutes)

Software

Upload code no.1,


then try code
no.2, do you see
any difference?
VS

1 2
How to read a
resistor colour code?

Eg. 4 band code = 560kΩ ±5%


1st band: green - 5
2nd band: blue - 6
Multiplier: yellow - 10kΩ
Tolerance: gold - ±5%

k means kilo (1000)


PROJECT 3: RUNNING MUSICAL LEDs
Tone Function
Project 3: Running Musical LEDs
(20 minutes)

Piezo buzzers are


simple devices that
can generate basic
beeps and tones.
Project 3: Musical touch
(20 minutes)

Software
Change to different
delay and tone values
and observe the
behaviour of your
circuit…Give it a try!

Fill in the
blanks
tone(pin, frequency)
To use it, you only need to tell the pin, which pin
the buzzer is connected to and which frequency
(in Hertz) you want.

For example: tone(5, 4000); 


produces a frequency of 4 kHz on the pin D5 on
Arduino.
NOTE_E6 165 NOTE_B6 247

noTone() NOTE_F6 175 NOTE_C4 262


NOTE_G 196 NOTE_D4 294
To stop the sound, we must use another function.
This function only need the pin which the buzzer 6 NOTE_E4 330
is connected to, without the necessity to specify NOTE_A6 220 NOTE_F4 349
the frequency.

For example: noTone(8)


PROJECT 4: TOUCH MUSICAL LEDs
Variables and If else function
Project 4: Touch Musical LEDs
(15 minutes)
Brown Black Orange or 10k Ω

Once you’ve done with


your code, press the
PushButton on your
simulation and see what
happens!
Project 4: Touch Musical LEDs
(15 minutes)

Continue..
if, else (Conditional statement)
You want to execute a block of code only if a particular condition is true. For example, you may want
to light an LED if a switch is pressed or if an analog value is greater than some threshold.

The if…else statement works as follows when the condition is tested true:
• statements inside the brackets of the if are executed when the condition is true
• statements inside the brackets of the else are skipped

The if…else statement works as follows when the condition is tested false:
• statements inside the brackets of if are skipped
• statement inside the brackets of else are executed.

Inside the parentheses, you can use various operators. The comparisons you can use are listed below.
• x ! = y ( x not equal to y )
• x < y ( x less than y )
• x > y ( x greater than y )
• x == y ( x equal to y )
• x < = y ( x less than or equal to y )
• x > = y ( x greater than or equal to y )
PROJECT 5: TOUCH MUSICAL FAN LEDs
Bonus: DC Motor
Project 5: Touch Musical Fan LEDs
(Bonus)

Continue..
Congratulation!
Closing
Thank you!
APPENDICES
"include"
"include" used starting code and include libraries into sketch.
  
"function"
• group code create name of function. For example, getMaximum().
• purpose of code in function getMaximum() return max value.
• function with () to identify is function/variable.

"return“
• Used in last line code in function.
• If function type is void, then no need return.
• If function type is integer, function return integer/ cannot compile

 
APPENDICES
"variable"
• Hold value in program.
• Variable name unique in entire system.
• Cannot have duplicate same variable names in code.

"declare“
• Assign data type to variable.
• Data type: int, char, string, double, float, bool.
• For example: int number; variable named "number" as 'integer’.

“initialize“
• Assign initial value to variable.
• For example, int number = 5; variable "number" is 'integer' hold value '5’.

You might also like