Sei sulla pagina 1di 30

PENDAMPINGAN KKSI

Jakarta, 3-5 September 2019


Rita Hartati, S.Pd.,MT

Configurasi

Node MCU

1. Pada Arduino IDE masuk ke menu File, terus pilih Preferences.


2. Lalu pada Additional Board Manager URLs:, masukan
link http://arduino.esp8266.com/stable/package_esp8266com_index.json , lalu klik Ok.
3. Lalu ke menu Tools, klik Board, lalu klik Boards Manager…
4. di Filter your search… atau dikolom pencarian masukan esp, klik esp8266 by ESP8266
Community, klik Install.

5. Tunggu sampai proses Install selesai, lalu tekan Close.

BLYNK
Skecth -> Include Library -> Manage Libraries

Search Blynk dan install Blynk library


Lab 1. Smart Home
Alat yang diperlukan :

 NodeMCU
 Lampu LED
 Kabel Jumper
Rakit :

Blynk :
di bikin 3 lampu lalu outputnya d1, d2, d3
Skrip :

1. #define BLYNK_PRINT Serial


2. #include <ESP8266WiFi.h>
3. #include <BlynkSimpleEsp8266.h>
4.
5. // You should get Auth Token in the Blynk App.
6. // Go to the Project Settings (nut icon).
7. char auth[] = "NEYTzr5thrk0tbTSJvwSzSkXu5j9mop2"; //Token blynk yg di email
8.
9. // Your WiFi credentials.
10. // Set password to "" for open networks.
11. char ssid[] = "Start"; //nama wifi
12. char pass[] = "1234567890"; //password wifi
13.
14. void setup()
15. {
16. // Debug console
17. Serial.begin(9600);
18.
19. Blynk.begin(auth, ssid, pass);
20. }
21.
22. void loop()
23. {
24. Blynk.run();
25. }

Lab 2. Smart Cat/Fish Feeder


Alat yang dibutuhkan :

 NodeMCU
 Motor Servo
 Kabel Jumper
Rakit :
Skrip :
Lab 3. Smart Trash
Membuat Tempat sampah otomatis
Alat yang dibutuhkan :
- Servo
- Arduino Uno
- Sensor Ultrasonik
- Baterai

Susun alat tadi sepeti dibawah ini


1. #include <Servo.h> //servo library
2. Servo servo;
3. int trigPin = 5;
4. int echoPin = 6;
5. int servoPin = 7;
6. int led= 10;
7. long duration, dist, average;
8. long aver[3]; //array for average
9.
10.
11. void setup() {
12. Serial.begin(9600);
13. servo.attach(servoPin); //mangatur posiso servo
14. pinMode(trigPin, OUTPUT);
15. pinMode(echoPin, INPUT);
16. servo.write(0); //close cap on power on
17. delay(100);
18. servo.detach();
19. }
20.
21. void measure() {
22. digitalWrite(10,HIGH);
23. digitalWrite(trigPin, LOW); // treigerpinnya dipastikan mati
24. delayMicroseconds(5);
25. digitalWrite(trigPin, HIGH); //terus dinyalain
26. delayMicroseconds(15);
27. digitalWrite(trigPin, LOW);
28. pinMode(echoPin, INPUT);
29. duration = pulseIn(echoPin, HIGH); //pulse in mengatur waktu yang dibutuhkan echopin untuk
menyala
30. dist = (duration/2) / 29.1; //obtain distance //jarak gelombang suara dari trigger dan kembali ke
echo
31. //dist (duration/2) / suhu
32. }
33. void loop() {
34. for (int i=0;i<=2;i++) { //average distance
35. measure();
36. aver[i]=dist;
37. delay(10); //delay between measurements
38. }
39. dist=(aver[0]+aver[1]+aver[2])/3;
40.
41. if ( dist<50 ) {
42. //Change distance as per your need
43. servo.attach(servoPin);
44. delay(1);
45. servo.write(0);
46. delay(3000);
47. servo.write(150);
48. delay(1000);
49. servo.detach();
50. }
51. Serial.print(dist);
52. }

Lab 4. Smart Watering Plant

