Hardware Reference
In-Depth Information
Controlling the relay from anywhere
In the last section of this chapter, we are going to take another approach. So far, we have a
server running on our Arduino board, which can receive commands from any device on
your local network. However, this is not convenient if you want to control a device from
anywhere in the world. For example, you want to activate a lamp in your home at given in-
tervals when you are away from your home.
To do so, we are going to use the Teleduino service, which allows you to do exactly that.
The Arduino Ethernet shield will be constantly connected to this service, so you can trans-
mit commands to the board from anywhere in the world if you have an Internet connection.
We are going to build a new sketch for the Arduino board and then adapt the interface ac-
cordingly, so you can control the relay from anywhere in the world right from your web
browser.
You first need to include the required libraries:
#include <EEPROM.h>
#include <Servo.h>
#include <Wire.h>
#include <Teleduino328.h>
#include <SPI.h>
#include <Ethernet.h>
Then you need to define the MAC address of your Ethernet shield:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xFE, 0x40 };
Then, define a lot of parameters for the Teleduino service. As we will use DHCP to get an
IP address, you don't need to change anything in the following code:
IPAddress deviceIp(192, 168, 1, 100); // Only if useDhcp is
false
IPAddress gatewayIp(192, 168, 1, 1); // Only if useDhcp is
false
IPAddress dnsIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress subnet(255, 255, 255, 0); // Only if useDhcp is
false
IPAddress serverIp(173, 230, 152, 173); // Only if useDns is
Search WWH ::




Custom Search