Arduino Control via a Web Service with Teleduino

 by nathanknz
Featured
Convert your Arduino into a sofisticated web control platform using Teleduino.

Teleduino is both a product and a service. Once the Teleduino sketch has been loaded on your Arduino (the 'product'), it then connects to the Teleduino server awaiting your instruction from anywhere in the world via the internet (the 'service').

Typically there are no firewall changes required, and if your network supports DHCP then no network configuration is needed on the device. Easy!

The Teleduino platform allows you to perform the following with your Arduino, all via the internet:
  • Reset, ping, get version, get uptime, get free memory.
  • Define pin modes, set digital outputs, set analog outputs, read digital inputs, read analog inputs, or read all inputs with a single API call.
  • Define up to 2 'banks' (4 for the Mega) of shift registers. Each 'bank' can contain up to 32 cascaded shift registers, giving a total of 512 digital outputs (1024 for the Mega).
  • Shift register outputs can be set, or merged, and expire times can be set on merges (you could set an output(s) high for X number of milliseconds).
  • Define, and read and write from serial port (4 for the Mega).
  • Read and write from EEPROM.
  • Define and position up to 6 servos (48 for the Mega).
  • Set preset values for the above functions, which get set during boot. Preset values are stored in the first 178 bytes of the EEPROM (413 for the Mega).

Just imagine what you can do. The possibilities are endless. What makes it even better? The process is quick and easy.

This tutorial will guide you through creating a Status LED for your device, then obtaining and uploading the Teleduino library/sketch to your ethernet enabled Arduino Uno (or equivalent).

To complete this tutorial you need:
  • Arduino Uno / Mega (or equivalent)
  • Ethernet Sheild (Wiznet based)
  • LED
  • 1K Resistor (or similar)

This is our first tutorial and will be adding neat project tutorials for achieving specific tasks.

If you get stuck on any of the steps, or if you feel that there is a step that could be explained better, please leave a comment so that we can improve things.

Enjoy!
 
Remove these adsRemove these ads by Signing Up

Step 1: Obtain Unique API Key

In order to uniquely identify your device on the Teleduino server, you need to obtain a unique API key.

This API key needs to be loaded into the Arduino sketch (explained in Step 4).

Your key will be sent to you by email within a few minutes of being requested.

To request a key, hop over to https://www.teleduino.org/tools/request_key.php (please bear with us while the nice looking site is being built!)

Cheers!
1-40 of 44Next »
Prodigal_Son says: Feb 27, 2013. 12:09 AM
I just wanted to say that you can download an early version of Teleduino Controller for Android devices on Google Play :
https://play.google.com/store/apps/details?id=appinventor.ai_ssslzc.Teleduino_Controller

And like the info says, if you miss any functions please contact me and I will try to add it in future releases.
dslrmotion says: May 3, 2013. 1:17 PM
Everything works as explained in the tutorials. Thanks for all the hard work developing this service. Would love more tutorials in the future if you ever find time. I do have one question. Not sure if I should ask here but I will anyway. I have two Teleduino's hooked up at the same time from two different ports from my router and they seem to conflict with each other. What steps would I take to eliminate this problem? Thanks again for unlimited future projects. Joe
nathanknz (author) in reply to dslrmotionMay 3, 2013. 10:12 PM
Hi dslrmotion,

Thanks for the kind words!

There is no limit to how many devices you can run on the same network (and you can run them all with the same serverPort). You just need to ensure that the mac[] variable is different for each device, and if you're not using DHCP (it is enabled by default), then you'll need to set unique network settings for the device.

Thanks!
siddiqov says: May 2, 2013. 5:44 PM
Hi again,
I have tried many times and wonder about TeleduinoEthernetClientProxy sketch.
if i upload it as it is except replace the key, it works. But as i make some change even a single statement of declaring a variable e.g. int pin=4; it generate error of the following
{"status":403,"message":"Key is offline or invalid.","response":[]}. if i remove the customize code it starts working again. Why is it exhibiting such behavior?
nathanknz (author) in reply to siddiqovMay 3, 2013. 10:09 PM
Hi siddiqov,

Adding custom code shouldn't cause any problems unless it exceeds the devices flash memory or volatile memory (SRAM).

The 403 is a response given by the server if either the key is incorrect or device has not connected to the server.

If you're having trouble getting your device to connect to the server, I would recommend connecting a status LED to pin 8 and checking at which stage the connection is failing - this would help to find a solution.

