Control digital out pins by Twitter messages. Sensor readings sent back to Twitter.
MODIFIED BY JOHN DINGLEY FROM Twitter2LCD originally written by Fabrizio Granelli
See http://www.instructables.com/id/Displaying-Twitter-feed-without-a-PC/

*You can send text messages to the Arduino LCD screen from twitter if there is anyone is around at the other (Arduino) end you want to send text messages to.

*You can control the digital output pins of your arduino by sending it twitter "data" messages from same twitter page.

*Your Arduino can send twitter messages or data back from analog port sensors to the person who is using twitter on the other side of the world.

..............So full 2 way control with feedback!

* Allows twitter messages to display on an LCD display via arduino and ethernet shield. No PC required!

*This means I can control 4 relays for example just by sending a Twitter message.

* Arduino reads the twitter messages at 1 minute intervals and displays them on an LCD screen.

* They can be normal text messages to someone near to the Arduino OR if they have a D as first letter, they are read as "data" messages and used to control the Digital Output Pins.
* Also, the arduino can take measurements from sensors, for example a thermometer and Tweet the readings back to the remote operator who is sending the data/text tweets to the Arduino. So you have FULL REMOTE 2 WAY CONTROL VIA TWITTER


Step 1: What it does

How to use it:
* Set up your twitter account. Choose a username that has 6 (SIX) characters in it, no more and no less.
* - To send a text twitter message to be displayed on the arduino-LCD display, just send it as normal.
* - To send a DATA message (to turn one of 4 LED's on the arduino digital output ports on or off) send a twitter formatted as follows:
* a) Start with a capital "D" , this tells the arduino this twitter has data in it which it needs to look for
* b) After the "D" , with no spaces enter FOUR digits. These must be 0 or 1.
* c) EXAMPLE: the twitter message D0100 will turn on LED 2, D1000 would turn on LED1, D0010 would turn on LED3, D0001 will turn on LED4
* Therefore you can modify this code to turn relays on and off or control anything you like.


Just require:
Arduino (I used a Uno) and Arduino 22
Ethernet shield
Ethernet cable to connect shield to your router box.
I use a standard Serial-to-LCD display. This connects to arduino with 4 wires in total so much easier to set up than a pure LCD screen. Arduino sends it text via a serial wire, using a print.Serial("yourtext"); type of command using SoftwareSerial library. LCD is actually optional, it will still work as a 2 way control system without it.

I have had trouble with some of the blue screened serial-to-LCD displays. I would get a completely standard green one from your Arduino supplier then you know it should work. Try to get one with 4 rows of text so everything fits on the screen.

In photo below you will see I tweeted the message D0101fgh to the Arduino. The Arduino sees the "D" at the front an therefore knows it is a data tweet not just a text message. It then looks at the next 4 characters after the D (which will always be 0 or 1), and these trun the 4 Output Pins ON or OFF.