Alat yang dibutuhkan :


1. Soil moisturizer sensor
2. Relay
3. Arduino uno
4. Motor Water Pump
5. USB Cabel to arduino
6. Kabel jumper
Rakit :

 Soil moisturizer
A0 ke A0 arduino
GND ke GND arduino
VCC ke 3,3V

 Relay

GND ke GND arduino


IN ke pin 4 digital Arduino
VCC ke 5V arduino
COM ke 5V arduino

 Water Pump
Kabel merah ke NC Relay

Kabel hitam ke GND arduino

Skrip :
1. int sensor_pin = A0; // Soil Sensor input at Analog PIN A0
2. int output_value ;
3. void setup() {
4. // put your setup code here, to run once:
5. pinMode(4,OUTPUT);
6. Serial.begin(9600);
7.
8. Serial.println("Reading From the Sensor ...");
9.
10. delay(2000);
11.
12. }
13.
14.
15. // put your main code here, to run repeatedly:
16.
17. void loop() {
18.
19. output_value= analogRead(sensor_pin);
20.
21. output_value = map(output_value,550,10,0,100);
22.
23. Serial.print("Mositure : ");
24.
25. Serial.print(output_value);
26.
27. Serial.println("%");
28.
29. if(output_value<0){
30. digitalWrite(4,HIGH);
31. }
32. else{
33. digitalWrite(4,LOW);
34. }
35. delay(1000);
36. }

Lab 5. Smart Weather Station


Alat yang dibutuhkan :

 NodeMCU
 DHT11
 Kabel Jumper

Rakit :
Blynk :
Skript :
Pertama masukan semua librarynya dulu
Dan simple timer pada link berikut :
https://github.com/schinken/SimpleTimer

1. #define BLYNK_PRINT Serial


2. #include <ESP8266WiFi.h>
3. #include <BlynkSimpleEsp8266.h>
4. #include <DHT.h>
5. #include <SimpleTimer.h>
6.
7. #define DHTPIN D3
8. #define DHTTYPE DHT11
9.
10. DHT dht(DHTPIN, DHTTYPE);
11. SimpleTimer timer;
12.
13. float humi, temp;
14. char auth[] = "fKsjBr5jcs_2D5kZ1jagiWESdUFyDNxh";
15. char ssid[] = "Start";
16. char pass[] = "1234567890";
17.
18. void setup() {
19. // put your setup code here, to run once:
20. dht.begin();
21. Serial.begin(115200);
22. delay(10);
23. Blynk.begin(auth, ssid, pass);
24. timer.setInterval(1000L, sendData);
25.
26. Serial.println("Suhu dan Kelembaban\n\n");
27.
28. }
29.
30. void sendData()
31. {
32. humi = dht.readHumidity();
33. temp = dht.readTemperature();
34. Blynk.virtualWrite(1, temp);
35. Blynk.virtualWrite(2, humi);
36. }
37.
38. void loop() {
39. // put your main code here, to run repeatedly:
40. float humi = dht.readHumidity();
41. float temp = dht.readTemperature();
42. Serial.print("Suhu Sekarang = ");
43. Serial.print(temp);
44. Serial.print("C\n");
45. Serial.print("kelembaban Sekarang = ");
46. Serial.print(humi);
47. Serial.print("%\n");
48. delay(800);
49.
50. Blynk.run();
51. timer.run();
52.
53. }

Lab 6. Smart Parking

Alat yang dibutuhkan :

 NodeMCU
 Sensor Infrared
 Kabel jumper
Rakit :

Blynk ;

