Arduino Programming TRAINING

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Khairil Nizam Khairuddin

Smk Bandar Baru Batang Kali


Kursus KSSM Mikropemproses 2018
0146435314
Arduino Programming

Buat flow chart dulu.

START

END

CONTOH FLOW CHART

/* dan */ utk programming to be void. (line mana yang kita tak nak or spare)

// comment yang tidak dibaca , boleh digunakan sebagai nota

delay = selamasa

println =bacaan dalam menegak

print =bacaan secara menegak

analog terminal =A0 – A5

digitalWrite = hantar signal secara bit (HIGH/LOW)

pinMode = declare pin yang digunakan.


Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
1st Project

BLINKING LED

+ 1K LED

void setup() { //jangan lupa setting dulu

// put your setup code here, to run once:

pinMode(13,OUTPUT);

void loop() { // PROGRAM BERMULA DISINI!

digitalWrite(13,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

delay(1000);

digitalWrite(13,LOW); // LOW (OFF) // put your main code here, to run repeatedly:

delay(1000);

digitalWrite(13,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

delay(1000);

}
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314

Sambungan

5v

Gnd

Pin 13

Pin 13 digunakan sebagai output utk menghantar isyarat kepada LED supaya menyala.
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
2ND Project

2 LED BLINKING

+ 1K LED

1K LED

void setup() { //jangan lupa setting dulu

// put your setup code here, to run once:

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

void loop() { // PROGRAM BERMULA DISINI!

digitalWrite(13,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

digitalWrite(12,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

delay(1000);

digitalWrite(13,LOW); // LOW (OFF)

digitalWrite(12,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

delay(1000);

digitalWrite(13,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

digitalWrite(12,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

delay(1000);

}
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314

Sambungan

5v

Gnd

Pin 13

Pin 12

Sambungan pin 13 dan 12 digunakan bagi penyambungan LED supaya menyala. Kadar selamasa
bagi kelipan lampu ditentukan pada pengaturcaraan delay. 1000 = 1saat.

3RD Project
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
3 LED RUNNING LIGHT

+ 1K LED

1K LED

1K LED

-
void setup() { //jangan lupa setting dulu

// put your setup code here, to run once:

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

pinMode(8,OUTPUT);

void loop() { // PROGRAM BERMULA DISINI!

digitalWrite(13,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (OFF)

digitalWrite(12,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (OFF)

digitalWrite(8,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (OFF)

delay(500);

digitalWrite(13,LOW); // LOW (ON)

digitalWrite(12,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (OFF)

digitalWrite(8,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (OFF)

delay(500);

digitalWrite(13,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (OFF)

digitalWrite(12,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (OFF)

digitalWrite(8,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (OFF)

delay(500);

}
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314

Sambungan

5v

Gnd

Pin 13

Pin 12

Pin 8

Hasil gabungan diantara 3 Led. Pengaturcara boleh mengubah suai litar utk nyalaan 3 Led secara
serentak atau berselang seli. Kadar selamasa ditentukan dalam aturcara delay.

*harus diingat, semua penyambungan led harus menggunakan perintang. Lazimnya pada kaki positif
Led.

4TH Project
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
TONE

+ PIN 7 BZZ

void setup() {

pinMode (7,OUTPUT);

void loop() // put your main code here, to run repeatedly:

tone (7,262,250);

delay (250);

tone (7,262,250);

delay (250);

tone (7,392,250);

delay (250);

tone (7,392,250);

delay (250);

tone (7,440,250);

delay (250);

tone (7,440,250);

delay (250);

tone (7,392,250);

delay (500);

5TH Project
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
3 LED WITH BUZZER
+ LED
1K

LED BUZZER
1K

1K LED
-
void setup() { //jangan lupa setting dulu

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

pinMode(8,OUTPUT);

pinMode(11,OUTPUT); // buzzer PORT 11

void loop() { // PROGRAM BERMULA DISINI!

digitalWrite(13,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

digitalWrite(12,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

digitalWrite(8,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

tone(11,220,1000);

delay(500);

digitalWrite(13,LOW); // LOW (OFF)

digitalWrite(12,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

digitalWrite(8,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

tone(11,247,1000);

delay(500);

digitalWrite(13,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

digitalWrite(12,LOW); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

digitalWrite(8,HIGH); // digitalWrite is a function that sends signal to a pin, turning it on or off. HIGH (ON)

tone(11,196,1000);

delay(500);

6th Project
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
POTENTIALMETER

Ground

Analog

Volt

void setup() { // put your setup code here, to run once

pinMode (A0, INPUT); //input dari analog potentialmeter

Serial.begin (9600); //channel serial analog

void loop() { // put your main code here, to run repeatedly:

int x = analogRead (A0); //POTENTIALMETER TERMINAL ANALOG DISAMBUNG KE A0

Serial.println(x); // keluarkan nilai analog ke skrin

Serial.println(" "); // keluarkan nilai ke skrin secara menegak

delay (1000); // kelajuan bacaan serial monitor

*SELESAI PENYAMBUNGAN BUKA TOOLS SERIAL MONITOR UNTUK SEMAK NILAI RESISTOR
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314

Sambungan

5v

Gnd

Pin A0
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
7TH PROJECT

POTENTIALMETER WITH LED

Ground GND

Analog ARDUINO PIN13 LED

5V
Volt

void setup() { // put your setup code here, to run once

pinMode (A0, INPUT); //input dari analog potentialmeter

pinMode(13,OUTPUT); //PIN Led

Serial.begin (9600); //channel serial analog

}void loop() {

// put your main code here, to run repeatedly:

int x = analogRead (A0); //POTENTIALMETER

Serial.println(x); // keluarkan nilai analog ke skrin

Serial.println(" "); // keluarkan nilai ke skrin secara menegak

analogWrite (13,x); // hantar nilai dari potentialmeter ke Led = pin 13

delay (500); // kelajuan bacaan serial monitor

}
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314

Sambungan

5v

Gnd

Pin 13

*pengujian litar dimana Led akan menyala jika diberikan arus yang cukup, selain itu, litar boleh diuji
dgn mentol utk menguji keterangan dan kemalapan cahaya mentol tersebut.
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
8TH PROJECT

LDR

LDR ARDUINO SERIAL MONITOR

void setup() {

// put your setup code here, to run once

pinMode (A1, INPUT); //input dari LDR

Serial.begin (9600); //channel serial analog

void loop() { // put your main code here, to run repeatedly:

int x = analogRead (A1); //LDR

Serial.println(x); // keluarkan nilai analog ke skrin

Serial.println(" "); // keluarkan nilai ke skrin secara menegak

//analogWrite (13,x); // hantar nilai dari potentialmeter ke Led = pin 13 ( TIDAK


DIGUNAKAN )

delay (500); // kelajuan bacaan serial monitor

}
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314

Sambungan

5v

Gnd

Pin A1

*Pengujian litar berlaku dengan menutup permukaan LDR bagi mendapatkan bacaan pada serial
monitor.
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314
9TH PROJECT

LDR WITH LED

LDR ARDUINO SERIAL MONITOR LED

void setup() {

// put your setup code here, to run once

pinMode (5,OUTPUT); //sambungan LED

pinMode (A1, INPUT); //input dari LDR

Serial.begin (9600); //channel serial analog

void loop() { // put your main code here, to run repeatedly:

int x = analogRead (A1); //LDR

Serial.println(x); // keluarkan nilai analog ke skrin

Serial.println(" "); // keluarkan nilai ke skrin secara menegak

analogWrite (5,x); // hantar nilai dari potentialmeter ke Led = pin8

delay (1000); // kelajuan bacaan serial monitor

}
Khairil Nizam Khairuddin
Smk Bandar Baru Batang Kali
Kursus KSSM Mikropemproses 2018
0146435314

Sambungan

5v

Gnd

Pin A0 = Pin Ldr

Pin 5 = Led

*pengujian litar dimana Led akan padam jika permukaan Ldr ditutup, selain itu juga bacaan pada
serial monitor juga boleh diambil.

You might also like