Internet Control of Arduino

Hi everyone, This is my first post on the website so please be understanding. I have been playing with the Arduino for about a year and it is awesome. I can do the basics but looking to expand to the web. I have some basic questions that I was hoping you could answer.

1) Do I need the ethernet sheild, what are the advantages to the different sheilds? 2) Do I need my own webserver if I want to control the outputs on Arduino via the web? 3) I have the book called Making Things Talk, everything in this book uses a home webserver and PHP. Do I need to buy a seperate computer just to act as a server? 4) Do I need to talk to my ISP and buy a different service plan to set up a home server?

I have many applications but my first is the following: I have a dog that keeps getting on the couch during the day and leaving her hair everywhere. So I would like to set something up that when she gets on the couch I get a text message or email notifying me she is on the couch. I could then sign into Skype and watch her. As I am watching her, I would like to be able to activate a solenoid to shoot water or compressed air at her. I know this is a very difficult solution to something that could be solved in a much simpler way, but that would not be as entertaining. Also, we love our dog very much and are not doing this to be mean to her, she has a very nice soft dog bed 5' from the couch.

1) Do I need the ethernet sheild, what are the advantages to the different shields?

You need an Internet connection of some kind. The most common connection seems to be an Etherenet shield so you'll find the most examples there. A WiFi shield would work if you have a WiFi network. The serial protocol PPP (Point-to-Point Protocol) could be used if you have some way of routing it. I don't have an opinion on which Ethernet shield to use.

2) Do I need my own webserver if I want to control the outputs on Arduino via the web?

No. The Arduino will work as a web server.

3) I have the book called Making Things Talk, everything in this book uses a home webserver and PHP. Do I need to buy a seperate computer just to act as a server?

Whatever computer you already have can probably act as a web server.

4) Do I need to talk to my ISP and buy a different service plan to set up a home server?

Depends on your ISP. In general I find that they don't care as long as you don't host anything so wildly popular that you use a lot of upload bandwidth.

So I can use my normal desktop as a webserver and then switch it back to a computer when I need it? How is this done, with software? Maybe I dont need to do this if I can use the Arduino as the server? Again I apoligize I have never programmed before and have no webdesign experience.

There are a couple of different approaches possible here.

One is to use the Arduino as a "smart peripheral" of a new/existing PC that acts as the webserver. The PC doesn't have to be "switched" or dedicated: the webserver software is just another application that can be running on your PC while you're doing all the things you do normally. Commercial websites use dedicated machines because they're very busy, but your system won't be doing much. However, if you're running Windoze, I would recommend picking up an "obsolete" PC that you can get for (nearly) nothing, and putting Linux on it to run the webserver, because I don't trust MS software to protect the rest of your system from attacks via the webserver.

The other approach is, as John suggested, to put a network interface on the Arduino. The Ethernet shields based on the ENC28J60 are the cheapest, but they require more CPU and memory from the Arduino, and their libraries are not compatible with the ones for the "official" shield. So most of the examples you'll find online won't work with them. The shields based on the Wiznet chip (like the "official" one) are more expensive, but the Wiznet chip takes a lot of the workload off the Arduino CPU, and you have many examples to learn/borrow from.

WiFi shields are more expensive still, but might be worth it to you to avoid stringing cables that your dog could chomp. I have no experience with them, so I know nothing about how compatible their libraries are, or how many examples are available.

Personally, I wound up buying parts (I was lucky in that Wiznet was having a sale on modules at the time) and building my two Ethernet shields from scratch for about $30 apiece. When I recently looked into doing another one, I decided against using the ENC28J60 because I decided the incompatibility wasn't worth the cost savings. However, other folks have decided that the savings were worth the extra work: it's a matter of personal preference. Since you seem to be a (relative) newbie, you're probably better off going with a Wiznet-based solution for now, and maybe doing something with the ENC28J60 when you have more experience.

Is this a decent shield http://www.robotshop.com/arduino-ethernet-shield-4.html

• Based on the Wiznet W5100 ethernet chip • Provides standard RJ45 ethernet jack • Contains a number of informational LEDs • Includes micro-SD card slot and reset controller • Compatible with Arduino Duemilanove and Mega

As the guys above have mentioned, there are two methods of getting an arduino on the internet.

  1. An Ethernet or Wifi shield (imo wifi is too expensive to bother with unless it’s an absolute necessity)
  2. Using a serial link to a PC (server)

