Instructables

Ethernet Switching - with Arduino

Picture of Ethernet Switching - with Arduino
Aim:

Switch relays from the ethernet or the internet, using your mobile, tablet or computer with a nice graphical user interface.

Update V4.06
Please read the below steps to Step 2 if you are viewing this article for the first time.
Please go to step 3 for the latest revision which is V4.06
A user modified version with logon option is placed in step 5 for easy download.

Material:

    * Arduino MEGA 2560
    * Arduino Ethernet Shield
    * Relay board
    * RJ45 cable


Tools:

    * Arduino Software version 1.0.1 (downloadable from Arduino Website )
    * A / B USB cable


Infrastructure:

    * Internet access with fixed IP for Arduino
    * Access to your router to share the port for internet access
    * Testing devices - your pc, mobile etc


Disclaimer:

    * This project was tested with iPhone 3GS, iPad 2 and MacBook Pro running Safari and PC running Safari, Firefox, Opera and IE.
    * This project was created on October 2012 with the mentioned material.
    * Binary sketch size: 22,322 bytes (of a 258,048 byte maximum).
    * This sketch does not offer any sort of authentification, therefore if required to be used from outside the network or from the internet, I suggest to configure your network to connect trough VPN. Nowadays many routers and smartphones support VPN.



 
Remove these adsRemove these ads by Signing Up

Step 1: Ethernet Switching - with Arduino - Description

Picture of Ethernet Switching - with Arduino - Description
iPadScreenshot.png
relay board.JPG
iPhone3GSPortrait.png
Description:

    * With this project, I had not included any images, or links to images from the internet. It only make use of CSS3 and HTML5.
    * The simulated LEDs are created from CSS3 code.
    * Some browsers does not make full use of CSS3 and HTML5. Thus I suggest using Safari.
1-40 of 62Next »
la3bna26 days ago

This is a really good project, Im tring to get this working on an Nano and a WIZ550io module, I have updated libs. Examples work but not this. I have changed the MAC (the wiz550 has a mac sticker on it).

Changed araound with pins and removed some of them.

tcvella (author)  la3bna26 days ago

Hi la3bna,

As per my instructions, I had tested this with the Arduino MEGA. If you read older posts you will find out that users had issues with the A. UNO probably due to low RAM size. So I am guessing you are encountering a similar issue with the Nano.

In other words to use the NANO you should compromise and leave some code out.

la3bna tcvella26 days ago

Ok I have trimmed it down some. I will try to leave out part of the HTML code and see if I get it running. The main reason I was looking at this is becase of the way it looks. If I dont get it working I will have to buy a MEGA ;).

Thanks replaying so fast

la3bna la3bna25 days ago

I saw that the issue would be resolved by commenting the CCS stuff. I am going to test that and maybe hav a ccs file on a network computer and poinit the html style ref to it. hoping that will work.

la3bna la3bna25 days ago

The browser only tried to download from the server address. Nothing is displayed

pgupta3125 days ago

Hi, nice project wanted to make one for me but I have uno board with w5100 shield. This program is not working on Uno. Can you help. I have tried other 8 relay program and it was working fine but I want to make this one with temperature sensor

.

iwrk4dedpr1 month ago

Thanks for posting all this great information. I have just bought 2 arduino controlers ( 1 for me and one for my 12 year old daughter ). Years ago my interest was in building smart homes. While the concept is out there presently I'd sure like to see my daughter find ways to make intelligent homes more reasonable and efficient. I think at my age my usefulness in this endeavor will be limited.

What you have done here is exactly where I'd like to get to ( and quickly ) I can't do much in a house that's all ready built but I'd like to design some system for new built homes where wiring can be done in a proper fashion.

Again thanks for demonstrating and, more importantly, sharing your knowledge with strangers.

tcvella (author)  iwrk4dedpr1 month ago
Thanks for your comments. I appreciate that you like the project and are making use of it.
teqmo tcvella1 month ago

This is a great project just started picking it up but the on and off are backwards for me would you mind giving some advice?

lights on the webpage come on when the relay lights go off.

jlout1 month ago

Hello,

Can this tutorial be used for RF transmitter as well?

So every button sends a code like that "mySwitch.switchOn("11111", "00010");" in order to turn on or off RF plugs.

I have a working RF transmitter GUI which is rather lame + it does not work properly under mobile devices.

tcvella (author)  jlout1 month ago
​I guess so. It depends on what your transmitter is, and does. If your transmitter can be switched by an arduino, then instead of sending the port to go high or low, you will send the command you need.
jlout tcvella1 month ago

I have a 433Mhz transmitter and i have successfully tested it with RCSwitch webserver.

