Vous êtes sur la page 1sur 17

Arduino Starter Kit - Basic

Target Audience: Arduino First timer


Target project: Simple functional piano.
Tutorial 1 - Arduino IDE Software
+ This lesson will basically teach you how to install the Arduino IDE Software.

Tutorial 2 - First LED blinking


+ The tutorial will guide you to upload a code into the Arduino board itself and
make on-board LED blink.

Tutorial 3 - LED Blink code


+ Tutorial 3 will teach you how to write a LED blink code from a simple
connection then upload the coding into the Arduino board.

Tutorial 4 – Chasing LED


+ This tutorial will show how to manipulate a LED connection to Arduino board

Tutorial 5 – Press and Light


+ This tutorial will teach how to control the two inputs components

Tutorial 6 - Switching LEDs


+ This tutorial will show you how to control more than one LED

Tutorial 7 – Music Time


+ Tutorial 7 will provide the lesson to add DO, RE, MI, FA, SO, LA, TI and DO

Challenge – A Piano Project


Tutorial 1 –
Installing Arduino IDE Software

1 Go to Arduino Website 2 The File


Download Arduino software at
https://www.arduino.cc/en/Main/Software Extract downloaded
file and open the Arduino
Download here !!! icon

arduino

3 The Software What is the most important to a new user?


Here where we can see
either the Arduino board
is connected to computer Upload arrow sign to upload
or not the code into Arduino board

Arduino team provide a


lots of example code to
be used
Tutorial 2 - My First Led Blink
1 Parts

1. What the things you need: a computer with Arduino


IDE Software, an Arduino board and a USB cable.
2. Connect your Arduino Board to computer USB Port
using a USB cable.

2 What is the plan? 1. The small embedded LED with


‘L’ labelled is call on board
“LED”.
2. We will try to make this
embedded LED to blink.
1 sec

1 sec

3 Example Code 1. Open arduino IDE


2. Go to “File”
3. Go to “example”
4. Go to “01 Basic”
5. Click and open “Blink”
example.
Tutorial 2 - My First Led Blink
4 Check Connection

4. Go to Port “COMX (Arduino/Genuino Uno)”


5. Then select “COMX (Arduino/Genuino
Uno)”
1. Go to “Tools”.
2. Go to Board “XXXX” Hint: If “Tools/Port” did not appear, there is a problem
3. Select “Arduino/Genuino Uno” with the connection between your arduino and
computer. Try to reconnect the cable again.

5 Upload Code 2. Go through the code.


1. If your code
3. Press the upload arrow successfully
sign and wait while the updated to the
code is uploading from computer, then
your computer to the “Done
Arduino Board. Uploading” will
be appear.

6 Result

On board 1 sec

“LED” is now
blinking 1 sec
Breadboard Why we need it?
The easiest way to series connected between two or more
components.

How to use this breadboard to connect a LED and resistor as


shown in figure above? The most convenient way is to use a
breadboard.

1. Take a breadboard
and the components. 3. So here are the
You wish to connect possible ways to
one end of LED to connect one end of
another end of LED to another end
resistor. of resistor.

2. The blue line


show how the
hole is actually
connected.
Tutorial 3 - LED Blinking Code
2 Circuit Let’s construct!

1 Red
Led
Parts
Gather 220Ω
these
parts.

3 Write Code
// LED Blinking

void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{

4
digitalWrite(13, HIGH);

Upload Code
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

5 Tip
LED Not Lighting Up? 1sec 1sec
Try taking it out and twisting the LED
polarity.
Tutorial 3 - LED Blinking Code
6 Change

Find this word and try to change number in it,


maybe between 100 to 5000.

delay(1000);
Then observe the LED changes state.

7 Exercise

Try to find the corresponding value to this delay in


seconds. Change in your program and upload the
code

1 Second = delay( );
3 Seconds = delay( );
5 Seconds = delay( );
Tutorial 4 – Chasing LED
1
2
220Ω x 4 unit
Circuit Let’s construct!
Parts
Yellow Led

Gather
these Blue Led
parts.
Green Led

Red Led

3 Write Code
void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}

Now you can see LED connected


to pin 13 is blinking.
Tutorial 4- Chasing LED
4 Write Code
6 Write Code

Add some more code. Now you can see LED


void setup() {
pinMode(13, OUTPUT);

connected to pin 13 and 10 is blinking.


pinMode(10, OUTPUT); void setup() {
} pinMode(13, OUTPUT);
pinMode(10, OUTPUT);
void loop() { pinMode(6, OUTPUT);
digitalWrite(13, HIGH); pinMode(2, OUTPUT);
delay(500); }
digitalWrite(13, LOW);
delay(500); void loop() {
digitalWrite(13, HIGH);
digitalWrite(10, HIGH); delay(500);
delay(500); digitalWrite(13, LOW);
digitalWrite(10, LOW); delay(500);
delay(500);
} digitalWrite(10, HIGH);
delay(500);

5
digitalWrite(10, LOW);
Write Code delay(500);

void setup() { digitalWrite(6, HIGH);


pinMode(13, OUTPUT); delay(500);
Add some more code. Now you can see LED connected

pinMode(10, OUTPUT); digitalWrite(6, LOW);


pinMode(6, OUTPUT); delay(500);
}
digitalWrite(2, HIGH);
void loop() { delay(500);
digitalWrite(13, HIGH); digitalWrite(2, LOW);
delay(500); delay(500);
digitalWrite(13, LOW); } Edit the
delay(500); code and
to pin 13, 10 and 6 is blinking.

digitalWrite(10, HIGH); observe


delay(500); the effect.
digitalWrite(10, LOW);
delay(500); Add some more code. Now you
can see LED connected to pin 13,
digitalWrite(6, HIGH); 10, 6 and 2 is blinking.
delay(500);
digitalWrite(6, LOW);
delay(500);
}
Tutorial 5 – Press and light
1
2
220Ω
Circuit Let’s construct!
Parts
10kΩ

