0% found this document useful (0 votes)
195 views

Arduino Internet Control Using The Arduino Ethernet Shield

This document describes how to control relays remotely over the Internet using an Arduino board and Ethernet shield. The hardware used includes an Arduino Uno, Ethernet shield, and 4-channel relay module. Software requirements involve using the Teleduino service to send commands via URLs to control the relays. An example Arduino sketch is provided to test the hardware connections and relay control. Overall, the document presents an inexpensive and easy way to remotely control relays online with open-source Arduino hardware and software.

Uploaded by

Benjamin Dover
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views

Arduino Internet Control Using The Arduino Ethernet Shield

This document describes how to control relays remotely over the Internet using an Arduino board and Ethernet shield. The hardware used includes an Arduino Uno, Ethernet shield, and 4-channel relay module. Software requirements involve using the Teleduino service to send commands via URLs to control the relays. An example Arduino sketch is provided to test the hardware connections and relay control. Overall, the document presents an inexpensive and easy way to remotely control relays online with open-source Arduino hardware and software.

Uploaded by

Benjamin Dover
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Control relays over the

Internet with Arduino


4URNINGITEMSONANDOFFREMOTELYVIATHE)NTERNETHASGENERALLY
BEENACOMPLEXANDEXPENSIVETASKDUETOTHEHARDWAREAND
KNOWLEDGEREQUIREDqNOTANYMORE(EREWESHOWHOWEASYAND
INEXPENSIVEITCANBETOCONTROLFOURORMORERELAYSOVERTHE)NTERNET
USINGOPEN SOURCE!RDUINO BASEDHARDWARE
By JOHN BOXALL

&

"

'

'

&

'

&

TS NOT DIFFICULT to remotely control relays via the


)NTERNET)NTHISARTICLE WEmLLRSTLOOKATTHEHARDWARE
REQUIRED THENEXPLAINTHESOFTWAREANDNETWORKREQUIREMENTS !FTER THAT  WEmLL LOOK AT HOW COMMANDS ARE SENT
over the Internet using a web browser to control the relays.
)F YOU ARE UNFAMILIAR WITH THE !RDUINO ENVIRONMENT 
PLEASEVISITTHEDEVICEmSHOMEPAGEAT

#ONNECTING THE RELAY MODULE TO THE !RDUINO BOARD IS


VERYSIMPLE

The hardware
4HEHEARTOFTHESYSTEMISAN!RDUINO5NO STYLEBOARDWITH
AN%THERNETSHIELD)NTHISCASE WEHAVEUSEDA&REETRONICS
%THER4ENBOARDWHICHCONVENIENTLYCOMBINESBOTHINTOA
SINGLEUNIT THEREBYSAVINGSPACEANDMONEYqSEE&IG
4HE %THER4EN BOARD CAN CONTROL UP TO FOUR RELAYS VIA
A&REETRONICS2%,!9 CHANNELRELAYCONTROLMODULEq
SEE&IG4HISMODULEINTERFACESDIRECTLYTOTHE%THER4EN
!RDUINOBOARDANDUSES&%4STOSWITCHTHERELAYCOILS)T
ALSOINCLUDESREVERSE CONNECTEDPOWERDIODESTOSUPPRESS
BACK %-&PULSESWHENTHERELAYSARETURNEDOFF

.OTETHATWHENUSINGAN%THERNET ENABLED!RDUINOBOARD 
DIGITALPINS AREUSEDBYTHE%THERNETINTERFACEAND
CANmTBEUSEDFOROTHERPURPOSES!NDINTHECASEOFTHE
%THER4ENBOARD DIGITALPINISUSEDFORTHEMICRO3$CARD
.OTETHAT FORTHISPROJECT WEDONmTUSEDIGITALPINEITHER
ANDWEmLLEXPLAINTHEREASONFORTHISSHORTLY
4HENEXTCONSIDERATIONISTHEPOWERSUPPLYFORTHERELAY
COILS!LTHOUGHTHEREISA6POWERSUPPLYAVAILABLEFROM
THE!RDUINOBOARD ITmSUNABLETOSUPPLYENOUGHCURRENTTO
DRIVEMOSTCONVENTIONALRELAYCOILS7HATmSMORE ITCANNOTBEUSEDTOPOWERRELAYSWITH6ORHIGHER COILS)N