Script :
1. #define BLYNK_PRINT Serial
2. #include <ESP8266WiFi.h>
3. #include <BlynkSimpleEsp8266.h>
4.
5. char auth[] = "YjcpAkwo8TeQ0oSgEA-qNXqkMO-eZ7wu";
6. char ssid[] = "jonggol";
7. char pass[] = "jonggol756";
8.
9. WidgetLED led1(V1); // Virtual LED to show status on App
10. WidgetLED led2(V2);
11.
12. int sensor1 = D1; // IR Sensors
13. int sensor2 = D2;
14.
15. void setup()
16. {
17. Serial.begin(9600);
18. Blynk.begin(auth, ssid, pass);
19.
20. pinMode(sensor2,INPUT);
21. pinMode(sensor1,INPUT);
22.
23. while (Blynk.connect() == false) {
24. // Wait until connected
25. }
26. }
27. void loop() {
28. int sensorval1 = digitalRead(sensor1); // Saving Values os sensors
29. int sensorval2 = digitalRead(sensor2);
30. Serial.println(sensorval1); // printing values
31. Serial.println(sensorval2);
32. delay(1000);
33. if (sensorval1 == 1)
34. {
35. led1.on(); // Setting virtual led on the app
36. }
37.
38. if (sensorval2 == 1)
39. {
40. led2.on();
41. }
42.
43.
44. if (sensorval1 == 0)
45. {
46. led1.off();
47. }
48.
49. if (sensorval2 == 0)
50. {
51. led2.off();
52. }
53.
54. Blynk.run();
55.
56. }

Lab 7. RFID dan e-ktp

RFID
Alat yang dibutuhkan :

 Arduino
 Kabel usb to arduino
 RFID
 Kabel jumper
Rakit :

READER PIN-OUT————————–TO ARDUINO


SDA ————————————————-10
SCK————————————————–13

MOSI————————————————11
MISO————————————————12

IRQ—————————————————Not connected
GND————————————————-GND

RST—————————————————-9
3.3V—————————————————3.3V

NOTE: Do not power the reader with 5V. You will fry the reader
Skrip :
(menggunakan example dari MFRC22 yang dumpinfo)

1. #include <SPI.h>
2. #include <MFRC522.h>
3.
4. #define RST_PIN 9 // Configurable, see typical pin layout above
5. #define SS_PIN 10 // Configurable, see typical pin layout above
6.
7. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
8.
9. void setup() {
10. Serial.begin(9600); // Initialize serial communications with the PC
11. while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on
ATMEGA32U4)
12. SPI.begin(); // Init SPI bus
13. mfrc522.PCD_Init(); // Init MFRC522
14. mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
15. Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
16. }
17.
18. void loop() {
19. // Look for new cards
20. if ( ! mfrc522.PICC_IsNewCardPresent()) {
21. return;
22. }
23.
24. // Select one of the cards
25. if ( ! mfrc522.PICC_ReadCardSerial()) {
26. return;
27. }
28.
29. // Dump debug info about the card; PICC_HaltA() is automatically called
30. mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
31. }

EKTP script
1. #include <SPI.h>
2. #include <MFRC522.h>
3. #define pinSDA 10
4. #define pinRST 9
5. MFRC522 RFID(pinSDA, pinRST);
6. void setup() {
7. Serial.begin(9600);
8. SPI.begin();
9. RFID.PCD_Init();
10. Serial.println("");
11. Serial.println("Tap Kartu/Gantungan !");
12. Serial.println();
13. }
14. void loop() {
15. if ( ! RFID.PICC_IsNewCardPresent()) {
16. return;
17. }
18. if ( ! RFID.PICC_ReadCardSerial()) {
19. return;
20. }
21. Serial.print("ID Tag :");
22. String content = "";
23. byte letter;
24. for (byte i = 0; i < RFID.uid.size; i++) {
25. Serial.print(RFID.uid.uidByte[i] < 0x10 ? " 0" : " ");
26. Serial.print(RFID.uid.uidByte[i], HEX);
27. content.concat(String(RFID.uid.uidByte[i] < 0x10 ? " 0" : " "));
28. content.concat(String(RFID.uid.uidByte[i], HEX));
29. }
30. Serial.println();
31. delay(2500);
32. }

Lab 8. RFID BASED SECURITY ACCESS CONTROL SYSTEM

Meneruskan RFID, sekarang kita akan mencoba membuat pengamanan dengan rfid

Alat yang dibutuhkan :


 Arduino Uno
 RFID
 Servo
 Kabel Jumper

Rakit :
Skrip :

Kita menggunakan skrip example MFRC22 dumpinfo dan ditambahkan skirp yang ada didalam
kotak merah