Using an Ethernet shield is probably the cheapest method and certainly uses the least amount of power. But if you already have a home server or want one (for more than just running an arduino) then that may be a more suitable solution.

As for ISP etc: you could ask your ISP for a static IP address and then buy a domain name (business grade broadband), but that will probably cost a fortune. The far more sensible approach is to use site like no-ip.com or dyndns.com.

• These sites will give you a free domain name and link that domain to your home IP (even if it dynamic). • Then you need to set your router up so it forwards port 80 requests to your server (arduino or PC)

Most ISPs will let you get away with this, some block port 80 (rare these days), but this can be overcome with a little bit of port forwarding. The only real concern is the ‘fair use policy’ that most ISPs have, but as long as you traffic isn’t too high (ie just you and your family just checking up on your site) then you shouldn’t have a problem.

hi, this is my first time posting here even though i've been using arduino for quite some time in the past. also i've been using the arduino ethernet shield for home automation, anyway, answering your questions..

1) yes, if you want to control something in your house over the internet, or locally you need the ethernet shield, it's quite simply to use, you just have to set up a configuration (ip address, mac address) then connect it to your router and you can access it by all the computers in your house, and with some port forwarding even the internet. I really recommend this shield before others, because of its simplicity. 2) No, the arduino ethernet shield will act as a server, for example, if you set up the ethernet shield by the ip address of http://192.168.1.100/, then you can access it by your computer typing the address in the browser bar. The shield will display a page with some data, as it is acting like a server. 3) Not quite, as i said before the shield will act as a server, the purpose of home webservers are generally for more complex tasks. 4) If you want to control the arduino over the internet, you should just check if your router has port forwarding.

About your application, yes you can do it with the ethernet shield, the one that you posted before it's fine, you just have to figure out how to detect if your dog lays on the couch, there are several ways to do this i can think of laser detection or pir, the output of that sensor should go to one of the arduino's input and it can be read as simple as:

client.print(analogRead(analogChannel));

with that data you can send a mail or something, ah, and it should be the same thing with the water gun lol, just setting it as an output

Is this a decent shield

Probably, but I have no personal experience to confirm/dispute that.

I have the Adafruit shields (also sold by robotshop, if you want to buy other stuff from them).

Advantages for the robotshop shield: lower profile (the Adafruit shield is a nuisance to stack on because the Wiznet module is so tall), and the SD card slot (the Adafruit shield can't share the SPI bus due to a bug in the Wiznet. It appears there's a fix for that on the robotshop board).

Advantages for the Adafruit: it's easy to wire the Wiznet reset to a digital pin to control resetting in software, which many have found useful. Also, it has the Arduino pins brought out to a separate set of holes. I found these useful for one project, where I needed to connect a small number of pins to sensors more reliably than the usual "solder wires to male PCB pins" method. Instead, I put polarized headers on the shield, which made it easy to make error-free connections.

So I can use my normal desktop as a webserver and then switch it back to a computer when I need it? How is this done, with software? Maybe I dont need to do this if I can use the Arduino as the server? Again I apoligize I have never programmed before and have no webdesign experience.

On your pc you can run the apache web server in the background and probably won't even notice it unless it is getting heavy traffic.

You guys have been a ton of help. I will go ahead and purchase an ethernet sheild today and hope you are still around when I struggle to get it up and running.

Thanks again. Mike

I will go ahead and purchase an ethernet sheild today and hope you are still around when I struggle to get it up and running.

I suggest you get the w5100 wiznet chip shield. It will probably save you a lot of time/effort over the cheap chip shield.

I was wondering if anyone could explain to me the diffrence between the ethernet shield/arduino combo and an IO Bridge. I have seen a lot of great home automation done with the IO Bridge, and it seems very simple to use. It also provides you with a way to simply create websites to monitor and run you automation. For someone who has very limited programming background this seems like a good introduction. I have not made up my mind on which direction I will go but it seems like the IO Bridge is easier to learn. What are the advantages to using an Arduino/Shield combo?

speemike: I was wondering if anyone could explain to me the diffrence between the ethernet shield/arduino combo and an IO Bridge.

Looks like IO Bridge costs $119 and you need to pay another $199 (or about $4/month) to use "Expression Builder" to program it? Looks like IO Bridge is primarily for environmental automation: light and humidity sensors. Ultrasonic range finders, etc. If that is what you want to do and someone is willing to pay for the expensive hardware and subscription service to avoid programming then IO Bridge would be a fine solution. If you want to automate something unusual like an art piece and you are willing to deal with programming to save s good deal of money then the Arduino might be a better choice. There are probably many cases where either would work.

