Control an LED Over the Internet Via Arduino With Teleduino
Intro: Control an LED Over the Internet Via Arduino With Teleduino
There is something cool about making an LED glow via an Arduino. What could make that even cooler? How about making that LED glow from anywhere in the world via the internet? Now we're talkin'!
This process is made really simple using the Teleduino sketch for your ethernet enabled Arduino. Haven't heard of Teleduino? That's cool, you may want to take a look at Arduino Control via a Web Service with Teleduino to get yourself started.
This tutorial will guide you through the process of attaching an LED to your Arduino, and provide some example Teleduino API calls to:
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.
Let's begin!
This process is made really simple using the Teleduino sketch for your ethernet enabled Arduino. Haven't heard of Teleduino? That's cool, you may want to take a look at Arduino Control via a Web Service with Teleduino to get yourself started.
This tutorial will guide you through the process of attaching an LED to your Arduino, and provide some example Teleduino API calls to:
- Define the pin mode of a pin
- Turn on the LED
- Turn off the LED
- Set the brightness of the LED (using one of the PWM supported pins on the Arduino)
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.
Let's begin!
STEP 1: Prepare an LED
In this step we put together an LED that we can easily connect to our Arduino.
Parts needed:
Steps:
Awesome!
Parts needed:
- An LED (we decided to use a 10mm white LED because they look neat)
- A 1K Resistor (or similar)
- Some hookup wire (we chose to use some single strand ethernet cable because it's cheap, and connects well to the Arduino pin sockets)
- Some heatshrink (optional, but makes it look nice and tidy)
Steps:
- Take the LED and shorten the lead on the flat-edge side (the shortest lead).
- Shorten one of the leads on the resistor.
- Solder the short lead of the resistor to the short lead of the LED.
- Shorten the other lead on the resistor so that it's the same length as the remainder lead on the LED.
- Solder the hookup wire to the two leads, and apply heatshrink. Take note of which lead is soldered to the resistor (we chose the white wire for this).
- Strip the other end of the hookup wires and connect to the Arduino. The white wire (the wire connected to the resistor) connects to a GND pin, and the other (our green wire) connects to a digital pin (we chose pin 3 because it also supports PWM).
Awesome!
STEP 2: Control LED Via the Teleduino API
Here are some example API calls that you can use to control your LED. You need to replace {key} with the unique API key you obtained when you completed the instructable Arduino Control via a Web Service with Teleduino. Just chuck the URLs into your browser's address bar and you should see some magic happen on that LED.
Define the pin mode of digital pin 3 (Must be done once per boot prior to setting digital outputs. 'pin=3' mean pin 3, 'mode=1' means OUTPUT):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=definePinMode&pin=3&mode=1
Set the output of digital pin 3 to HIGH ('pin=3' means pin 3, 'output=1' means HIGH):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setDigitalOutput&pin=3&output=1
Set the output of digital pin 3 to LOW ('pin=3' means pin 3, 'output=0' means LOW):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setDigitalOutput&pin=3&output=0
Toggle the output of digital pin 3 ('pin=3' means pin 3, 'output=2' means toggle):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setDigitalOutput&pin=3&output=2
Set the PWM value of pin 3 to 32 (LED will glow dull. 'pin=3' means pin 3, 'output=32' means PWM value):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setPwmOutput&pin=3&output=32
Set the PWM value of pin 3 to 255 (LED will glow bright. 'pin=3' means pin 3, 'output=255' means PWM value):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setPwmOutput&pin=3&output=255
Pretty neat, huh?
Define the pin mode of digital pin 3 (Must be done once per boot prior to setting digital outputs. 'pin=3' mean pin 3, 'mode=1' means OUTPUT):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=definePinMode&pin=3&mode=1
Set the output of digital pin 3 to HIGH ('pin=3' means pin 3, 'output=1' means HIGH):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setDigitalOutput&pin=3&output=1
Set the output of digital pin 3 to LOW ('pin=3' means pin 3, 'output=0' means LOW):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setDigitalOutput&pin=3&output=0
Toggle the output of digital pin 3 ('pin=3' means pin 3, 'output=2' means toggle):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setDigitalOutput&pin=3&output=2
Set the PWM value of pin 3 to 32 (LED will glow dull. 'pin=3' means pin 3, 'output=32' means PWM value):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setPwmOutput&pin=3&output=32
Set the PWM value of pin 3 to 255 (LED will glow bright. 'pin=3' means pin 3, 'output=255' means PWM value):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=setPwmOutput&pin=3&output=255
Pretty neat, huh?
STEP 3: Further Reading
Controlling an LED is just a very simple example of what can be achieved by using the Teleduino Arduino library/sketch.
To view the full API reference manual, take a look at http://www.teleduino.org/rtfm/api/328.php.
Have fun!
To view the full API reference manual, take a look at http://www.teleduino.org/rtfm/api/328.php.
Have fun!
33 Comments
jurassic.henri.23 3 years ago
I was wondering if it is possible to control the lights of the Arduino with an other Arduino on an other Wi Fi? I'm pretty sure I'll need to control it by a server, but I'm not so sure yet... If it is possible, can I have a link or the instructions of what I am trying to build somewhere on the web?
THANK YOU VERY MUCH
ThaoD5 8 years ago
Please note that teleduino support the 'mega' size of arduino / arduino-like platforms. The links of the step 2 might not work, you should use https://us01.proxy.teleduino.org/api/1.0/2560.php?k={key}&r=setDigitalOutput&pin=8&output=1 instead
yuvaaraaja 8 years ago
Why only some pins are working for controlling the LED.
from pin 2 to pin 9 are working
others when connected are always glowing the LED.
lmillard 8 years ago
It works! yay
ThomasF5 9 years ago
Never mind. I missed the last letter of my key.
arnold.schmucker 9 years ago
It worked like a charm!
arnold.schmucker 9 years ago
It worked like a charm!
helacaster 9 years ago
im using this awesome system to control relays that control my exterior lights. is there a way to control more then one arduino pin at once?
nathanknz 9 years ago
Great to hear! You can certainly control multiple outputs with a single API call. Take a look at the setDigitalOutputs method over at the Teleduino API documentation: https://www.teleduino.org/documentation/api/328-full
Michele Carfora 9 years ago
Hi, setDigitalOutput always answers with response=0 and every digital pin does not change state while all other functions are ok. Where I'm doing wrong?
Arduino Uno, Ethernet Shield
Thanks
nathanknz 9 years ago
Are you defining the pin mode first using the definePinMode method? It's recommended to set default pin modes using the preset manager at https://www.teleduino.org/tools/manage-presets
Michele Carfora 9 years ago
Thanks, it works!
pmartins11 10 years ago
Hi, I'm wondering if you can control several LED's and servos at the same time without having to use definePinMode every time
nathanknz 10 years ago
You certainly can, providing you are running the servos and LEDs on different pins. To retain the definePinMode setting between reboots, you can set presets by using the tool at https://www.teleduino.org/tools/manage-presets
leonardsla3 11 years ago
---Define the pin mode of digital pin 3 (Must be done once per boot prior to setting digital outputs. 'pin=3' mean pin 3, 'mode=1' means OUTPUT):
http://us01.proxy.teleduino.org/api/1.0/328.php?k={key}&r=definePinMode&pin=3&mode=1------
When you say that it has to be done once per boot does that mean that this will have to be done every time you turn on the teleduino.
nathanknz 11 years ago
Thanks for your comment, and great to hear that you get everything up and running nice and easy.
You're right about definePinMode having to be called each time the Teleduino is turned on, HOWEVER, you can set preset values on your Teleduino device which means that this can occur automatically and you'll no longer have to call definePinMode.
To set preset values on your device, pop over to https://www.teleduino.org/tools/manage-presets. Your device needs to be online for presets to be set (the values are stored in the Arduino's EEPROM).
Thanks for trying Teleduino!
Rainbowjeremy 11 years ago
nathanknz 11 years ago
Thanks for the comment!
Absolutely, the output time can be set. There is an optional parameter expire_time which sets the expiry on the output in milliseconds. If you set it to output=1&expire_time=1000 then the output will go HIGH, then go LOW after 1 second.
Thanks!
Nathan.
moleface 11 years ago
Thanks again. Love your work.
nathanknz 11 years ago
Thanks for the comment.
The PHP class isn't for running on the device itself, it's for running on an external web server that supports PHP. The PHP class contains the methods required to communicate with the Teleduino.
Hope that helps! Let me know if I can help any further.