Judul : Belajar Arduino Ethernet Modul
link : Belajar Arduino Ethernet Modul
Belajar Arduino Ethernet Modul
hallo Sobat Arduino Indonesia,Sekarang lagi musim IOT nih, apa apa serba IOT (Internet Of Things). Sudah banyak diterapkan di kota-kota besar, pernah dengar Smart City kan, lha itu semuanya sudah nyambung ke internet, atau bisa di bilang Internet Of Things. Pada share kali ini tidak membahas tentang Internet of Things nya, tapi tentang koneksi arduino ke Jaringan komputer. Jadi nanti sobat bisa akses Arduino melalui browser dari komputer.
Lets go biar gak lama-lama
Bahan-bahan yang dibutuhkan sebagai berikut
1. Ethernet Module W5100
2. Arduino Uno Clone
3. Kabel Jumper dan kabel ethernet
Ethernet module yang di gunakan adalah type W5100, koneksi yang digunakan oleh ethernet ini dengan arduino adalah spi, jadi kita gunakan mosi, miso, sck, reset.
Berikut konfigurasi pin ethernet module dengan pin arduino
Setelah koneksi semua ke pin arduino dan ethernet module, buka arduino dan pilih example - ethernet - WebServer
atau sobat bisa copy paste dari program belajar arduino ethernet module berikut ini
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
Ethernet.maintain();
}
}
Langkah selanjutnya sambungkan kabel ethernet antara module ethernet dengan komputer, biar bisa terkonek jangan lupa setting IP di local komputer biar sama sama address nya. Untuk setting local komputer bisa di Control Panel - Network (pilih view Network Status and task) maka akan muncul berikut iniWeb Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
Ethernet.maintain();
}
}
Pilih Local Area Connection, dan
Pilih Properties - Internet Protocol Version (TCP/IPv4). kemudian isi ip Adress nya
//IPAddress ip(192, 168, 1, 177);
IPAddress ip(192, 168, 0, 101); //ip ini digunakan untuk mengakses data dari arduino
Upload program arduino.
Tips : Jika pada proses uploadnya gagal-gagal terus, kabel jumper yang menuju ke reset di cabut dahulu, kemudian setelah upload berhasil, baru di sambungkan kembali
Ketika proses upload sudah berhasil buka browser dan ketikan di url nya 192.168.0.101 kemudian tekan enter
Data yang diatas adalah data yang didapat dari pin analog arduino.
Untuk lebih jelasnya bisa di lihat pada video berikut ini, jangan lupa like, comment dan subscribe ya biar cepet update nya. Salam Arduino Indonesia
Demikianlah Artikel Belajar Arduino Ethernet Modul
Sekianlah artikel Belajar Arduino Ethernet Modul kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel Belajar Arduino Ethernet Modul dengan alamat link https://arduinolibs.blogspot.com/2016/07/belajar-arduino-ethernet-modul.html
0 Response to "Belajar Arduino Ethernet Modul"
Post a Comment