Thanks!
siddiqov says: May 1, 2013. 4:43 PM
Hi NatahnKnz,
there is an example of fading. i want to run it through teleduino. but don't know how to do it. the example is using pin 9 for the LED, i can turn it on and off through teleduino but how to pass loop controlling variables. will be very grateful to you in this regards.
the code is here
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
nathanknz (author) in reply to siddiqovMay 2, 2013. 2:56 AM
Hi siddiqov,

Unfortunately fading is not natively supported in the standard Teleduino library.

You could, however, add the extra code to the library. The analogWrite function is being called at line 332 of the Teleduino328 library (version 328-0.6.7).

Thanks!
siddiqov in reply to nathanknzMay 2, 2013. 4:49 PM
Hi Nathanknz,
I used fade example for my two linear actuator to extract and retract simultaneously just like to open a box top at both ends and found that from pin 1-8 doesn't activating the linear actuators although i have checked with leds and serial monitors and both are showing that PINS are responding. but as i attached these linear actuators with pin 9 and on-wards, these are activating the actuators. just posting my stupid experiences to help someone who face same things in future.
siddiqov in reply to nathanknzMay 2, 2013. 3:43 AM
Thank you. how about if i send request to turn on PIN 4 and then in the loop i start checking in if(pin==0n){ then do my fading coding}else{do nothing}
OR
if (pin4==ON){
set pin5 high
set pin6 high
delay();}
something like that.
is it possible to handle multiple pins while in one go.
Best regards
nathanknz (author) in reply to siddiqovMay 3, 2013. 10:05 PM
Hi siddiqov,

An override like you've suggested should work fine.
If you just want to replicate the output of one pin to another, the following would probably work (untested):
digitalWrite(5, digitalRead(4));
Just make sure you have the pin modes set to OUTPUT.

Thanks,
Nathan.
siddiqov says: May 1, 2013. 4:35 PM
Hi NathanKnz,
I want to set more then one pin on for a specific time, but don't know how to do it in one go. there is a URL but only for only one pin like pin 4.
https://us01.proxy.teleduino.org/api/1.0/328.php?k=F37CF622F3DAE9AA3ACAE643177A93C7&r=setDigitalOutput&pin=4&output=1&expire_time=10000
nathanknz (author) in reply to siddiqovMay 2, 2013. 2:51 AM
Hi siddiqov,

Thanks again for your comments.

Your question was actually very well timed! In the current version of the firmware (328-0.6.7) you are not able to set multiple outputs with a single API call, but I'm currently testing the next version (328-0.6.8) which supports exactly that! It should be released within the next couple of weeks once I'm satisfied that it's tested out fine.

Setting multiple outputs on a shift register is already supported via a single API call, but requires further components.

Thanks!
Nathan.
siddiqov says: Apr 24, 2013. 3:47 PM
Thank you Nathanknz, the problem in my case was an older version of arduino IDE. when i upgrade it to 1.0.1, every things went perfect.
nathanknz (author) in reply to siddiqovApr 25, 2013. 2:31 AM
Hi siddiqov,
Thanks for reporting back, and great to hear you got it working. Thanks for using Teleduino!
siddiqov says: Apr 20, 2013. 9:09 AM
I uploaded the TeleduinoEhternetClientPoroxy sketch and set my key, obtained via email, but when i tried the following link
https://us01.proxy.teleduino.org/api/1.0/328.php?k=0D8554078235C27AD714A83F08D0DE31&r=getUptime
got the following response
{"status":403,"message":"Key is offline or invalid.","response":[]}

please let me know where am i wrong. I am pasting my code where i have done sme changes
byte useDhcp = true;
byte useDns = true;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xAE, 0xED };
IPAddress deviceIp(192, 168, 0, 100); // Only if useDhcp is false
IPAddress gatewayIp(192, 168, 0, 1); // Only if useDhcp is false
IPAddress dnsIp(192, 168, 0, 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 false
char serverName[] = "us01.proxy.teleduino.org"; // Only if useDns is true
unsigned int serverPort = 5353; // Can be set to either 53 or 5353
byte statusLedPin = 8;

// User configurable key, this is used to authenticate with the proxy server
// This is checked against the EEPROM on boot and written if necessary
// The proxy server retreives the key from the EEPROM
byte key[] = { 0x0D, 0x85, 0x54, 0x07,
0x82, 0x35, 0xC2, 0x7A,
0xD7, 0x14, 0xA8, 0x3F,
0x08, 0xD0, 0xDE, 0x31 };
nathanknz (author) in reply to siddiqovApr 20, 2013. 2:30 PM
Hi siddiqov,

Looking at your code everything looks fine. The error your getting is most likely because something is preventing your device from connecting to the server (possibly firewall).

You can try changing the serverPort variable to 53. If you continue to experience problems, take note of what status the status LED is indicating that you're getting up to. This will help to troubleshoot where the issue is.

On a side note, you may want to request a new API key since you have published this one in a public forum :) Just fill in the form again and a new key will be sent to you.