Input 1 to Arduino D2
Input 2 to Arduino D3
Input 3 to Arduino D5
Input 4 to Arduino D6
Logic GND to Arduino GND

either case, you will have to connect an external DC power


supply with the required ratings to the RELAY4 boards
power terminals (bottom-left of Fig.3).
On the other hand, if you can keep the current draw
under 150mA and are using solid-state 5V relays with very
low switching currents, the on-board Arduino 5V supply
will be enough.
With a 5V supply, the RELAY4 board itself draws around
13mA with all LEDs on. Add four relays drawing just
20mA each and you can comfortably power the lot from
the Arduino. In that case, connect the positive pin from the
RELAY4 power terminal to the Arduino +5V pin.

>

Testing
You can then test the connections to the RELAY4 board
with a simple Arduino sketch (software program) that
turns the outputs on and off as indicated by the on-board
RELAY4 LEDs. Once your hardware has been connected,
enter and upload the following sketch using the Arduino
IDE (Integrated Development Environment):

"

To identify an individual Arduino board to the Teleduino service, we use a unique key in the form of a long
hexadecimal number. This key is issued by the Teleduino
service and is inserted into the Arduino sketch and also
into the commands issued to control the board.
To generate a key, simply go to
ANDCOMPLETETHEREQUIREDELDS!
short time later, your key will arrive via email remember
to store this for later retrieval. It will be a long string of
characters, eg, 18F5F4749B058F952ABCDEF8534B2BBF.
The next step is to download and install the Teleduino
Arduino library into the IDE. The latest library can be
Extract
found at:
the library folder and copy it to the arduino-1.0.1/libraries
folder in your IDE installation. If your IDE is running, you
will need to restart it in order to use the library.
You now have to prepare the Teleduino sketch for the
Arduino board. This sketch connects the Arduino to the
1

<

<

<

Software and network requirements


To control our Arduino over the Internet, we use a free
online service called Teleduino. It allows us to send commands to an Arduino board (via the Internet) using simple
commands in the form of URLs similar to that used to refer
to a web page.
9OUCANNDOUTMOREATTHE4ELEDUINOWEBSITEAT


At this stage, all four LEDs should be blinking on and off


at 2Hz. If not, check the wiring between the two boards,
including the GND line.

void loop()
{
PORTD = B01101100; // set D2, D3, D5, D6 HIGH
delay(250);
PORTD = B00000000; // set D2, D3, D5, D6 LOW
delay(250);
}

Teleduino server and also executes received commands


via the service. The sketch is included with the library,
so in the IDE select File > Examples > Teleduino328 >
TeleduinoEthernetClientProxy.
Before uploading the sketch, the unique Teleduino key
needs to be inserted so the Arduino can identify itself to
the service. To do this, go to
, enter your Teleduino key into
THEELDANDCLICKl'ENERATE#ODEm4HISWILLAPPEARASAN
array in Arduino format as shown, for example, in Fig.4.
That done, scan through the Arduino sketch currently
loaded in the IDE, locate the same byte variable (it should
start on line 36) and replace the array full of zeros with
your Teleduino key array see Fig.5 (for example).
/NCEYOUHAVEMODIEDTHESKETCHASABOVE UPLOADITTO
your Arduino as normal. You should also save the sketch
so you dont need to repeat the key-insertion process in
the future. Note that if you are going to control multiple
Arduino boards, you will need multiple Teleduino keys. Just
remember to keep track of the key uploaded to each board.
The next step is to test that the Arduino is connecting to
the Teleduino service by monitoring the connection status.
This can be done using an LED indicator connected via a
560 resistor between the Arduinos D8 pin and GND, as
shown in Fig.6.
Once the indicator LED is in place, connect the Arduino
to your router via a network cable, apply power and watch
the LED. After a few moments, the LED will start blinking
to indicate the status of the connection to the Teleduino
service.
At the time of writing, the following blink parameters
are used:
1

void setup()
{
DDRD = B11111111; // set PORTD (digital 7~0) to outputs
}

'

&

'

&

