MAKALAH
Diajukan Untuk Memenuhi Persyaratan Menyelesaikan
Mata Kuliah PROJECT AKHIR
Oleh:
AHMAD JATI WIDODO (0220120049)
ARDHINATA BAYU KURNIAWAN (0220120051)
DAMAR ARDYANSYAH (0220120053)
PROGRAM STUDI
TEKNIK PRODUKSI DAN PROSES MANUFAKTUR
KONSENTRASI MEKATRONIKA
POLITEKNIK MANUFAKTUR ASTRA
JAKARTA
2015
BAB I
PENDAHULUAN
1.1
Latar belakang
Semakin
berkembangnya
teknologi
yang
pesat
saat
ini
1.2
Tujuan penelitian
Manfaat
2 BAB II
2.1
Pengertian Mikronkontroller
Mikrokontroler disebut juga MCU atau C adalah salah satu
yaitu:
CPU
(Central
Processing
Unit)
atau
unit
digunakan
dalam
beberapaperalatan
otomatik
seperti
dari
suatu
mikrokontroler
yang
mempunyai
ke/dari
mikrokontroler.
mikrokontroler
mempunyai
semua
Tidak
komponen
semua
tersebut,
jenis
mikrokontroler
tertentu.
Dalam
suatu
setiap
terdapat
mikrokontroler,
pada
beberapa
sedangkan
jenis
EEPROM
mikrokontroler
hanya
tertentu.
yang
berfungsi
mikrokontroler.
Mikroprocessor
sebagai
adalah
otak
peranti
dari
yang
register-register.
Register
adalah
tempat
dengan
serial.
peranti
Terdapat
lain
berbagai
menggunakan
standar
atau
dan
USART
(Universal
Synchronous-
1.
2.
3.
4.
5.
6.
7.
4. Browser
Browser di sini digunakan untuk melihat hasil pembuatan halaman web serta
digunakan untuk akses Linksys basi setup. Terdapat banyak aplikasi browser
diantaranya adalah Google Chrome, Mozilla Firefox, UC Browser, Internet
Explorer dan masih banyak lagi lainnya. Berikut adalah contoh dari tampilan web
browser Mozilla Firefox.
Berdasarkan topologi jaringan diatas, sistem kontrol Smart Home dibagi menjadi
beberapa bagian, yaitu:
1. Perangkat Input:
a. Push Button
b. Client / User (Komputer / Laptop)
2. Perangkat Proses:
a. Arduino Mega 2560
b. Arduino Ethernet Shield
c. Linksys Wifi Router
3. Perangkat Output:
a. 5VDC Relay 4 channel
b. Lampu
c. Stop kontak (terminal)
2.2.4 Pembuatan Wiring Sistem Kontrol
Berikut ini adalah diagram wiring pada project smart home .
Dan berikut merupakan tabel I/O yang digunakan pada Arduino Mega 2560:
Setelah melakukan konfigurasi pada Internet Ip address kemudian pilih pada tab
application & gaming untuk melakukan konfigurasi Ip yang di-forward oleh router
wi-fi yang juga sebagai Ip address pada ethernet shield arduino. Berikut merupakan
gambar konfigurasi Ip yang di-forward wi-fi router.
Berikut adalah gambar setelah membuat program html maka tampilan web server
pada ip 192.168.1.101
2.3
Pengujian
Berikut ini adalah pengujian yang dilakukan pada smart home setelah dilakukan
program dan konfigurasi IP . Pengujian ini dikendalikan melalui aplikasi browser
untuk mengakses IP yang telah dikonfigurasi.
3.
4.
7.
8.
10.
11.
13.
3
14.
3.1
BAB III
PENUTUP
kesimpulan
15.
diakses
melalui
web
browser
yang
kemudian
dapat
saran
16.
Refernsi
19.
http://www.vedcmalang.com/pppptkboemlg/index.php/
menuutama/listrik-electro/1045-part-2
20.
http://www.vedcmalang.com/pppptkboemlg/index.php/
menuutama/listrik-electro/1053-part-3
21.
LAMPIRAN
1. Program HTML
22. <!DOCTYPE html>
23. <html>
24.
<head>
25.
<title>Smart Home Mekatronika 2015</title>
26.
<script>
27.
strLED1 = "";
28.
strLED2 = "";
29.
strLED3 = "";
30.
strLED4 = "";
31.
var LED1_state = 0;
32.
var LED2_state = 0;
33.
var LED3_state = 0;
34.
var LED4_state = 0;
35.
function GetArduinoIO()
36.
{
37.
nocache = "&nocache=" + Math.random() * 1000000;
38.
var request = new XMLHttpRequest();
39.
request.onreadystatechange = function()
40.
{
41.
if (this.readyState == 4) {
42.
if (this.status == 200) {
43.
if (this.responseXML != null) {
44.
// XML file received - contains analog values, switch values and LED states
45.
var count;
46.
//LED1
47.
if (this.responseXML.getElementsByTagName('LED')[0].childNodes[0].nodeValue === "on0") {
48.
document.getElementById("LED1").innerHTML = "Lampu 1 ON (D22)";
49.
LED1_state = 1;
50.
}
51.
if (this.responseXML.getElementsByTagName('LED')[0].childNodes[0].nodeValue === "off0") {
52.
document.getElementById("LED1").innerHTML = "Lampu 1 OFF (D22)";
53.
LED1_state = 0;
54.
}
55.
//LED2
56.
if
(this.responseXML.getElementsByTagName('LED')
[1].childNodes[0].nodeValue === "on1") {
57.
document.getElementById("LED2").innerHTML = "Lampu 2 ON (D23)";
58.
LED2_state = 1;
59.
}
60.
if (this.responseXML.getElementsByTagName('LED')[1].childNodes[0].nodeValue === "off1") {
61.
document.getElementById("LED2").innerHTML = "Lampu 2 OFF (D23)";
62.
LED2_state = 0;
63.
}
64.
//LED3
65.
if
(this.responseXML.getElementsByTagName('LED')
[2].childNodes[0].nodeValue === "on2") {
66.
document.getElementById("LED3").innerHTML = "Lampu 3 ON (D24)";
67.
LED3_state = 1;
68.
}
69.
if (this.responseXML.getElementsByTagName('LED')[2].childNodes[0].nodeValue === "off2") {
70.
document.getElementById("LED3").innerHTML = "Lampu 3 OFF (D24)";
71.
LED3_state = 0;
72.
}
73.
//LED4
74.
if
(this.responseXML.getElementsByTagName('LED')
[3].childNodes[0].nodeValue === "on3") {
75.
document.getElementById("LED4").innerHTML = "Stop Kontak ON (D25)";
76.
LED4_state = 1;
77.
}
78.
if (this.responseXML.getElementsByTagName('LED')[3].childNodes[0].nodeValue === "off3") {
79.
document.getElementById("LED4").innerHTML = "Stop Kontak OFF (D25)";
80.
LED4_state = 0;
81.
}
82.
}
83.
}
84.
}
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
}
// send HTTP GET request with LEDs to switch on/off if any
request.open("GET", "ajax_inputs" + strLED1 + strLED2 + strLED3 + strLED4 + nocache, true);
request.send(null);
setTimeout('GetArduinoIO()', 1000);
strLED1 = "";
strLED2 = "";
strLED3 = "";
strLED4 = "";
}
function GetButton1()
{
if (LED1_state === 1) {
LED1_state = 0;
strLED1 = "&LED1=0";
}
else {
LED1_state = 1;
strLED1 = "&LED1=1";
}
}
function GetButton2()
{
if (LED2_state === 1) {
LED2_state = 0;
strLED2 = "&LED2=0";
}
else {
LED2_state = 1;
strLED2 = "&LED2=1";
}
}
function GetButton3()
{
if (LED3_state === 1) {
LED3_state = 0;
strLED3 = "&LED3=0";
}
else {
LED3_state = 1;
strLED3 = "&LED3=1";
}
}
function GetButton4()
{
if (LED4_state === 1) {
LED4_state = 0;
strLED4 = "&LED4=0";
}
else {
LED4_state = 1;
strLED4 = "&LED4=1";
}
}
</script>
<style>
.IO_box {
float: left;
margin: 0 20px 20px 0;
border: 1px solid blue;
padding: 0 5px 0 5px;
width: 120px;
}
h1 {
font-size: 120%;
color: blue;
margin: 0 0 10px 0;
}
h2 {
font-size: 85%;
color: #5734E6;
margin: 5px 0 5px 0;
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
}
p, form, button {
font-size: 80%;
color: #252525;
}
.small_text {
font-size: 70%;
color: #737373;
}
marquee_text{
font-size: 100%;
color: #252525;
}
</style>
</head>
<body onload="GetArduinoIO()">
<marquee direction="up" behavior="scroll" scrollamount="2" scrolldelay="100" height="40px">Selamat
Datang di Smart Home Web Controller</marquee>
174.
<h1>Politeknik Manufaktur Astra</h1>
175.
<h1>Smart Home - Mekatronika</h1>
176.
<h1>2015</h1><br>
177.
<div class="IO_box">
178.
<h2>Lampu 1</h2>
179.
<button type="button" id="LED1" onclick="GetButton1()">Lampu 1 OFF (D22)</button><br /><br />
180.
</div>
181.
<div class="IO_box">
182.
<h2>Lampu 2</h2>
183.
<button type="button" id="LED2" onclick="GetButton2()">Lampu 2 OFF (D23)</button><br /><br />
184.
</div>
185.
<div class="IO_box">
186.
<h2>Lampu 3</h2>
187.
<button type="button" id="LED3" onclick="GetButton3()">Lampu 3 OFF (D24)</button><br /><br />
188.
</div>
189.
<div class="IO_box">
190.
<h2>Stop Kontak</h2>
191.
<button type="button" id="LED4" onclick="GetButton4()">Stop Kontak OFF (D25)</button><br /><br />
192.
</div>
193. </body><br>
194.</html
195.
2. Program Arduino
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
/*
* Program Name : Arduino Smart Home Ethernet Controller
* Author
: Ahmad Jati Widodo
* Year
: 2015
* Focus
: Mechatronics
* Study
: Politeknik Manufaktur Astra, Jakarta
*/
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ 60
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 106); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
File webFile;
// the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;
// index into HTTP_req buffer
boolean LED_state[4] = {0}; // stores the states of the LEDs
void setup()
{
// disable Ethernet chip
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
Serial.begin(9600);
// for debugging
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
// check for index.htm file
if (!SD.exists("index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
// switches
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
// LEDs
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin();
// start to listen for clients
}
void loop()
{
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
delay(5);
// give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
// read buttons and debounce
ButtonDebounce();
}
// function reads the push button switch states, debounces and latches the LED states
// toggles the LED states on each push - release cycle
// hard coded to debounce two switches on pins 2 and 3; and two LEDs on pins 6 and 7
// function adapted from Arduino IDE built-in example:
// File --> Examples --> 02.Digital --> Debounce
void ButtonDebounce(void)
{
static byte buttonState[4]
= {LOW, LOW, LOW, LOW}; // the current reading from the input pin
static byte lastButtonState[4] = {LOW, LOW, LOW, LOW}; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
static long lastDebounceTime[4] = {0}; // the last time the output pin was toggled
long debounceDelay = 50;
// the debounce time; increase if the output flickers
byte reading[4];
reading[0]
reading[1]
reading[2]
reading[3]
=
=
=
=
digitalRead(5);
digitalRead(6);
digitalRead(7);
digitalRead(8);
LED_state[0]);
LED_state[1]);
LED_state[2]);
LED_state[3]);
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
446.
447.
448.
}
// checks if received HTTP request is switching on/off LEDs
// also saves the state of the LEDs
void SetLEDs(void)
{
// LED 1 (pin 22)
if (StrContains(HTTP_req, "LED1=1")) {
LED_state[0] = 1; // save LED state
digitalWrite(22, HIGH);
}
else if (StrContains(HTTP_req, "LED1=0")) {
LED_state[0] = 0; // save LED state
digitalWrite(22, LOW);
}
// LED 2 (pin 23)
if (StrContains(HTTP_req, "LED2=1")) {
LED_state[1] = 1; // save LED state
digitalWrite(23, HIGH);
}
else if (StrContains(HTTP_req, "LED2=0")) {
LED_state[1] = 0; // save LED state
digitalWrite(23, LOW);
}
// LED 3 (pin 24)
if (StrContains(HTTP_req, "LED3=1")) {
LED_state[2] = 1; // save LED state
digitalWrite(24, HIGH);
}
else if (StrContains(HTTP_req, "LED3=0")) {
LED_state[2] = 0; // save LED state
digitalWrite(24, LOW);
}
// Stop Kontak (pin 25)
if (StrContains(HTTP_req, "LED4=1")) {
LED_state[3] = 1; // save LED state
digitalWrite(25, HIGH);
}
else if (StrContains(HTTP_req, "LED4=0")) {
LED_state[3] = 0; // save LED state
digitalWrite(25, LOW);
}
}
// send the XML file with analog values, switch status
// and LED status
void XML_response(EthernetClient cl)
{
int analog_val;
// stores value read from analog inputs
int count;
// used by 'for' loops
int sw_arr[] = {5, 6, 7, 8}; // pins interfaced to switches
cl.print("<?xml version = \"1.0\" ?>");
cl.print("<inputs>");
// button LED states
// LED1
cl.print("<LED>");
if (LED_state[0]) {
cl.print("on0");
}
else {
cl.print("off0");
}
449.
450.
451.
452.
453.
454.
455.
456.
457.
458.
459.
460.
461.
462.
463.
464.
465.
466.
467.
468.
469.
470.
471.
472.
473.
474.
475.
476.
477.
478.
479.
480.
481.
482.
483.
484.
485.
486.
487.
488.
489.
490.
491.
492.
493.
494.
495.
496.
497.
498.
499.
500.
501.
502.
503.
504.
505.
506.
507.
508.
509.
510.
511.
512.
cl.println("</LED>");
// button LED states
// LED2
cl.print("<LED>");
if (LED_state[1]) {
cl.print("on1");
}
else {
cl.print("off1");
}
cl.println("</LED>");
// button LED states
// LED3
cl.print("<LED>");
if (LED_state[2]) {
cl.print("on2");
}
else {
cl.print("off2");
}
cl.println("</LED>");
// button SK states
// Stop Kontak
cl.print("<LED>");
if (LED_state[3]) {
cl.print("on3");
}
else {
cl.print("off3");
}
cl.println("</LED>");
cl.print("</inputs>");
}
// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
for (int i = 0; i < length; i++) {
str[i] = 0;
}
}
// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
513.
514.
515.
516.
517.
518.
519.
520.
521.
522.
523.
524.
}
}
else {
found = 0;
}
index++;
}
return 0;
}