The only problem i have is that it has a very simplistic UI and it does not work properly with mobile devices. I can only turn on and off 1 or 2 times a power outlet until it stops working (but it is working properly from firefox/chrome etc from a desktop browser).

The commands i'm using look like this:

void processCommand(char* command) {
if (strcmp(command, "1-on") == 0) {
mySwitch.switchOn("11111", "00010");
} else if (strcmp(command, "1-off") == 0) {
mySwitch.switchOff("11111", "00010");

and so on.

Could you elaborate on the code changes so it can work with RF transmitter?

It would be really cool since you only need some RF outlets (i currently have 8).

Thank you

ShalvaN2 months ago

Hi there,

Great project i already set it up, but i have few questions:

1) is there a possibility to change NTC to DS18B20 (lets say 2 of them)?

2) can we add DHT22 to check also humidity?

the web page could look like this

temp in (dht22 - nr1)

humidity in (dht22 - nr1)

temp out (dht22-nr2)

humidity out (dht22-nr2)

temp something 1 (DS18B20)

temp something 2 (DS18B20)

and at last all of them could be programable ( so i can tourn them visible or invisible, change the names)

kitjawat4 months ago

When I'm browsing from a computer on the same LAN as the Arduino, everything works fine. But when I'm browsing from a remote location via my VPN, the page waiting and timeout from the Arduino Ethernet Shield web server and some time it work fine.

do you know how to fix it?

sidbin5 months ago

Problem will be at UNO with RAM (2kB RAM vs. MEGA 8KB).

After deleting the css page arduino works.
erojs7 months ago
First of all it's nice to hear that someone else is interested in pulse solution.
I have to warn everyone that for my compilation I used original 4.06 code and added DS18B20 and login parts adjusted from drewpalmer04 code.

Please note, when used with login function, the device hangs very rapidly! sometimes after 24h.
maybe it is a millis issue, however without the login elements the code works like a charm.
Could also be issue with string.h usage and note that drewpalmer04 login solution uses also the password part to let you in, for example if your password is 'password123', if you input 'password12345' it will also work.

In my project I used
4 relays in pulse mode
4 relays in on/off mode
5 Dallas DS18B20 temperature sensors
temperature sensors data is sent to ksduino.org for data logging. (free service like Pachube, Cosm etc. )
For pulse effect the function triggerPinPulse is used, where delay has to be set, if need, change 250 milliseconds to 2000 or 3000. this function basically changes the value to previous state after set delay.

I had power issues too, if I connected 5V DC adapter to Mega, not all of the relays worked.
Actually No4 didn't work, and if login function is used No8 (last) also had different state than No5, No6, No7. Without login No5, No6, No7, and No8 works all the same.
I solved my project by connecting DC 9V power adapter and USB cable connected to 5V 1A power adapter (my arduino is not connected to PC, when it operates).
After power loss it hangs, but works fine again after reset button pressed.

Here is the file:
http://failiem.lv/u/rnqpjmi
I will be happy to hear your comments and experience, as I would be happy to find bugs.
erojs8 months ago
The project is indeed great!

I tied to adjust ir for my needs, but somewhere I did something wrong.

I would really appreciate some advices.

The first thing I wanted to implement were the simple trigger buttons i needed along with on/off switches. I got it by modifying triggerPin function, I just created new one on base of it and added few lines to switch button back:

digitalWrite(pin, HIGH);

delay(250);

digitalWrite(pin, LOW);

Basically it works, both buttons does the same function.

The only problem is that if the new trigger relays after reconnecting power I want to remain off after disconnecting/connecting power, on/off switches will be on, and I can't get both off.



Maybe someone has solution?



Another thing I wanted to implement is multiple DS18B20 sensors to be read and displayed. I tried both parastatic and average mode, but no success.

Every time something goes down, either IP is 0.0.0.0 and temperatures 0.0, or mostly temperature is constantly 85.
Only once I managed to get both temperature + switches, but after reconnecting the power, temperature was back to 85.
Does someone has experience with DS18B20?

Thank you.

It seems you managed to send only a pulse to your board?, i can't get this to work, i don't want it to stay on, just to get on for a second or two.
Carlos, me puedes ayudar?, necesito que el botón mande un pulso de unos 2 segundos al relay y se cierre enseguida, cuando usas para puertas o garages el mantener prendido provoca problemas.

Estoy feliz con este proyecto, mil gracias.

Puedes agregar la autenticación en tu versión original?, la que pusieron aquí no compila bonito.
I beleive you don't speak Spanish, I thought you did since you have a latin name, just in case I will ask in English.

