Category Archives: Etherned Shield

Connecting Arduino to LAN via Ethernet

Here we’re going to use an arduino uno board arduino

And we need an arduino ethernet controller, here’s the one that I used :

First of all, we need to plug arduino uno to arduino ethernet shield. Plug arduino ethernet shield over arduino board as follow :

Next plug rj45 to arduino ethernet shield and connect it to a router / switch, plug arduino virtual serial port to pc / notebook.

plug3

My laptop has ip address 192.168.1.2, we will give ip address of our arduino machine : 192.168.1.3, it can be done by using simple routine : IPAddress ip(192,168,1,3); The mac address can be seen below arduino ethernet shield, here my given mac address by arduino ethernet shield is 90-A2-DA-0F-17-D9, we set mac address simply : byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x17, 0xD9 };

For testing purpose we use this simple telnet daemon code :

 

/*  Telnet - A simple telnet daemon for testing arduino ethernet shield  Original from Simple Web Server by David A. Mellis & Tom Igoe  Modified by Antonius (Sw0rdm4n) */ 
#include <SPI.h> 
#include <Ethernet.h>  

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x17, 0xD9 }; 
IPAddress ip(192,168,1,3); 
IPAddress gateway(192,168,1,1); 
IPAddress subnet(255,255,255,0); 
EthernetServer server(23); 

void setup() {   
	Ethernet.begin(mac, ip);   
	server.begin(); 
} 
void loop() {   
	EthernetClient client = server.available();   
	if (client) {     
		int i;     
		boolean currentLineIsBlank = true;     
		while (client.connected()) {       
			if (client.available() > 0) {           
				client.print("\nWelcome to simple telnet daemon using Arduino Ethernet Shield\n");           
				delay(1000);           
				client.print("\nGood bye 1337!!!\n");            
				break;       
			}     
		}     
		delay(1);     
		client.stop();   
	} 
} 

 

Upload this code to arduino uno. On success we can connect to telnet daemon on 192.168.1.3 using telnet client :

telnet_server

Advertisements