The old forum has post concerning the IO bridge, the one below might be of interest.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272560163

As another option (sorry to re-post):

We're creating a free web-service that relays messages through a cloud server. We'll post more details soon, but the Arduino essentially authenticates and establishes an ongoing connection to the server.

It's great because it does not require any network configuration. No need to use a local static address, open up your firewall to setup port forwarding, remember your temporary IP address, configure Dynamic DNS, or pay an exorbitant rate for a static IP.

Check out the project: http://www.kickstarter.com/projects/916146896/customctrl?ref=category

customctrl: As another option (sorry to re-post):

We're creating a free web-service that relays messages through a cloud server. We'll post more details soon, but the Arduino essentially authenticates and establishes an ongoing connection to the server.

It's great because it does not require any network configuration. No need to use a local static address, open up your firewall to setup port forwarding, remember your temporary IP address, configure Dynamic DNS, or pay an exorbitant rate for a static IP.

Check out the project: http://www.kickstarter.com/projects/916146896/customctrl?ref=category

That's pretty much how the IO Bridge works. It connects to their server every few seconds and uploads status and checks for instructions. If you want to send it an instruction you connect to the server and post an instruction, if you want status you download it from their server. As long as the IO Bridge can access the internet and you can access the internet no other configuration is necessary. It supports DHCP so all you have to do is attach it to a network.

One of the variations CustomCTRL is bringing to Arduino is sustaining the connection to the server, so the results happen in a fraction of a second. When you think about the time it takes to load a webpage, it's still amazing to me that the data can be relayed so rapidly...

I have a code that work in the version 22 of the IDE
this code will display a site with options to turn on/off outputs, and show values of analog sernsors =)

//*******************************

#include <SPI.h>
#include <Ethernet.h>

/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox

The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/