Reproduced by arrangement
with SILICON CHIP
MAGAZINE
www.siliconchip.com.au

(Vin)

(5V)
POWER

(3.3V)

SCK

(RST)
(AREF)

MISO
MOSI
SS
(D9)
(D8)

ARDUINO
ETHERNET
SHIELD

DIGITAL INPUTS/OUTPUTS

(D7)

(A0)

ANALOG INPUTS

(A1)
(A2)
(A3)
(A4)

PWM

(A5)

(D6)

PWM

(D5)

PWM

R1
560

(D3)

1 blink:
2 blinks:
3 blinks:
4 blinks:
5 blinks:
6 blinks:
10 blinks:

(D1)

Tx

(D0)

Rx

There are three parameters you need to enter into this


PAGE 4HE RST IS YOUR 4ELEDUINO KEY q SIMPLY REPLACE
999999 with your key. The next is the Arduino digital pin
TOCONTROLqREPLACEl8mWITHTHEPINNUMBER!NDNALLY 
TOTURNTHEPINONOROFF REPLACE9WITHAlmFOROFFORA
lmFORON
&OREXAMPLE TOTURNONRELAY YOUWOULDUSE

initialising
starting network connection
connecting to the Teleduino server
authentication successful
session already exists for supplied key
invalid or unauthorised key
connection dropped

Default relay settings


4HE NAL STEP IN SETTING UP THE 4ELEDUINO SERVICE IS TO
decide what the default settings will be for each of the
relays. These are the settings that the relays revert to when
the Arduino board is turned on or reset, loses the Internet
connection or the network cable is removed.
You can set the defaults after your Arduino has connected
to Teleduino by browsing to
After entering your Teleduino key,
a large selection of options will be displayed. Scroll down
to the Pins section (see Fig.7) and change the mode of the
Arduino pins youre using to OUTPUT. Then, depending
P

Controlling the RELAY4 module


4O CONTROL THE 2%,!9 MODULE  RST LAUNCH YOUR WEB
browser (on a computer, smartphone or tablet). You can
then control the Arduinos digital pins and thus the relays
by going to

It is normal for the LED to work its way up from one


to four blinks. After the connection and authentication is
SUCCESSFUL THE,%$WILLTHENBLINKVERYBRIEYEVERY
SECONDSORSO4HISSIGNIESTHATALLISWELL
)F YOUR ,%$ SHOWS VE BLINKS  JUST RESET THE !RDUINO
board. If your LED shows six blinks, check your Teleduino
key in the control sketch and re-upload it to the Arduino.
!NDNALLY IFITBLINKSTIMES THE)NTERNETCONNECTION
has dropped out.
Although the above procedure may seem somewhat tedious, it is necessary to establish that everything is working
correctly. Once youve done that, the status LED can be
removed if desired, but we suggest keeping it to aid troubleshooting if you strike problems in the future.

on your needs, you can set the default relay status with
the value parameter.

l LED1

(D2)

PWM

SS

(GND)

4OTURNITOFFAGAIN SIMPLYCHANGETHENALlmTOlm
9OUMAYNDITCONVENIENTTOBOOKMARKTHEVARIOUS52,S
to make sending commands much easier. Furthermore, the
can
use of URL-shortening services such as
reduce their length to more manageable sizes.
By checking the status LEDs on the RELAY4 board, you
can test the pin control without needing to wire up your
ENTIREPROJECTATTHESTART!LSO WHENYOUSENDACOMMAND 
the Teleduino server will return a message if the action has
been successful or not. If the command worked, an output
similar to the following will appear in the web page:
B

{"status":200,"message":"OK","response":{"result":1,"time":
0.2338559627533,"values":[]}}

Conversely, if it was not successful, you will see:


{"status":403,"message":"Key is offline or invalid.","response":[]}

This tells you that the Arduino has lost connection to


the Teleduino servers.
Conclusion
Once you have run through the set-up procedure, controlling the relays remotely is quite simple. If you need to
control more relays, either add another RELAY4 board or
check out the Freetronics RELAY8 board.
Finally, the Teleduino service allows web-based control
OFMUCHMORETHANYOUR!RDUINOmSDIGITALOUTPUTSqREFER
to
for more information.
B

You might also like