I need some of the relays to send a pulse (2-3 seconds) and then turn off, instead of staying on or off, since for garage door openers or 12v driven front doors. How can I do this.

Also, could you include the authentication and instruccions in your comments, I tried the one some user posted here but It won't compile, I beleive is made for the UNO and I have the Mega as you suggested

I'm really happy with this project, thanks alot
Perdón, Claudio. Me equivoqué de nombre
rdomarkas8 months ago
hello, i wanted to ask a question, is it possible to reach my router via vpn and then arduino server (arduino ethernet shield) using smartphone? do i need to use some apps for that aswell? thanks alot :)!!
jaquesdev8 months ago
Hi There

I would love to use this but, I would need to use the actual wall buttons to switch the lights on and off as well and not just via the website has anyone mange to get this to work?
dede449 months ago
"All on/off buttons" doesn't works for me, it disables only the first pin.
I tested with 3 outputs (pin 38, 36 and 34)

the URL is that : http://myip/?L38L36L34
It only sets pin 38 low, not 36 and 34.

do you have an idea for fixing that ?
Thanks a lot for sharing your work
DISKJOHN9 months ago
Good morning I want to know the access to the display options for the switches on and off is done by entering the ip or is there some password first;
squid5169 months ago
have tried his on arduino uno but seems the code for css are not working in arduino uno...is there any way to solve it?
HansiEdi squid5169 months ago
Hello squid516,
you can purchase an Arduino Mega clone from China ~10 USD (Shipping free)

bye Hans
HansiEdi9 months ago
Hello tcvalla,

No-IP function in your EthernetSwitch

I have found the follow:
http://forum.arduino.cc//index.php?PHPSESSID=bld0709qub18o9fi4d54mn3pb4&topic=95456.15

It is very great and works fine :-)
Can you please integrate it to your EthernetSwitch?

It is a perfect combination :-)

bye Hans
rmvandek10 months ago
Great project. But also i have problems when downloaded to an UNO or the new Ethernet board. On the Mega I have it working well even when downscale it in the sofware to only 2 channels (uno can handle the amount of channels). Then change the boards and upload on an UNO, gives no reaction on the set IP adres. Compiling and sending is no problem after that I see only a continu stream of strange caracters (Aooo) in the serieel monitor. The UNO and Ethernet boards working well with other simpler ethernet switch software so it have to be something to do with this software. Anyone ideas what the difference can be. Tried a lot of thinks but all without positive results.
Acidjazz541 year ago
Claudio,

Great post and the interface is very nice. I'm wondering if you have any idea how I can convert this to work with the EtherCard library? I have a board that I made which uses the ENC28J60 chip instead of the WIZnet chip. Any help would be greatly appreciated.

Obrigado,

David Vaughn
asayegh1 year ago
i upload the same code on arduino but its not work ??
can you help me?
HansiEdi1 year ago
Hello and thanks.
I bought an Arduino MEGA and your project works.
tcvella, good afternoon.

Congratulations, beautiful and functional.
A doubt.
What would need to change the code to write the name of each button?
For example, where is Switch ON - write pin2 Light Room or any other room in the house.
You can?

Thank you and congratulations.

Alexandre / Sao Paulo / Brazil
tcvella (author)  Alexandre Yoshikawa1 year ago
This have been done on the latest versions. So check it out.
tcvella (author)  Alexandre Yoshikawa1 year ago
Hi Alexandre,

First thanks for your comments.
Currently the program does not have that option.
However that could be easily done by creating an array of the required names. Then instead of calling the var number to be displayed, you will call the var number of that array you have created.
Hope that this helped a bit.

Claudio Vella
HansiEdi1 year ago
Hi, I have the Arduino UNO as others, but unfortunately it does not work the sketch.
Can you write an update or do you need an Arduino Uno to eliminate the problem?

bye
tcvella (author)  HansiEdi1 year ago
Hi HansEdi,
I had tested the sketch with Arduino Mega, I don t have an Arduino uno to test the sketch on. It depends on the errors it is giving up. There are some things to inestigate. 1) Check the pinouts and arrange the sketch as required. 2) Check if you are having any missing library. These are the first points to check. Of course if having an Arduino Uno will help into solving such issue as one can tackle the issue.
Ya I have an UNO and can't seem to get it to work, but will keep trying.
Removed external links.

See page 5 for the login option for this great looking layout.

Also, The authentication option has 16 relay control... :)
HansiEdi1 year ago
Hallo, ich habe wie andere das Arduino UNO, aber leider funktioniert damit der Sketch nicht.
Können sie ein Update schreiben oder benötigen Sie ein Arduino Uno um das Problem zu beseitigen?
bye
1-40 of 62Next »