Académique Documents
Professionnel Documents
Culture Documents
arduino
1 sec
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.
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.
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
delay(1000);
Then observe the LED changes state.
7 Exercise
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);
}
5
digitalWrite(10, LOW);
Write Code delay(500);
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);
}
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);
}
}
void setup() {
pinMode(6, INPUT);
pinMode(12, OUTPUT);
the differences!!!
pinMode(3, INPUT);
pinMode(8, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
5
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;
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.
}
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
}