Thanks for trying Teleduino!
siddiqov in reply to nathanknzApr 22, 2013. 7:58 AM
Thank you for the quick response, Nathanknz. I tried and attached the status LED with 1 k resistor and a new key. The LED didn't even a single flash, though there are many others build-in LED on Ethernet shield, some of them are blinking while two of them are constantly on. Moreover I checked the Status LED with simple Arduino LED sketch and it works. still getting the same error.
{"status":403,"message":"Key is offline or invalid.","response":[]}
when i tried the following URL
https://us01.proxy.teleduino.org/api/1.0/328.php?k={MY KEY}&r=getUptime

i have tried with replacing 5353 with just 53 as well and get the status quo.
nathanknz (author) in reply to siddiqovApr 23, 2013. 1:59 AM
Hi siddiqov,

It's very bizarre that you're not getting anything on the status LED, because even if you didn't have the ethernet shield attached you should still at least see a status flash of '1 - pause - 2', and then it should eventually time out and fail and flash '2' for a while before it restarts and tries again. (1 flash means initialising, 2 flashes means establishing itself on the network). Have you definitely got the status LED connected to pin 8?
siddiqov in reply to nathanknzApr 23, 2013. 4:48 AM
Thank you for your consistent replies. I just Noticed when i restart the teleduino, the status LED flash once and then immediately it flash two times (Flashes). Does it means it initialized and started network but couldn't connect to the server. I will appreciate your tips in this regards. I will appreciate your feed back.
nathanknz (author) in reply to siddiqovApr 24, 2013. 3:04 AM
Hi siddiqov,

The '2' flash indicates that it's in the process of establishing itself on the network, and then a '3' flash indicates it's connecting to the server. It sounds as though it's not connecting to your network. Does your network support DHCP? If not, you'll need to set in the network configuration manually and set useDhcp to false.

Have you verified that your ethernet shield is working fine by trying one of the example sketches that comes with the IDE?
mikeyc.2009 says: Mar 1, 2013. 2:56 AM
Thank you, thank you, thank you!!!
Using Teleduino and Android App Inventor I can control my Arduino from my phone. I have been struggling with DNS and port forwarding for some time. Within a day of finding this Instructable I have something up and running thanks to you.

How hard would it be to point the Teleduino to my own PHP server?
nathanknz (author) in reply to mikeyc.2009Mar 4, 2013. 12:35 AM
Hi mikeyc.2009,
Thanks for the awesome comment!
The Teleduino cloud service is not a distributable package, but if you wish to integrate Teleduino control into your PHP application (via the Teleduino cloud service) you can do so with the Teleduino PHP library (available for download from the Teleduino website - https://www.teleduino.org).
Futuring says: Feb 21, 2013. 10:14 AM
Hi nathanknz ! i'm realy excited of what i'm seeing right now! but while i menchened my Key to the URL i get this error message :
{"status":403,"message":"Key is offline or invalid.","response":[]}

Can you help me PLEASE..i'm realy interested of this great tutorial
nathanknz (author) in reply to FuturingFeb 23, 2013. 1:49 PM
Hi Futuring.

Thanks for the comment.

That particular message occurs when either your key is invalid (which it wont be if it's exactly the same as the one emailed to you), or the device is currently offline. Have you managed to get your device connected? The status LED will provide some clues as to whether or not it has connected, or flash error codes on boot.

Hope that helps!
Futuring in reply to nathanknzFeb 23, 2013. 4:49 PM
Hi Again nathanknz :)
i realy thank you for your quick response! it's such a kind from you .
Okay i'll check it out.. bu now i have other probleme wich is the use of the Ethernet shield : What's the point of using it? i don't realy inderstand the rrelation between the Server/Client Ethernet in the arduino code. in fact, i think about doing a server myself so that it'll communicatie with Both Androphone (Via Webservices) and The arduino Code (Via a simple USB Cable) So Is it a Good Solution ?? or The Ethernet Shild will solve and replace My Server Application ?????
I Appreciate your Help :) Thank you in advance for replying me .. Good Day
nathanknz (author) in reply to FuturingFeb 26, 2013. 1:22 AM
Hi Futuring,