1. #include <SPI.h>
2. #include <MFRC522.h>
3. #define SS_PIN 10
4. #define RST_PIN 9
5. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
6. String cards[] ={ "E0 70 D1 18","E8 D7 0B 89"};// change to your tag UID
7. String users[] = {"Alade kayode","Eden Hazard"};// change to your username
8. #include <Servo.h>
9. Servo myservo;
10. void setup()
11. {
12. Serial.begin(9600); // Initiate a serial communication
13. SPI.begin(); // Initiate SPI bus
14. mfrc522.PCD_Init(); // Initiate MFRC522
15. Serial.println("Scan Your Tag...");
16. Serial.println();
17. myservo.attach(6); // attaches the servo on pin 6 to the servo object
18. }
19.
20. void loop()
21. {
22. // Look for new cards
23. if ( ! mfrc522.PICC_IsNewCardPresent())
24. {
25. return;
26. }
27. // Select one of the cards
28. if ( ! mfrc522.PICC_ReadCardSerial())
29. {
30. return;
31. }
32. //Show UID on serial monitor
33. Serial.print("UID tag :");
34. String content= "";
35. byte letter;
36. for (byte i = 0; i < mfrc522.uid.size; i++)
37. {
38. Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
39. Serial.print(mfrc522.uid.uidByte[i], HEX);
40. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
41. content.concat(String(mfrc522.uid.uidByte[i], HEX));
42. }
43. Serial.println();
44. Serial.print("Message : ");
45. content.toUpperCase();
46. if (content.substring(1) == cards[0] )
47. {
48.
49. Serial.println("Access Granted");
50. Serial.print("User: ");
51. Serial.println(users[0]);
52. unlock();
53. lock();
54. }
55. else if (content.substring(1) == cards[1] )
56. {
57.
58. Serial.println("Access Granted");
59. Serial.print("User: ");
60. Serial.println(users[1]);
61. unlock();
62. lock();
63. }
64. else {
65. Serial.println(" Access denied");
66. delay(1000);
67. }
68. }
69. void unlock()
70. {
71. for (int pos = 0; pos <= 180; pos += 1)
72. { // goes from 0 degrees to 180 degrees in steps of 1 degree
73. myservo.write(pos); // tell servo to go to position in variable 'pos'
74. delay(15); // waits 15ms for the servo to reach the position
75. }
76. delay(3000);
77. }
78. void lock()
79. {
80. for (int pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
81. myservo.write(pos); // tell servo to go to position in variable 'pos'
82. delay(15); // waits 15ms for the servo to reach the position
83. }
84. }

Lab 9. Lampu Relay dengan Google Assistant

LED Relay with Google Asistant


Alat yang di butuhkan :

 Node MCU
 Relay
 Kabel Jumper
 Lampu LED
 Dudukan Lampu
 Terminal
Rakit :

 Relay
GND ke GND Node MCU
IN ke D2
VCC ke 3V

 Kabel terminal
(kupas kulit putihnya terus potong salah satu kabelnya yang ada didalamnya, sambungkan ke
NC dan COM Relay)

IFTTT :
Buka web ifttt lalu sign in, buat applest baru
Ini untuk Ini untuk
lamp on lamp off

URL = https://”ip blynk”/”token blynk”/action/pin


BLYNK :
Skrip :
(Skrip menggunakan example blynk wifi standalone)

26. #define BLYNK_PRINT Serial


27. #include <ESP8266WiFi.h>
28. #include <BlynkSimpleEsp8266.h>
29.
30. // You should get Auth Token in the Blynk App.
31. // Go to the Project Settings (nut icon).
32. char auth[] = "NEYTzr5thrk0tbTSJvwSzSkXu5j9mop2";
33.
34. // Your WiFi credentials.
35. // Set password to "" for open networks.
36. char ssid[] = "Start";
37. char pass[] = "1234567890";
38.
39. void setup()
40. {
41. // Debug console
42. Serial.begin(9600);
43.
44. Blynk.begin(auth, ssid, pass);
45. }
46.
47. void loop()
48. {
49. Blynk.run();
50. }