Photo of Arduino + Ethernet shield + Serial-LCD display.
LED's on the 4 digital output pins we are using are there just to show which ones are ON and which ones are OFF.
So here Digital output Pin7 (in the pin sequence 4,5,6,7) is turned ON according to the "data" tweet it has just received, so 4th LED from the left (connected to Pin7) is indeed turned ON as you can see....it works.
(The 5th LED on the right is just there to flash once per second while one minute delay is running before it looks for the next Tweet message, you can set any time delay you like).
Here is a view of the Twitter page the person remotely controlling the Arduino will be using.
- As you can see the person has sent a "data" message to the Arduino (D0101) to turn on LED's attached to pins 5 and 7.
- They have also received some twitter messages from the Arduino showing data values from a sensor on Analog Pin 1 (value displayed is 1023 at the moment).
To stop twitter rejecting the repeat readings from the analog sensor which are still 1023 - the same as previous readings, my code puts the reading in brackets so it is clear to the person looking at it, then puts some random numbers between 1000 and 9999 at the end to make the total tweet NOT the same as any of the previous ones, so Twitter accepts it as a new message and displays it OK.
Now for the setup.
You will be pleased to hear that you do not have to do any port-forwarding with your router or anything like that.
However, you do need to set up aTwitter account for your remote control arduino project, which from now on we will call your "machine account".
Also you need to use your normal PC to find out some information about your own router (the box that your phone cable goes into and your PC is also connected to to allow it to "talk" to the internet).
In Arduino on the PC that you will use to program your Arduino board with (via the temporarily attached USB cable) there is a folder called Libraries.
Inside this folder there are more folders for different functions. These are the individial libraries containing code for specific specialist functions the Arduino will perform. You need to add some extra folders like these to the main libraries folder.
Here is a list of the library folders you will need to add to your main arduino "Libraries" folder:
SPI.h (this one should already be there)
Ethernet.h (this one should already be there on later versions of arduino)
SoftwareSerial.h (this one should already be there)
a) TextFinder is available from here: http://www.arduino.cc/playground/Code/TextFinder
b) EthernetDNS and EthernetDHCP are found here: http://gkaindl.com/software/arduino-ethernet/dns
- Click to download their file called Arduinoethernet. Extract the files. Open the folder and inside you will find
more folders. Get the ones called EthernetDNS and EthernetDHCP and copy these folders into your main arduino "libraries" folder.
c) Twitter.h library is found here: http://www.arduino.cc/playground/Code/TwitterLibrary
d) Ethernet.h library is already in the libraries in latest versions of Arduino
Having done this you need to log on to www.twitter.com and set up an account.
NOTE: for my program to work without being modified, you need to choose yourself a 6 (SIX) character long Username (no smaller and no longer !) From now on we will refer to this account as your "machine account."
NEXT: You need to find out what your twitter account "Token" is as you will need to write it down and insert it into the Arduino sketch later.
In the Arduino sketch there is a line like this:
Twitter twitter("275938231-D93Q2mTtMv3vg4quP25qOe1Lp5eER09ZdHsbibOE"); //this one is my jddat2 token where jddat2 is my 6 digit twitter username. You need to get your own twitter token and insert it here instead of mine
HOW TO GET YOUR TWITTER TOKEN?
a) Log onto Twitter (www.twitter.com) and set up an account for these data transfers. We shall call this your machine account
from now on.
b) Make sure your username has SIX (6) characters in it else the arduino data reader code below will need to be modified.
c) Then, open this web tutorial: http://tronixstuff.wordpress.com/2011/03/08/moving-forward-with-arduino-%e2%80%93-chapter-30-%e2%80%93-twitter/
d) It tells you what to do to get a Twitter TOKEN for your "machine account" that you have just set up.
e) Once you have your token, write it down as you will later enter it between the " and " in line of code in my sketch (see later on) that starts with Twitter twitter("..............
Page 1 of web tutorial (c) screenshot attached.
Click where it says "this page"..................
Here is the data appearing on the Twitter page.
You can also see that the person using Twitter has sent a data file (beginning with a D so the sketch "knows" a data twitter is coming) back to the arduino to turn on the second and fourth LED's in the sequence of 4 (Pins 5 and 7).
That's a pro feature!
Want to go pro?
First step is to sign up.
Already a member?" Login »