Thanks again for the message.
I'm not 100% sure what you're asking in your question, but I think the correct solution for you is to use the EthernetClientProxy sketch and control the device using the webservice (as shown in this Instructable).

I hope that helps!

Thanks,
Nathan.
tattik says: Nov 27, 2012. 10:55 AM
This is the simplest and efficient Arduino sketch that I've tried.... and is the first that WORKS in a couple of minute. Thank you so much!

Michele.
Italy
nathanknz (author) in reply to tattikNov 27, 2012. 12:11 PM
Thank you for the kind words. Enjoy, and have fun!
jcussol says: Nov 6, 2012. 10:42 AM
Hi, good job !
I have the "Arduino WiFi Shield" : can i modify your sketch to operate on this ?
I tried to simply replace Ethernet.h by Wifi.h, and affect good (i hope !) parameters.
But that don't works.
Can you help me ?
nathanknz (author) in reply to jcussolNov 7, 2012. 12:02 AM
Hi there. The WiFi shield is very exciting and something that I would love to see working with Teleduino.
From reading the reference manual at arduino.cc it looks as though it should work, but will need some additional code added to configure the WiFi device. Try taking a look at the examples at arduino.cc to see if you can get it working - unfortunately I don't have a WiFi shield to try it out with!
kshibata says: Jun 12, 2012. 8:08 PM
Hi, this is the library I am looking for. Thanks!!!
Just short question: Do I have to have static global IP to use this library?
nathanknz (author) in reply to kshibataJun 13, 2012. 3:08 AM
Hi kshubata,

Thank you for your expression of interest.

The Teleduino does not require a static IP, and will work perfectly fine on a dynamic IP. This is because it acts as a client device rather than a server.

Enjoy!
kshibata in reply to nathanknzJun 13, 2012. 6:38 PM
Hi Nathan,

I see. That's nice idea. Is it some technique like "comet" or so? I had difficulties with web server library before because of dynamic IP.

Thank you for your reply anyway.
miguipda says: Apr 22, 2012. 12:08 PM
Hi,



I really appreciate this explanation.



Then I presume that if it is possible to activate a LED it could be possible to activate an independent external computer fan.



The idea for me is to activate a fan if the 1-wire server detect a too high humidity level in a room then it will activate (via web) to start the computer fan to extract outside the air humidity. And it will be stopped when the air humidity has been reduced to the value I decided.



Sincerely thanks and have a nice day.



Miguipda ;-)
nathanknz (author) in reply to miguipdaApr 22, 2012. 1:10 PM
Yep, you're correct. Controlling a fan would use the same theory as controlling the LED. I would suggest you use a combination of a transistor (2N2222) and a relay. Controlling a relay would make a great next topic for my next Instructable. Thanks for the interest!
miguipda in reply to nathanknzApr 23, 2012. 8:39 AM
Yep,

it could be great if you could explain how to command the relay with the SHT10 and/or SHT15 sensor (of temperature/humidity).

Have a nice day,

Miguipda ;-)
nathanknz (author) in reply to miguipdaMay 16, 2012. 3:17 AM
Hi Miguipda,

I'm pleased to say that I have completed adding support for TWI/I2C to the Teleduino firmware and API, using the Arduino Wire library.

This functionality is available from firmware version 328-0.6.5, and the API methods are documented at http://www.teleduino.org/rtfm/api/328.php.

Enjoy!
nathanknz (author) in reply to miguipdaApr 30, 2012. 3:24 AM
Hi Miguipda,

Just a quick note to let you know that I've done some research and I'll be adding I2C support to the Teleduino platform soon, which will support your sensors.

In regards to controlling your fan, I have since posted an Instructable for operating a relay: http://www.instructables.com/id/Control-a-Relay-over-the-Internet-via-Arduino-with/

Thanks!
nathanknz (author) in reply to miguipdaApr 23, 2012. 12:07 PM
Hi. I'll have a look at what is involved with interfacing with those sensors. Thanks!
miguipda in reply to nathanknzMay 17, 2012. 2:20 AM
Hi nathanknz,

it could become a great functionality.

Thanks for your research.

Miguipda ;-)
1-40 of 44Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!