Introduction: The Cheapest and Simplest Method to Control Arduino Through Ethernet
A video on how to control arduino through ethernet. Full two way communication both sending and reciving!
Shows the overview, wiring instructions, arduino sketch, testing as well as an extra part on creating an android app that communicates with the server on the ethernet module.
arduino sketch below, just copy and paste
// A simple web server that shows temperature and controlls an LED
#include "etherShield.h"
#include "ETHER_28J60.h"
#include
OneWire ds(A3); // on pin A3
int celsius,celsiusF;
int outputPin = 3; //the LED pin
static uint8_t mac[6] = {
0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
// so unless you have more than one of these boards
// connected, you should be fine with this value.
static uint8_t ip[4] = {
192, 168, 1, 15}; // the IP address for your board. Check your home hub
// to find an IP address not in use and pick that
// this or 10.0.0.15 are likely formats for an address
// that will work.
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
void setup()
{
Serial.begin(9600);
e.setup(mac, ip, port);
}
void loop()
{
char* params;
if (params = e.serviceRequest())
{
e.print(" Temperature
");
e.print(celsius);
e.print(",");
e.print(celsiusF);
e.print(" C ");
e.print("
");
e.print("
");
e.print(" LED control ");
e.print("Turn off
");
e.print("Turn on
");
if (strcmp(params, "?cmd=on") == 0)
{
digitalWrite(outputPin, HIGH);
e.print("LED is ON");
}
else if (strcmp(params, "?cmd=off") == 0)
{
digitalWrite(outputPin, LOW);
e.print("LED is OFF");
}
e.respond();
delay(100);
}
else
{
{
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(10); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print(" Data = ");
Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();
// convert the data to actual temperature
unsigned int raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// count remain gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
// default is 12 bit resolution, 750 ms conversion time
}
celsius = abs(raw / 16.0);
celsiusF= (raw / 16.0 - celsius) * 100;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(",");
Serial.println(celsiusF);
}
}
}

Participated in the
Hardware Hacking

Participated in the
Microcontroller Contest
4 Comments
4 years ago
Hello how are you
I want to cut the network cable halfway down and connect it wirelessly
My question is, it did this with this module
If you have an experience with your friend.
This module can read the pins + rx, -rx, + tx, and -tx of the network port.
7 years ago on Introduction
hi. can you share how to make your phone app like in the video??? thank you :)
8 years ago on Introduction
can you please match the code to the video, this has been helpful but as shown it does not work. I went to www.trollmaker.com and found a simple version of this and with a little effort was able to get up and running
Reply 8 years ago on Introduction
ohh you mean arduino code?? yeah there is something wrong part of the code changed to links when I pasted it - that's because it was pasted as plain code and the html tags were interpreted as real html tags. Hmm I wonder if it can be fixed. Meanwhile go to the video description on YT and find a link to the thread on this project on arduino forum - you can download the arduino code there