بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
Halo lagi nih bro, berjumpa lagi nih dengan ane di kesempatan yang semoga bahagia ini ya :)
Gimana nih kabar? semoga tetap diberikan nikmat sehat ya gan, biar bisa terus semangat.
Di hari ini, kita masih bermain - main dengan arduino dan ethernet shield nih. Setelah sebelumnya kita telah mencoba memulai dengan ethernet shield untuk menampilkan Input analog ataupun digital arduino pada web browser . Nah, kalau sekarang tidak jauh berbeda gan, kita sekarang akan mengontrol pin output dari arduino melalui web browser ente gan!
Di tutorial lainnya yang sudah ane publish di blog ini, mungkin sudah cukup banyak ya gan artikel tentang mengontrol relay dengan Arduino. Ada yang via bluetooth dan lainnya. Nah kalau di artikel kali ini, kita juga akan mencoba menggunakan Ethernet shield untuk mengontrol relay yang terhubung pada pin output arduino melalui web server. Simak aja langsung deh :)
Alat dan Bahan yang dibutuhkan :
1x Arduino UNO
1x Ethernet Shield
1x Relay Modul
Koneksi Internet
Kabel jumper secukupnya
Breadboard (Project Board)
Langkah - Langkahnya :
1.) Pertama, susunlah rangkaian seperti gambar dibawah ini
Keterangan Konfigurasi Kabel :
Tancapkan Ethernet Shield pada Board Arduino
Hubungkan Pin 5V Arduino ke VCC pada Relay Modul
Hubungkan GND Arduino ke GND pada Relay Modul
Hubungkan Pin 2 Arduino ke IN1 pada Relay Modul
Hubungkan Pin 3 Arduino ke IN2 pada Relay Modul
Hubungkan Pin 4 Arduino ke IN3 pada Relay Modul
Hubungkan Pin 5 Arduino ke IN4 pada Relay Modul
2.) Setelah itu sambungkan Arduino pada Laptop/PC dengan menggunakan kabel serial.
3.) Download dan Install program Arduino IDE di Arduino.cc ( If Needed )
4.) Setelah terinstall, jalankan program Arduino-nya.
5.) Klik menu "Tools -> Board -> Arduino Uno"
6.) Klik menu "Tools -> Port -> ( Pilih Port arduino yang terdeteksi di komputer anda )
7.) Lalu masukan Sketch dibawah ini, dan klik upload.
Klik LIHAT DONG untuk melihat sketch Active HIGH
#include < SPI . h >
#include < Ethernet . h >
int relay1 = 2 ;
int relay2 = 3 ;
int relay3 = 4 ;
int relay4 = 5 ;
boolean statusR1 , statusR2 , statusR3 , statusR4 = false ;
String readString ;
char c ;
byte mac [ ] = { 0xDA , 0xAD , 0xBE , 0xEB , 0xFE , 0xFB } ;
IPAddress ip ( 192 , 168 , 0 , 182 ) ;
EthernetServer server ( 80 ) ;
void setup ( ) {
pinMode ( relay1 , OUTPUT ) ;
pinMode ( relay2 , OUTPUT ) ;
pinMode ( relay3 , OUTPUT ) ;
pinMode ( relay4 , OUTPUT ) ;
Serial . begin ( 9600 ) ;
while ( ! Serial ) { ; }
Ethernet . begin ( mac , ip ) ;
server . begin ( ) ;
}
void loop ( ) {
EthernetClient client = server . available ( ) ;
if ( client ) {
while ( client . connected ( ) ) {
if ( client . available ( ) ) {
c = client . read ( ) ;
if ( readString . length ( ) < 100 ) {
readString += c ;
}
if ( c == '\n' ) {
client . println ( "HTTP/1.1 200 OK" ) ;
client . println ( "Content-Type: text/html" ) ;
client . println ( ) ;
client . println ( "<HTML>" ) ;
client . println ( "<HEAD>" ) ;
client . println ( "<meta http-equiv=\"Refresh\" content=\"4; url=/wakwaw\" />" ) ;
client . println ( "<meta http-equiv=\"Content-Type\" content=\"application/vnd.wap.xhtml+xml; charset=utf-8\" />" ) ;
client . println ( "<link type=\"text/css\" rel=\"stylesheet\" href=\"http://haidao.mw.lt/js_css/css_pages.css\" />" ) ;
client . println ( "<TITLE>Room Automation</TITLE>" ) ;
client . println ( "</HEAD>" ) ;
client . println ( "<BODY align=\"center\">" ) ;
client . println ( "<h1>Penel Kontrol Ruang Kerja Andy182 </h1>" ) ;
client . println ( "<hr />" ) ;
client . println ( "<br />" ) ;
client . println ( "<br />" ) ;
client . println ( "<table align=\"center\"><tr>" ) ;
client . println ( "<th width=\"10%\">Nama Perangkat</th>" ) ;
client . println ( "<th width=\"10%\">Status Perangkat</th>" ) ;
client . println ( "<th width=\"10%\">Saklar ON/OFF</th></tr>" ) ;
client . println ( "<tr class=\"trh1\"><td align=\"left\">" ) ;
client . println ( " " ) ;
client . println ( " " ) ;
client . println ( "Relay 1" ) ;
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR1 == false ) {
client . println ( "<b>MATI</b>" ) ;
} else {
client . println ( "<b>HIDUP</b>" ) ;
}
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR1 == false ) {
client . println ( "<a href=\"/1on\" />HIDUP</a>" ) ;
} else {
client . println ( "<a href=\"/1off\" />MATI</a>" ) ;
}
client . println ( "</td></tr>" ) ;
client . println ( ) ;
client . println ( "<tr class=\"trh2\"><td align=\"left\">" ) ;
client . println ( " " ) ;
client . println ( " " ) ;
client . println ( "Relay 2" ) ;
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR2 == false ) {
client . println ( "<b>MATI</b>" ) ;
} else {
client . println ( "<b>HIDUP</b>" ) ;
}
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR2 == false ) {
client . println ( "<a href=\"/2on\" />HIDUP</a>" ) ;
} else {
client . println ( "<a href=\"/2off\" />MATI</a>" ) ;
}
client . println ( "</td></tr>" ) ;
client . println ( ) ;
client . println ( "<tr class=\"trh1\"><td align=\"left\">" ) ;
client . println ( " " ) ;
client . println ( " " ) ;
client . println ( "Relay 3" ) ;
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR3 == false ) {
client . println ( "<b>MATI</b>" ) ;
} else {
client . println ( "<b>HIDUP</b>" ) ;
}
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR3 == false ) {
client . println ( "<a href=\"/3on\" />HIDUP</a>" ) ;
} else {
client . println ( "<a href=\"/3off\" />MATI</a>" ) ;
}
client . println ( "</td></tr>" ) ;
client . println ( ) ;
client . println ( "<tr class=\"trh2\"><td align=\"left\">" ) ;
client . println ( " " ) ;
client . println ( " " ) ;
client . println ( "Relay 4" ) ;
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR4 == false ) {
client . println ( "<b>MATI</b>" ) ;
} else {
client . println ( "<b>HIDUP</b>" ) ;
}
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR4 == false ) {
client . println ( "<a href=\"/4on\" />HIDUP</a>" ) ;
} else {
client . println ( "<a href=\"/4off\" />MATI</a>" ) ;
}
client . println ( "</td></tr>" ) ;
client . println ( ) ;
client . println ( "</BODY>" ) ;
delay ( 1 ) ;
client . stop ( ) ;
if ( readString . indexOf ( "1on" ) > 0 ) {
digitalWrite ( relay1 , HIGH ) ;
statusR1 = true ;
}
if ( readString . indexOf ( "1off" ) > 0 ) {
digitalWrite ( relay1 , LOW ) ;
statusR1 = false ;
}
if ( readString . indexOf ( "2on" ) > 0 ) {
digitalWrite ( relay2 , HIGH ) ;
statusR2 = true ;
}
if ( readString . indexOf ( "2off" ) > 0 ) {
digitalWrite ( relay2 , LOW ) ;
statusR2 = false ;
}
if ( readString . indexOf ( "3on" ) > 0 ) {
digitalWrite ( relay3 , HIGH ) ;
statusR3 = true ;
}
if ( readString . indexOf ( "3off" ) > 0 ) {
digitalWrite ( relay3 , LOW ) ;
statusR3 = false ;
}
if ( readString . indexOf ( "4on" ) > 0 ) {
digitalWrite ( relay4 , HIGH ) ;
statusR4 = true ;
}
if ( readString . indexOf ( "4off" ) > 0 ) {
digitalWrite ( relay4 , LOW ) ;
statusR4 = false ;
}
readString = "" ; } } } } }
Klik LIHAT BRAY untuk melihat sketch Active LOW
#include < SPI . h >
#include < Ethernet . h >
int relay1 = 2 ;
int relay2 = 3 ;
int relay3 = 4 ;
int relay4 = 5 ;
boolean statusR1 , statusR2 , statusR3 , statusR4 = false ;
String readString ;
char c ;
byte mac [ ] = { 0xDA , 0xAD , 0xBE , 0xEB , 0xFE , 0xFB } ;
IPAddress ip ( 192 , 168 , 0 , 182 ) ;
EthernetServer server ( 80 ) ;
void setup ( ) {
pinMode ( relay1 , OUTPUT ) ;
pinMode ( relay2 , OUTPUT ) ;
pinMode ( relay3 , OUTPUT ) ;
pinMode ( relay4 , OUTPUT ) ;
digitalWrite ( relay1 , HIGH ) ;
digitalWrite ( relay2 , HIGH ) ;
digitalWrite ( relay3 , HIGH ) ;
digitalWrite ( relay4 , HIGH ) ;
Serial . begin ( 9600 ) ;
while ( ! Serial ) { ; }
Ethernet . begin ( mac , ip ) ;
server . begin ( ) ;
}
void loop ( ) {
EthernetClient client = server . available ( ) ;
if ( client ) {
while ( client . connected ( ) ) {
if ( client . available ( ) ) {
c = client . read ( ) ;
if ( readString . length ( ) < 100 ) {
readString += c ;
}
if ( c == '\n' ) {
client . println ( "HTTP/1.1 200 OK" ) ;
client . println ( "Content-Type: text/html" ) ;
client . println ( ) ;
client . println ( "<HTML>" ) ;
client . println ( "<HEAD>" ) ;
client . println ( "<meta http-equiv=\"Refresh\" content=\"4; url=/wakwaw\" />" ) ;
client . println ( "<meta http-equiv=\"Content-Type\" content=\"application/vnd.wap.xhtml+xml; charset=utf-8\" />" ) ;
client . println ( "<link type=\"text/css\" rel=\"stylesheet\" href=\"http://haidao.mw.lt/js_css/css_pages.css\" />" ) ;
client . println ( "<TITLE>Room Automation</TITLE>" ) ;
client . println ( "</HEAD>" ) ;
client . println ( "<BODY align=\"center\">" ) ;
client . println ( "<h1>Penel Kontrol Ruang Kerja Andy182 </h1>" ) ;
client . println ( "<hr />" ) ;
client . println ( "<br />" ) ;
client . println ( "<br />" ) ;
client . println ( "<table align=\"center\"><tr>" ) ;
client . println ( "<th width=\"10%\">Nama Perangkat</th>" ) ;
client . println ( "<th width=\"10%\">Status Perangkat</th>" ) ;
client . println ( "<th width=\"10%\">Saklar ON/OFF</th></tr>" ) ;
client . println ( "<tr class=\"trh1\"><td align=\"left\">" ) ;
client . println ( " " ) ;
client . println ( " " ) ;
client . println ( "Relay 1" ) ;
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR1 == false ) {
client . println ( "<b>MATI</b>" ) ;
} else {
client . println ( "<b>HIDUP</b>" ) ;
}
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR1 == false ) {
client . println ( "<a href=\"/1on\" />HIDUP</a>" ) ;
} else {
client . println ( "<a href=\"/1off\" />MATI</a>" ) ;
}
client . println ( "</td></tr>" ) ;
client . println ( ) ;
client . println ( "<tr class=\"trh2\"><td align=\"left\">" ) ;
client . println ( " " ) ;
client . println ( " " ) ;
client . println ( "Relay 2" ) ;
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR2 == false ) {
client . println ( "<b>MATI</b>" ) ;
} else {
client . println ( "<b>HIDUP</b>" ) ;
}
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR2 == false ) {
client . println ( "<a href=\"/2on\" />HIDUP</a>" ) ;
} else {
client . println ( "<a href=\"/2off\" />MATI</a>" ) ;
}
client . println ( "</td></tr>" ) ;
client . println ( ) ;
client . println ( "<tr class=\"trh1\"><td align=\"left\">" ) ;
client . println ( " " ) ;
client . println ( " " ) ;
client . println ( "Relay 3" ) ;
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR3 == false ) {
client . println ( "<b>MATI</b>" ) ;
} else {
client . println ( "<b>HIDUP</b>" ) ;
}
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR3 == false ) {
client . println ( "<a href=\"/3on\" />HIDUP</a>" ) ;
} else {
client . println ( "<a href=\"/3off\" />MATI</a>" ) ;
}
client . println ( "</td></tr>" ) ;
client . println ( ) ;
client . println ( "<tr class=\"trh2\"><td align=\"left\">" ) ;
client . println ( " " ) ;
client . println ( " " ) ;
client . println ( "Relay 4" ) ;
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR4 == false ) {
client . println ( "<b>MATI</b>" ) ;
} else {
client . println ( "<b>HIDUP</b>" ) ;
}
client . println ( "</td><td align=\"center\">" ) ;
if ( statusR4 == false ) {
client . println ( "<a href=\"/4on\" />HIDUP</a>" ) ;
} else {
client . println ( "<a href=\"/4off\" />MATI</a>" ) ;
}
client . println ( "</td></tr>" ) ;
client . println ( ) ;
client . println ( "</BODY>" ) ;
delay ( 1 ) ;
client . stop ( ) ;
if ( readString . indexOf ( "1on" ) > 0 ) {
digitalWrite ( relay1 , LOW ) ;
statusR1 = true ;
}
if ( readString . indexOf ( "1off" ) > 0 ) {
digitalWrite ( relay1 , HIGH ) ;
statusR1 = false ;
}
if ( readString . indexOf ( "2on" ) > 0 ) {
digitalWrite ( relay2 , LOW ) ;
statusR2 = true ;
}
if ( readString . indexOf ( "2off" ) > 0 ) {
digitalWrite ( relay2 , HIGH ) ;
statusR2 = false ;
}
if ( readString . indexOf ( "3on" ) > 0 ) {
digitalWrite ( relay3 , LOW ) ;
statusR3 = true ;
}
if ( readString . indexOf ( "3off" ) > 0 ) {
digitalWrite ( relay3 , HIGH ) ;
statusR3 = false ;
}
if ( readString . indexOf ( "4on" ) > 0 ) {
digitalWrite ( relay4 , LOW ) ;
statusR4 = true ;
}
if ( readString . indexOf ( "4off" ) > 0 ) {
digitalWrite ( relay4 , HIGH ) ;
statusR4 = false ;
}
readString = "" ; } } } } }
NOTE : Ubah 192.168.0.182 dan sesuaikan IP Adress pada sketch.
VIDEO
Terimakasih telah berkunjung, selamat mencoba, semoga bermanfaat.
Assalamualaikum, om request saklar internet pke modul sim800l bisa gk ya? ^_^
ReplyDeleteWaalaikum salam, kalau modul sim800l ane belum punya modulnya gan... Mungkin nanti ane pakai modul Sim900 yang sudah ane punya.
Deleteok gan, ditunggu tutorialnya ya? ^_^
Deletetrims
kalau dengan Ethernet Module ENC28J60 sama gk skecth-nya?
ReplyDeleteBeda gan.
Deletebikin tampilan web servernya itu kayak gimana gan ?
ReplyDeleteMasukkan HTML dan CSS pada sketch di arduinonya.
Deletekalau koneksi internet pake mifi smartfren gak ada slot rj45 buat ethernet shieldnya solusinya gimana ga?
ReplyDeleteSolusinya, pakai ESP8266
Deletegan saya coba buka di hape dengan tulis ip nya pada jaringan wifi yg sama ga bisa terkoneksi, mohon bantuan gan
ReplyDeleteCoba ulangi kembali tutorialnya dari awal, mungkin ada step yang terlewatkan.
DeleteThis comment has been removed by the author.
ReplyDeleteBisa.
Deleteassalamulaikum kak ini sudah bisa control lampu atau cuma relay saja ?
ReplyDeleteWaalaikum salam. Bisa keduanya, kan kalau contact NO/NC relay dihubungkan ke lampunya... Bisa untuk mematikan dan menyalakan lampu.
DeleteGan itu ip nya publik apa lokal ?
ReplyDeleteKalau yang ini Lokal gan, kalau mau bisa diakses dimana saja pakai Teleduino aja.
DeleteKetik saja di pencarian blog ini "Teleduino"
asalamualaikum mhn pencerahan kenapa semua relay on pada saat arduio mendapatkan daya atau di aktifkan pertama kali
ReplyDeleteWaalaikum salam, pakai sketch yang Active LOW ukalau pakai Relay Active LOW.
Deletegan klo g niat share g usah d sahre .
ReplyDeletepake acara kodingnya sengaja disalahain
kalau bisa itu gan mempermudah kesulitan orang
bukan malah mempersulit keadaan
ingat siapa yg mempermudah kesulitan orang maka dia akan di permudah jua segala urusannya
Halo, maaf sebelumnya. Kalau memang anda sudah mencoba dan gagal, sertakan saja kegagalannya dimana... Jangan malah membuat kesan putus asa seperti itu.
DeletePraktek gak selamanya mulus sesuai teori, kalau pengunjung blog ini ada yang berhasil dan ente gak berhasil, Tentunya ada faktor faktor yang menyebabkan kegagalan ente. Dicari permasalahan, jangan frustasi. Oke?
bg,... tolong penjelasan yang ini...
ReplyDeletemksih bg...
href=\"http://haidao.mw.lt/js_css/css_pages.css\" />");
Itu untuk modifikasi tampilan di web browsernya.
Deletemantap ni tutorial saya coba pake mega2560 coba pake 16 relay mantap da masih nantang makasih gan tutorialya semoa bertambah barokaah amin
ReplyDelete