[Note: The few random letters after the 0's and 1's are there because twitter will not send repeat messages that are the same as ones sent previously. A few random letters get around this (or regularly delete your tweets).

When the Arduino is tweeting data from the analog sensors back to the person using twitter on the other side of the world, it does the same thing but then automatically generates a few random harmless characters at the end of the message to achieve the same objective in the other direction.]
<p>Is there any other method to find my twitter rss code? Since twitter has been updated and none of these methods worked for me.</p>
<p>Hi,</p><p>I&rsquo;m irinakim and I&rsquo;m work in the Wiznet.</p><p>Thank you for using our product.</p><p>We are collecting so much data using our product.</p><p>And I will post the this project on our Web site.( <a href="http://wiznetmuseum.com/" rel="nofollow">http://wiznetmuseum.com</a>)</p><p>Can I post your product on our Web site?</p>
Thanks been using it for awhile. Works great! kinda a noob on coding. Can you asisst in helping me get the code to update more than 1 sensor. I have a dallas temp sensor working currently. The 4 control pins run things on my aquarium. Want to be able tosee more sensor data on twitter and then be able to react. thanks Kenny
I'm a noob but got this partially working. I decided to skip the lcd portion so that I can get the basic sketch working. It compiled without any problem. I monitor the twitter feed and get the expected &quot;Analog Pin 1 reading = [0] 3365&quot; ( I have pin 1 shorted. I get 1023 for 5V as expected). I can see the led hooked to pin 9 blink as expected. I decided to turn on the serial monitor on the pc to monitor the serial out. I get something like this: <br> <br>OKOK. <br>Connection failed <br>Disconnected <br>TEXT TWEET COMING <br>9206 <br>connecting ... <br>HTTP/1.0 200 OK <br>Content-Type: text/html; charset=utf-8 <br>Cache-Control: no-cache <br>Vary: Accept-Encoding <br>Date: Fri, 12 Oct 2012 03:13:02 GMT <br>Server: Google Frontend <br> <br>The number after &quot;TEXT TWEET COMING&quot; corresponds to the random number in the twitter feed. When I tweet D1000 or other combinations, none of the leds on pins 4,5,6 or 7 light up. <br> <br>It is definitely sending the analog value to the twitter feed but I can't seem to control the 4 digital output pins. <br> <br>Any help would be appreciated.
Great UploD Mn. Kinda a noob here. My code keeps hangin up. For for awile and keeps hanging. Any ideas?
I sometimes get this error when trying to read the tweets. <br /> <br />Rate limit exceeded. Clients may not make more than 150 requests per hour <br /> <br />How to handle this problem??
hi, i wanna ask something.. instead of using arduino, is it possible if i use just the atmega8 to build this project? one more thing, i'm a very noob when it comes to programming.. so, could somebody please help me design this project step by step (i know that there is already step by step guide given by the project owner but the truth is i really do not understand especially the codng part).. i would really appreciate if somebody could help me.. thanks in advance..
Hi, <br>I love tis instructable very much and used it as basis of some projects I did. <br>Unfortunaly it doesn't compile on the Arduino 1.0 IDE. <br> <br>What do I need to do to make it work under arduino 1.0 <br> <br>Addie
I just used your project as a templet to control relay for my Xmas tree. I turned off the tweet back and im running it with out a LDC screen and im loving it :D Thanks a lot for putting such a nice ible together
woow.. thanks for sharing :)<br><br>I jut tried this, but I got problem to change twitter to old version eventhougt I clicked my username on the top right..<br>so How I can look RSS feed??<br>Is it anyway else?
plz delete earlier post ill post fixed updated code<br>
I have ported the code for normal lcd setup instead of Serial display ill post code here:<br><br>#include <br><br><br>/*<br>* MODIFIED BY JOHN DINGLEY FROM Twitter2LCD originally written by Fabrizio Granelli See http://www.instructables.com/id/Displaying-Twitter-feed-without-a-PC/<br>* ALSO USES TUTORIAL FROM THIS WEBSITE: http://tronixstuff.wordpress.com as the basis of the part of code that gets Arduino to send data back to Twitter<br><br>* Allows twitter messages to display on an LCD display via arduino and ethernet shield. No PC required!<br>* ALSO ALLOWS CONTROL OF 4 DIGITAL OUTPUT PORTS VIA SIMPLE TWITTER MESSAGES<br>* Also allows Arduino to send data back to the twitter user for example sensor data to complete the very-remote control loop<br><br> * Twitter2LCD<br> * gets xml data from http://twitter.com/statuses/user_timeline/16297873.rss<br> * reads the most recent tweet from field: <br> * writes the output to the LCD.<br> * NOTES (J Dingley): <br> * Set up your twitter account. Choose a username that has 6 (SIX) characters in it, no more and no less.<br> * - To send a text twitter message to be displayed on the arduino-LCD display, just send it as normal.<br> * - To send a DATA message (to turn one of 4 LED's on trhe arduino digital output ports on or off) send a twitter formatted as follows:<br> * a) Start with a capital &quot;D&quot; , this tells the arduino this twitter has data in it which it needs to look for<br> * b) After the &quot;D&quot; , with no spaces enter FOUR digits. These must be 0 or 1.<br> * c) EXAMPLE: the twitter message D0100 will turn on LED 2, D1000 would turn on LED1, D0010 would turn on LED3, D0001 will turn on LED4<br> * Therefore you can modify this code to turn relays on and off or control anything you like.<br> <br> *NOTE: If you have sent a lot of tweets in this format, twitter may stop you sending them as it thinks &quot;you have already sent this message&quot;<br> * Options are to add a few random letters after your data tweet, such as D0100kjjkh, so it is now different to your previous D0100 data tweets<br> (code only looks at the 4 digits that come after the D) OR in longer term, DELETE your past tweets!!<br> <br> * Set up for SERIAL LCD display, green 4 line display.<br> * Compiles with Arduino 22 and runs ok on an Arduino UNO.<br> *NOTE: the various libraries have to be added as folders to the main libraries folder within your arduino environment<br> <br> <br> */<br> <br><br>//LIBRARIES you will need to have in your libraries folder within arduino<br>#if defined(ARDUINO) &amp;&amp; ARDUINO &gt; 18 // If using Arduino 0019 or later, include SPI.h<br>#include <br>#endif<br>//#include <br>#include <br>#include <br>#include <br>#include <br>#include <br>#include <br><br>//Setup of pins as digital outputs (in this case with LED's attached to them, but intention is to use them to control things with)<br>#define LED1Pin 16<br>#define LED2Pin 17<br>#define LED3Pin 18<br>#define LED4Pin 19<br>#define DelayFlashPin 9 //this pin flashes while arduino is waiting 1 minute before looking for next tweet<br><br>long randNumber;<br><br>int analog1;<br><br>char myStringBuffer[80];<br><br>//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };//default ethernet shield MAC<br>byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x20, 0x3B };//my particular ethernet shield MAC (this number is WRITTEN on a label on the Ethernet Shield)<br>//byte server[] = {128,242,240,20}; // Twitter...I found this did NOT work so googled to find current Twitter server IP<br>byte server[] = {199,59,148,10}; // Twitter server IP address (checked 29/3/11)<br><br><br>Twitter twitter(&quot;340667820-dDubuIMtsTPtL2UwsB6arQrbJgYP2kGQzSXmGpU8&quot;); //this one is my jddat2 twitter &quot;token&quot; as in instructable. <br>//You need to get your own twitter token and insert it here instead of mine<br>//XXXXXXXXXXXXXXXXXXXX HOW TO GET YOUR TWITTER TOKEN? XXXXXXXXXXXXXXXXXXXXXXXXXX<br>//a) Log onto Twitter (www.twitter.com) and set up an account for these data transfers. We shall call this your machine account <br>// from now on.<br>//b) Make sure your username has SIX (6) characters in it else the arduino data reader code below will need to be modified.<br>//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/<br>//d) It tells you what to do to get a Twitter TOKEN for your &quot;machine account&quot; that you have just set up.<br>//e) Once you have your token, enter it between the &quot; and &quot; in line of code above that starts with Twitter twitter(&quot;..............<br>//XXXXXXXXXXXXXXXXXXXX END OF HOW TO GET YOUR TWITTER TOKEN XXXXXXXXXXXXXXXXXXXXX<br><br>char tweet[140];<br><br>Client client(server, 80);<br><br>TextFinder finder( client ); <br><br>//SETUP SOFTWARE SERIAL FOR LCD DISPLAY<br>#define rxlcdprintPin 2 //sets new software rx as pin2, from LCD serial-LCD display usnit<br>#define txlcdprintPin 3 //sets new software tx pin as pin 3 to LCD serial-LCD display usnit<br>SoftwareSerial lcdSerial = SoftwareSerial (rxlcdprintPin, txlcdprintPin); //define lcdSerial as rxlcdprintPin (2) and txlcdprintPin (3)<br>//END OF SOFTWARE SERIAL LCD DISPLAY SETUP<br><br>LiquidCrystal lcd(7, 6, 5, 4, 3, 2);<br><br>void setup()<br>{<br><br> lcd.begin(20, 4);<br> Serial.begin(9600);<br> delay(100);<br> <br> //FOR LCD DISPLAY<br> pinMode (rxlcdprintPin, INPUT);<br> pinMode (txlcdprintPin, OUTPUT);<br> lcdSerial.begin(9600);// LCD serial out<br> //end of LCD setup<br> <br> <br> <br> //For digital output pins (with LEDS on them, pins 4 5 6 7, also 13 which flashes as the one minute counter counts down)<br> pinMode(LED1Pin,OUTPUT);<br> pinMode(LED2Pin,OUTPUT);<br> pinMode(LED3Pin,OUTPUT);<br> pinMode(LED4Pin,OUTPUT);<br> pinMode(DelayFlashPin,OUTPUT);<br> <br> <br> <br> Serial.println(&quot;Twitter2LCD&quot;);<br> delay(50);<br>//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br> <br> lcd.clear(); //clears screen<br> delay(50);<br> lcd.print(&quot;Twitter to LCD and&quot;); //lcd text<br> lcd.setCursor(0, 1); //newline<br> lcd.print(&quot;control 4 outputs&quot;); //lcd text<br> delay(50);<br> lcd.setCursor(0, 2);//newline<br> lcd.print(&quot;J.Dingley V1.1&quot;);<br> lcd.setCursor(0, 3);<br>lcd.print(&quot;Ported lcd by sapc&quot;); //lcd text<br> //lcdSerial.print(13, BYTE); //newline<br> delay(500);<br>//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br> <br> randomSeed(analogRead(0)); //reads analog port 0 which must have nothing connected to it as a seed for the random number generator<br> <br> <br> <br> EthernetDHCP.begin(mac);<br>}<br><br><br>void loop()<br>{<br> //lcd.clear();<br> if (client.connect()) {<br><br> //XXXXXXXXXXXXXXX CHANGE THE 9 DIGITS IN STATEMENT BELOW TO THOSE OF YOUR OWN TWITTER RSS feed xxxxxxxxxxxxxxxxxxxxxxx<br> //XXXXXXXXXXXXXXX My instructable tells you how to get your twitter RSS feed number XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br> client.println(&quot;GET http://www.twitter.com/statuses/user_timeline/340667820.rss HTTP/1.0&quot;); // twitter rss for jddat2<br> client.println();<br> } <br> else {<br> <br> Serial.println(&quot;Connection failed&quot;);<br> delay(200);<br> //XXXXXXXXXXX Display XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br> lcd.clear(); //clears screen<br> delay(50);<br> lcd.print(&quot;Connection&quot;); //lcd text<br> lcd.setCursor(0, 1); //newline<br> lcd.print(&quot;FAILED&quot;); //lcd text<br><br> delay(500);<br> //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br> } <br> if (client.connected()) {<br> // get the last tweet by simply parsing the item and title tags<br> if((finder.find(&quot;&quot;)&amp;&amp;(finder.getString(&quot;&quot;,&quot;&quot;,tweet,140)!=0)))<br> { <br> Serial.println(tweet);<br> delay(100);<br> //XXXXXXXXXXXX Display XXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br> lcd.clear(); //clears screen<br> delay(200);<br> lcd.print(&quot;tweet coming&quot;); //lcd tweet text<br> //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX <br><br> delay(500);<br> <br> <br> } <br> else {<br> Serial.println(&quot;Could not find item field&quot;);<br> delay(100);<br> //XXXXXXXXXXXXX Display XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br> lcd.clear(); //clears screen<br> delay(50);<br> lcd.print(&quot;Could not find&quot;); //lcd text<br> lcd.setCursor(0, 1);//newline<br> lcd.print(&quot;item field&quot;); //lcd text<br> //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX <br> } <br> }<br> else {<br> Serial.println(&quot;Disconnected&quot;); <br> delay(100);<br> lcd.clear(); //clears screen<br> delay(50);<br> lcd.print(&quot;Disconnected&quot;); //lcd text<br> }<br> client.stop();<br> client.flush();<br><br><br>/* <br> //XXXXXXXXXXXXX LED control debugging your data read (LED/output pin controller) tweet routine XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br> Serial.println(&quot;LED control routine&quot;);<br> Serial.print(&quot;Last Tweet:&quot;);<br> Serial.print(tweet);<br> Serial.print(&quot;character at position 8 is:&quot;); //if your username has 6 characters, then position 8 in the tweet should be the letter &quot;D&quot; you used at start of this data-tweet<br> Serial.println(tweet[8]);<br> Serial.print(&quot;character at position 9 is:&quot;); //if your username has 6 characters, then position 9 in the tweet should be the first of the 4 control digits (0 or 1)after the &quot;D&quot;<br> Serial.println(tweet[9]);<br> Serial.print(&quot;character at position 10 is:&quot;);//if your username has 6 characters, then position 10 in the tweet should be the second of the 4 digits after the &quot;D&quot;<br> Serial.println(tweet[10]);<br> Serial.print(&quot;character at position 11 is:&quot;);//if your username has 6 characters, then position 11 in the tweet should be the third of the 4 digits after the &quot;D&quot;<br> Serial.println(tweet[11]);<br> Serial.print(&quot;character at position 12 is:&quot;);//if your username has 6 characters, then position 12 in the tweet should be the fourth of the 4 digits after the &quot;D&quot;<br> Serial.println(tweet[12]);<br>*/<br> <br> if (tweet[8] == 68){ //i.e. if character at position 8 of your tweet, where first position is position 0 (zero), is 68 (a capital letter &quot;D&quot; in your tweet<br> //..indicating that the next 4 characters you type will be DATA to the 4 LEDS (i.e. 0's or 1's) then we have a DATA tweet....<br> //if no &quot;D&quot; as first letter of your tweet (after your automatic username) then it will assume we have a TEXT tweet and just display it but<br> //not use it to alter LED outputs i.e not alter any control pin outputs on the arduino, it will leave them as they were until next data tweet comes along<br> Serial.println(&quot;DATA TWEET COMING&quot;);<br> lcd.clear(); //clears screen<br> lcd.print(&quot;DATA TWEET COMING&quot;); //lcd tweet text <br> delay(2000);<br> lcd.clear(); //clears screen<br> lcd.print(&quot; DATA TWEET....&quot;); //lcd tweet text<br> lcd.setCursor(0, 1); //newline <br> delay(200);<br> lcd.print(tweet); //lcd tweet text<br> <br> lcd.print(13, BYTE); //newline<br> <br><br> <br> <br> if (tweet[9] == 49){ //i.e. if character at position 8 of your tweet, where first position is position 0 (zero), is 49 (a number 1 in your tweet) then....<br> Serial.print(&quot;LED Pin 4: ON &quot;);<br> lcd.print(&quot;Pin4 ON &quot;);<br> digitalWrite(LED1Pin, HIGH); // Activate LED1 (i.e, digital output pin 4) <br> <br> }<br> else {<br> Serial.print(&quot;LED Pin 4: OFF &quot;);<br> lcd.print(&quot;Pin4 OFF &quot;);<br> digitalWrite(LED1Pin, LOW); // De-ctivate LED1 (i.e, digital output pin 4) <br> }<br> <br> if (tweet[10] == 49){<br> Serial.print(&quot;LED Pin 5: ON &quot;);<br> lcd.print(&quot;Pin5 ON&quot;);<br> digitalWrite(LED2Pin, HIGH); // Activate LED2 (i.e, digital output pin 5) <br> }<br> else {Serial.print(&quot;LED Pin 5: OFF &quot;);<br> lcd.print(&quot;Pin5 OFF&quot;);<br> digitalWrite(LED2Pin, LOW); // De-activate LED2 (i.e, digital output pin 5) <br> }<br> <br> lcd.setCursor(0, 1); //newline <br> <br> if (tweet[11] == 49){<br> Serial.print(&quot;LED Pin 6: ON &quot;);<br> lcd.print(&quot;Pin6 ON &quot;);<br> digitalWrite(LED3Pin, HIGH); // Activate LED3 (i.e, digital output pin 6) <br> }<br> else {Serial.print(&quot;LED Pin 6: OFF &quot;);<br> lcd.print(&quot;Pin6 OFF &quot;);<br> digitalWrite(LED3Pin, LOW); // De-activate LED3 (i.e, digital output pin 6) <br> }<br> <br> if (tweet[12] == 49){<br> Serial.println(&quot;LED Pin 7: ON&quot;);<br> lcd.print(&quot;Pin7 ON&quot;);<br> digitalWrite(LED4Pin, HIGH); // Activate LED4 (i.e, digital output pin 7) <br> }<br> else {Serial.println(&quot;LED Pin 7: OFF&quot;);<br> lcd.print(&quot;Pin7 OFF&quot;);<br> digitalWrite(LED4Pin, LOW); // De-activate LED4 (i.e, digital output pin 7) <br> } <br> } //end of check for a data tweet <br> <br> <br> <br> <br> <br> //XXXXXXXXXXXXXXXXXXXX else if text tweet (no data)just send it to LCD screen and leave LEDS as they were since last data text<br> //REMEMBER, IF YOU START YOUR TEXT TWEETS WITH A LETTER &quot;D&quot; IT SHOULD BE OK AS DATA READER SEES THE D THEN LOOKS FOR &quot;1&quot; VALUES TO TURN ON LEDS WITH<br> //IF IT DOES NOT SEE A &quot;1&quot; IT DEFAULTS THE LED STATUS TO OFF. SO PROBABLY OK MOST OF THE TIME TO START SOME TEXT TWEETS WITH A &quot;D&quot; IF YOU REALLY MUST!<br>else {<br> //XXXXXXXXXXXXXXXXput text tweet onto LCD XXXXXXXXXXXXXXXXXXXXXXXXX<br> lcd.clear(); //clears screen<br> Serial.println(&quot;TEXT TWEET COMING&quot;);<br> lcd.print(&quot;TEXT TWEET COMING&quot;); //lcd tweet text<br> delay(2000);<br> lcd.clear(); //clears screen<br> delay(200);<br> Serial.print(tweet); //Serial viewer<br> lcd.print(tweet); //lcd tweet text<br> //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX <br> }<br><br>transmittweet1 (); //send a data tweet to twitter (you could write different versions of transmittweet for different parameters, sent at different time intervals)<br><br>//60 SECOND DELAY BEFORE LOOKING FOR NEXT TWEET. ALTER THIS TO SUIT YOUR REQUIREMENTS. <br>for (int j=0; j&lt;60; j++) { <br> digitalWrite(DelayFlashPin, HIGH); // Activate Pin 9 LED so you know it is counting down 1 min not just crashed!<br> delay(300); // delay 0.3 second<br> digitalWrite(DelayFlashPin, LOW); // De-activate Pin 9 LED built into arduino board so it flashes on and off<br> delay(700); // delay 0.7 second<br> }<br>}<br><br>void transmittweet1 (){<br>//XXXXXXXXXXXXXXXXXXXXXXXXXXXX TRANSMIT A TWEET SECTION xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br>//XXXX THIS IS WHERE THE ARDUINO TAKES A MEASUREMENT FROM A SENSOR FOR EXAMPLE AND TWEETS THE VALUE TO MY TWITTER PAGE XXXXXXXXXX<br>// THE TWEET HAS A 4 DIGIT RANDOM NUMBER ATTACHED TO THE END OF IT SO THAT IF THE DATA READING SENT HAS SAME VALUE AS AN EARLIER TWEET<br>//TWITTER WILL STILL ACCEPT IT (TWIITER TENDS TO BLOCK REPEAT IDENTICAL MESSAGES OTHERWISE)<br><br><br>// Ethernet Shield Settings<br>// Alter ip, gateway and subnet to suit your own network!<br><br>byte ip[] = { 192,168,0,177}; // choose your own IP for ethernet shield - this one should work though as it stands<br>byte gateway[] = { 192,168,0,1 }; // insert your network gateway here<br>byte subnet[] = { 255, 255, 255, 0 }; // insert your network subnet address here (Instructable shows you how to do this)<br>//XXXXXXXXXXXXXXXXXX How to find your gateway and subnet ? (leave the ip[] above alone)XXXXXXXXXXXXXXXXX<br>//Probably easier ways to do this but this is what I did:<br>//Open this website: http://portforward.com/help/setup_static_ip_address.htm<br>//Download their software called PF Setup Static IP Address <br>//Run the program, a window will open displaying properties of your system, in particular your router<br>//DO NOT ALTER ANYTHING, JUST LOOK AT THE VALUES AND WRITE THEM DOWN, they include your router ip address, the gateway address and the subnet mask<br>//Close program down, you can delete it later. Not needed again<br>//XXXXXXXXXXXXXXXXX End of how to find your gateway address and subnet mask XXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br><br>delay(5000);<br>Ethernet.begin(mac, ip, gateway, subnet);<br><br><br>delay(1000);<br>BufferClear (); //clears myStringBuffer NOTE: buffer has 80 characters at present as max length<br>strcat(myStringBuffer, &quot;Sent to twitter: Analog Pin 1 reading = [&quot;); //adds this to start of myStringBuffer<br>analog1=(analogRead(1)); //reads analog port 1<br>char measurement1buffer[7];<br>itoa (analog1,measurement1buffer,10);//converts measured value (0-1023) to a char string.<br>strcat(myStringBuffer, measurement1buffer); //adds this measurement1buffer to my string buffer<br>strcat(myStringBuffer, &quot;] &quot;); //adds this to end of the data value we have just added to the myStringBuffer, the next 4 digits will just be the random ones to be ignored<br><br>getrandomnumber();<br>char endbuffer [8];<br>itoa (randNumber,endbuffer,10); //converts random number into same number but in a char string with ?? a terminal null added<br><br>strcat(myStringBuffer, endbuffer); //adds this randomly generated 4 digit endbuffer to my string buffer so twitter accepts <br>//and displays new measurements even if they are the same as previous ones!!<br><br><br>sendtweet(myStringBuffer); //send the completed tweet text with the 4 digit random number tacked on the end<br>//xxxxxxxxxxxxxxxxxxxxxxxxx END OF TRANSMIT A TWEET function XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>}<br><br>void sendtweet(char msg[])<br>{<br>Serial.println(&quot;connecting ...&quot;);<br>if (twitter.post(msg))<br>{<br>// Specify &amp;Serial to output received response to Serial.<br>// If no output is required, you can just omit the argument, e.g.<br>// int status = twitter.wait();<br>int status = twitter.wait(&amp;Serial);<br>if (status == 200)<br>{<br>Serial.println(&quot;OK.&quot;);<br>} else<br>{<br>Serial.print(&quot;failed : code &quot;);<br>Serial.println(status);<br>}<br>} else<br>{<br>Serial.println(&quot;connection failed.&quot;);<br>}<br>}<br><br><br>//string manipulation function for adding each new letter to the existing sentence string<br>void strcat(char* original, char appended)<br>{<br> while (*original++)<br> ;<br> *original++ = appended;<br> if (appended)<br> *original = '\0';<br>} <br><br><br>void BufferClear (){<br>//to clear the character string ready for a new sentence when &quot;new&quot; is clicked on the screen<br> for (int k = 1;k &lt;= 80;k++){<br> myStringBuffer[k - 1] = 0; // blank buffer content with null characters<br> }<br>}<br><br><br>void getrandomnumber() {<br> // print a random number from 0 to 299<br> //randNumber = random(300);<br> //Serial.println(randNumber); <br><br> // print a random number from 1000 to 9999<br> randNumber = random(1, 9999);<br> Serial.println(randNumber);<br><br> delay(50);<br>}<br>
Awesome! I've been waiting for this!
Awesome! Love it!

About This Instructable