Go Down

Topic: Ethernet relay project (Read 7438 times) previous topic - next topic

indoor

Hello,

i'm new in arduino world. I would like to start my first project using arduino, but before I buy arduino boards I would like to find out some things, I hope some one will help me.

So the questions about arduino:
1) What kind of arduiono bords should I buy to create Ethernet controlled relay projet ? The thing I found out already that I should buy Arduino Ethernet Shield, but what kind of main board is compatible with Arduino Ethernet Shield?
2) Is there any VB samples for arduino control over ethernet ?
3) What kind of relay boards is comatible with arduino ? I would like to use some factory boards.

I will wait for answer. Thanks.

Jantje

indoor
Welcome to arduino
to answer your questions:
Quote
1) What kind of arduiono bords should I buy to create Ethernet controlled relay projet ? The thing I found out already that I should buy Arduino Ethernet Shield, but what kind of main board is compatible with Arduino Ethernet Shield?

You can add the ethernet shield to all boards that have the headers. That is the uno, mega 256, mega ADK, but not the lilpad, or fio.
Next to having a ethernet shield you can also buy the Aduino ethernet. And there are plenty of clones. See this page on the avilable official hardware http://arduino.cc/en/Main/Hardware
Quote
2) Is there any VB samples for arduino control over ethernet ?

There is no VB with arduino. Code is written in a C C++ like language.

Quote
3) What kind of relay boards is comatible with arduino ? I would like to use some factory boards.

I can't help you with this one.

Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

indoor

Thanks for reply.

I decided to buy Arduino Mega and Arduino Ethernet Shield.

C++ is OK for me, but there I have another questions:

1) Are there any samples/documentation how to control arduiono over ethernet from web page or from Visual Studio ?
2) How to Drive AC relays with Arduino ?



Hello,

did you install the arduino IDE on your computer? This is necessary to write code and to transport it to your arduino. And it is also necessary to learn how the whole thing works. With the IDE come some ethernet examples. Additionally google for webduino.

Best regards

Elektrix
My blog about arduino and Linux themes:
http://heliosoph.mit-links.info/

Si

Here is some example code that will help you turn pins on and of from your browser.

Taken from my book: 'Programming Arduino: Getting Started with Sketches'

Code: [Select]

// sketch 10-02 Internet Pins

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

// MAC address just has to be unique. This should work
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// The IP address will be dependent on your local network:
byte ip[] = { 192, 168, 1, 30 };
EthernetServer server(80);

int numPins = 5;
int pins[] = {3, 4, 5, 6, 7};
int pinState[] = {0, 0, 0, 0, 0};
char line1[100];

void setup()
{
  for (int i = 0; i < numPins; i++)
  {
     pinMode(pins[i], OUTPUT);
  }
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  EthernetClient client = server.available();
  if (client)
  {
    while (client.connected())
    {
      readHeader(client);
      if (! pageNameIs("/"))
      {
        client.stop(); 
        return;
      }
      client.println("HTTP/1.1 200 OK");
      client.println("Content-Type: text/html");
      client.println();

      // send the body
      client.println("<html><body>");
      client.println("<h1>Output Pins</h1>");
      client.println("<form method='GET'>"); 
      setValuesFromParams();
      setPinStates();
      for (int i = 0; i < numPins; i++)
      {
         writeHTMLforPin(client, i);
      }
      client.println("<input type='submit' value='Update'/>");
      client.println("</form>");
      client.println("</body></html>");

      client.stop();           
    }
  }
}

void writeHTMLforPin(EthernetClient client, int i)
{
  client.print("<p>Pin ");
  client.print(pins[i]); 
  client.print("<select name='");
  client.print(i);
  client.println("'>");
  client.print("<option value='0'");
  if (pinState[i] == 0)
  {
    client.print(" selected");
  }
  client.println(">Off</option>");
  client.print("<option value='1'");
  if (pinState[i] == 1)
  {
    client.print(" selected");
  }
  client.println(">On</option>");
  client.println("</select></p>"); 
}

void setPinStates()
{
  for (int i = 0; i < numPins; i++)
  {
     digitalWrite(pins[i], pinState[i]);
  }
}

void setValuesFromParams()
{
  for (int i = 0; i < numPins; i++)
  {
    pinState[i] = valueOfParam(i + '0');
  }
}

void readHeader(EthernetClient client)
{
  // read first line of header
  char ch;
  int i = 0;
  while (ch != '\n')
  {
    if (client.available())
    {
      ch = client.read();
      line1[i] = ch;
      i ++;
    }
  }
  line1[i] = '\0';
  Serial.println(line1);
}

boolean pageNameIs(char* name)
{
   // page name starts at char pos 4
   // ends with space
   int i = 4;
   char ch = line1[i];
   while (ch != ' ' && ch != '\n' && ch != '?')
   {
     if (name[i-4] != line1[i])
     {
       return false;
     }
     i++;
     ch = line1[i];
   }
   return true;
}

int valueOfParam(char param)
{
  for (int i = 0; i < strlen(line1); i++)
  {
    if (line1[i] == param && line1[i+1] == '=')
    {
      return (line1[i+2] - '0');
    }
  }
  return 0;
}
--
My New Arduino Book: http://www.arduinobook.com

jdmaag

works great! But I can not access through my phones data network. Any suggestions?

Arrch


works great! But I can not access through my phones data network. Any suggestions?


Get a static IP, forward port 80 to your Arduino and hope that your ISP is not blocking said port.

For furture reference, you're better off posting full descriptions of your project in the "Project Guidance" section, if you want more help; this sub-forum isn't nearly as active as that one.

FaTaL

Hey guys... This is a very nice piece of code. I run it locally on my machine and while the LED works properly, the client side of the code isn't working and always says "connection failed". That means that I can't read the state of the LED, right? What am I possibly doing wrong? Can I expand the code for 8 on-off buttons? Any help would be greatly appreciated. Have a nice day :)

jamlol


Hey guys... This is a very nice piece of code. I run it locally on my machine and while the LED works properly, the client side of the code isn't working and always says "connection failed". That means that I can't read the state of the LED, right? What am I possibly doing wrong? Can I expand the code for 8 on-off buttons? Any help would be greatly appreciated. Have a nice day :)


You need to set the port in your code i.e.:

EthernetServer server(54321);

After doing this you need to forward port 54321 to your arduino device on your router/modem.  After doing this you can connect remotely by going to http://yourexternalIP:54321

Hope this helps.


FaTaL

No... My problem is when I have 2 leds on for example, and then I try to hit the 192.168.1.30 again in the URL bar. All the leds turn off again. I see that there is a void setValuesFromParams() function but doesn't seem to work properly... That means that if I have 5 lights on for two hours for example, and then try to open the browser and hit the ip, the lights will turn off, regardless of their state at the time :( Any help would be appreciated. Thanks

Go Up