Blue
Gather
Led
these
parts. Switch

3 Write Code
void setup() {
pinMode(12, OUTPUT);
}

void loop() {
digitalWrite(12, HIGH);
delay(500);
digitalWrite(12, LOW);
delay(500);
}

Now you can see LED connected


to pin 12 is blinking. Just to make
sure the LED connection.
Tutorial 5 – Press and light
4 Write Code
void setup() {
pinMode(12, OUTPUT); //LED
pinMode(8, INPUT); //Switch
}
void setup() {
void loop() { pinMode(12, OUTPUT);
if( digitalRead(8) == HIGH ) }
{
//Switch is pressed void loop() {
//What happen? digitalWrite(12, HIGH);
//LED should ON delay(500);
} digitalWrite(12, LOW);
else delay(500);
{ }
//Switch did not press
//What happen
//LED should OFF
}
}

Light

3
Up !!! Press !!!
Write Code
void setup() {
pinMode(12, OUTPUT); //LED
pinMode(8, INPUT);
//Switch
}

void loop() {
if( digitalRead(8) == HIGH )
{ NO Press
digitalWrite(12, HIGH);
}
else
{
digitalWrite(12, LOW);
}
}
Tutorial 6 – Switching LEDs
1
2
220Ω X 4units
Circuit Let’s construct!
Parts
10kΩ X 4units

Blue Led
Gather
X 4 units
these
parts. Switch
X 4 units

3 Write Code
void setup() {
pinMode(13, OUTPUT);
pinMode(6, INPUT);
}

void loop() {
if( digitalRead(6) == HIGH
)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}

Now you can see LED connected to pin


13 is light up when switch at pin 6 is
pressed. Just to make sure your LED and
switch connection is correct.
Tutorial 6 – Switching LEDs
4 How to activate the others
void setup() { Duplicate OUTPUT and
pinMode(12, OUTPUT); //LED
INPUT declaration, keep
pinMode(8, INPUT); //Switch
} it mind to change the pin
void loop() {
number accordingly.
if( digitalRead(8) == HIGH )
{
digitalWrite(12, HIGH); Duplicate the “if else”
}
else statement, keep it mind
{ to change the pin
digitalWrite(12, LOW);
} number accordingly.
}

void setup() {

Upload the code, play with it.


pinMode(13, OUTPUT);
Write Code

pinMode(6, INPUT);
pinMode(12, OUTPUT);

Adjust the code, and observe


pinMode(5, INPUT);
pinMode(10, OUTPUT);

the differences!!!
pinMode(3, INPUT);
pinMode(8, OUTPUT);
pinMode(2, INPUT);
}

void loop() {
5

if( digitalRead(6) == HIGH ) {


digitalWrite(13, HIGH); }
else{
digitalWrite(13, LOW); }

if( digitalRead(5) == HIGH ) {


digitalWrite(12, HIGH); }
else{
digitalWrite(12, LOW); }

if( digitalRead(3) == HIGH ) {


digitalWrite(10, HIGH); }
else{
digitalWrite(10, LOW); }

if( digitalRead(2) == HIGH ){


digitalWrite(8, HIGH); }
else{
digitalWrite(8, LOW); }
}
Tutorial 7 – Music Time
1 Circuit Let construct!

Hint: Red wire of piezo buzzer


can only connected to pin 3, 5,
6, 19 and 11 and set as output.
You can notice that beside these
pin with ~ sign.

2 Later in coding, we will


use these notations:
Music
Note c-d-e-f-g-a-b-C
Do re mi fa so la ti DO
Tutorial 7 – Music Time
3 Set up basic code
void setup()
{
pinMode(6, OUTPUT);
}

void loop()
{

}
4 Add music code
// The tempo is how fast to play the song.
// To make the song play faster, decrease this value.
int tempo = 150;

// This value will be overwrite later in the loop()


int duration = 0;

void setup()
{
pinMode(6, OUTPUT); This is a music code
}
part, it’s okay if you
void loop() don’t understand it
{ for a first timer.
}

int frequency(char note)


{
if(note == ' ') return(0);
int i;
const int numNotes = 8;
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
for (i = 0; i < numNotes; i++) {
if (names[i] == note) return(frequencies[i]);
}
return(0);
}
Tutorial 7– Music Time
5 Edit void loop()
void loop()
{
duration = 1 * tempo;
tone(6, frequency('c'), duration);
delay(duration); // wait for tone to finish
delay(tempo/10); // brief pause between notes

duration = 2 * tempo;
tone(6, frequency('d'), duration);
delay(duration); // wait for tone to finish
delay(tempo/10); // brief pause between notes

duration = 1 * tempo;
tone(6, frequency('f'), duration);
delay(duration); // wait for tone to finish
delay(tempo/10); // brief pause between notes

duration = 4 * tempo;
tone(6, frequency(' '), duration);
delay(duration); // wait for tone to finish
delay(tempo/10); // brief pause between notes

duration = 1 * tempo;
tone(6, frequency('d'), duration);
delay(duration); // wait for tone to finish
delay(tempo/10); // brief pause between notes

duration = 4 * tempo;
tone(6, frequency('a'), duration);
delay(duration); // wait for tone to finish
delay(tempo/10); // brief pause between notes
}

Here is the part of the code to


produce sound. Play with the
number in this code and observe
the difference.
Challenge – Piano Time
By combining these two
projects, you can make a
Piano.

If you are able to do this challenge, you are most


welcome to post the video or picture in the Facebook
with hastag:
#pianoTime
#STEMfactory
#nadiEleczone

Vous aimerez peut-être aussi