**************************************************************
*  Edited by Haavard GJ to work in version 0021              *
*  Thanks to PaulS for the big help on getting this to work  *
**************************************************************
*/


 byte    mac[] =     { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
 byte    ip[] =      { 192, 168, 2, 110 };                     // ip in lan
 byte    gateway[] = { 192, 168, 2, 1 };                       // the IP of the router or acsesspoint
 byte    subnet[] =  { 255, 255, 255, 0 };                     //subnet mask (i dont think this is neccesary
 Server  server(80);                // server port (change this if you are having a local webserver else than the arduino)
 int     ledPin = 4;                // LED pin
 int     heatpin = 5;               // Heating *relay* (change this if you want)
 int     lightpin = 6;              // lights
 int     sensorPin = A0;            // analog in 0 for testing
 int     sensorValue = 0;           // integer for the analog sensor
 String  readString = String(30);   // string for fetching data from address
 boolean LEDON = false;             // LED status flag
 boolean HEATON = false;            // Heat status flag  (add more status flags if you need more outputs)
 boolean LIGHTON = false;           // lights *test* 

void setup()
{    
  Serial.begin(57600); //enable serial datada print
  Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet
  
  pinMode(ledPin, OUTPUT); //Set pin 4 to output
  pinMode(heatpin, OUTPUT);
  Serial.print("Starting server"); //for debugging
  
  sensorValue = analogRead(sensorPin); 
}

void loop(){

  Client client = server.available();  // Create a client connection
    if (client) {
      while (client.connected()) {
        if (client.available()) {

          char c = client.read();

        if (readString.length() < 30) { //read char by char HTTP request
          readString.concat(c); } //store characters to string
          
        Serial.print(c); //output chars to serial port for debugging
        



        if (c == '\n') { //if HTTP request has ended
        
          Serial.println("");
          Serial.println(readString); // print for debugging
          Serial.println("");
          int Le = readString.indexOf("L="); // led         here is a key component of where 
          int He = readString.indexOf("H="); // heat        the status is being read by the arduino
          int V = readString.indexOf("V"); // light
          Serial.print("L= position: ");
          Serial.println(Le);
          Serial.print("H= position: ");
          Serial.println(He);
          Serial.print("V= position: ");
          Serial.print(V);
          
          
          
          
          
          
          //lets check if LED should be lighted
          if (Le > 1){
          
          if (readString.substring(Le,(Le+3)) == "L=1") { //led has to be turned ON
              digitalWrite(ledPin, HIGH); // set the LED on
              Serial.println("ledpin paa"); // debugging
              LEDON = true; 
          }

          if (readString.substring(Le,(Le+3))== "L=0") {
            //led has to be turned OFF
            digitalWrite(ledPin, LOW); // set the LED OFF
            Serial.println("ledpin av"); //debugging
            LEDON = false; 
           }}
           
           if (He > 1){ 
             
          if (readString.substring(He,(He+3)) == "H=1") { //heat has to be turned ON
              digitalWrite(heatpin, HIGH); // set the heat on
              Serial.println("heatpin paa");//debug
              HEATON = true; 
          }

          if (readString.substring(He,(He+3)) == "H=0") {
            //heat has to be turned OFF
            digitalWrite(heatpin, LOW); // set the heat OFF
            Serial.println("heatpin av"); //debug
            HEATON = false; 
           }}
           
            if (V > 1){ 
             
          if (readString.substring(V,(V+3)) == "V=1") { //light has to be turned ON
              digitalWrite(lightpin, HIGH); // set the heat on
              Serial.println("lys paa pin 6");//debug
              LIGHTON = true; 
          }

          if (readString.substring(V,(V+3)) == "V=0") {
            //light has to be turned OFF
            digitalWrite(lightpin, LOW); // set the heat OFF
            Serial.println("lys av"); //debug
            LIGHTON = false; 
          }}
           


  client.println("HTTP/1.1 200 OK"); //output HTML data starting with standart header
  client.println("Content-Type: text/html");
  client.println();
  client.print  ("<body style=background-color:white>"); //set background to white

  // HTML Code

  client.println("<font color=’red’><h1>Arduino Remote control</font></h1>");//send first heading

  client.println("<font color=’blue’ size=’5?>Analog input 0: "); //print analog in to the browser
  
  
  sensorValue = analogRead(sensorPin);


  client.print(sensorValue);//Analog input. 
  Serial.print(sensorValue);

  client.println("
");//some space between lines

  //controlling led via checkbox
  client.println("<h1>LED control</h1>");

  // address will look like http://192.168.1.110/?L=1 when submited
  // this line will give the radiobuttons that give the input
  client.println("<form method=get name=LED> <input type='checkbox' name='L' value='1'>LED

<input type='checkbox' name='H' value='1'>HEAT

<input type='checkbox' name='V' value='1'>Light 
<input type=submit value=submit></form>");
  client.println("
");
  
  //printing LED status
  client.print("<font size=’4?>LED status: ");
  if (LEDON == true) {
     client.println("<font color='green' size='4'>ON</font>"); 
     Serial.print("led on pin 4");
   }
   else {
    client.println("<font color='red' size='4'>OFF</font>");
    Serial.println("Led off pin 4");
   }

  client.print("
");

 //printing LED status
  client.print("<font size=’4?>Heatpin status: ");
  if (HEATON == true) {
     client.println("<font color='green' size='4'>ON</font>"); 
     Serial.print("Heat on pin 5");
   }
   else {
    client.println("<font color='red' size='4'>OFF</font>");
    Serial.println("Heat off pin 5");
   }
   client.print("
");
   
     client.print("<font size=’4?>Light status: ");
  if (LIGHTON == true) {
     client.println("<font color='green' size='4'>ON</font>"); 
     Serial.print("light on pin 6");
   }
   else {
    client.println("<font color='red' size='4'>OFF</font>");
    Serial.println("light off pin 6");
   }



  client.println("</body></html>");


readString=""; //clearing string for next read

client.stop(); //stopping client

Serial.println("stopped client"); // for debugging

}}}}}

speemike: Is this a decent shield http://www.robotshop.com/arduino-ethernet-shield-4.html

Only if you also need storage, else why spending more?

Ok so I am going to wait until Arduino puts out their Ethernet Shield again, and then buy it. I am still somewhat confused as to which code goes where? This is the way I think it works, let me know if I am wrong. PHP or Processing code goes on the Ethernet Shield, this acts like a server and plugs into my router. Arduino code goes on the Arduino.

But if you do not have an ethernet shield I can load the PHP code or Processing code into a program called Apache on my desktop which simulates a server.

What is the differences between Processing and PHP?

To create a webpage with buttons that will work on my blackberry to trigger LED's I need to write HTML code? Which software do I use to create buttons on a website, or can it be done in PHP or processing? I see a lot of people using MySQL in there projects, what is that for?