Rafa Juárez
Published © GPL3+

Arduino and Ethernet Shield sending Tweets to Twitter

The idea is to show how easy we can use Arduino to post automatic and cyclical Tweets to share the status of the Analog inputs in Twitter.

BeginnerProtip1 hour5,620
Arduino and Ethernet Shield sending Tweets to Twitter

Things used in this project

Story

Read more

Code

Code

Arduino
Copy and paste. Change your token and IP
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>

// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { 192, 168, 1, 177 }; //This is for the IP address of your board. Scan your router and select the ight IP address
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("PUT HERE YOUR TOKEN THAT LINKS THE TWEETS TO YOUR TWEETER ACCOUNT"); //put here your token

// Message to post
char msg[200];
int a0,a1,a2,a3,a4,a5;
int n=0;

void setup()
{
  delay(1000);
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("SimplePostTwitter.ino  envía un tweet cada 70sgs. con el valor de la A0 en decimal y delante un número indicando el numero de Tweet");
  Serial.println("connecting ...");
}

void loop()
{
while(1){ //repeat for ever
          n++; // Index to say which order of tweet is
          //get some data from Aanalog inputs. 
          a0=analogRead(0);
          a1=analogRead(1);
          a2=analogRead(2);
          a3=analogRead(3);
          a4=analogRead(4);
          a5=analogRead(5);
          sprintf(msg,"Tweet number... %d : A0=%d : A1=%d : A2=%d : A3=%d : A4=%d : A5=%d", n,a0,a1,a2,a3,a4,a5); // Variables to show in the Tweet body
          Serial.println(msg);  //for testing
          if (twitter.post(msg)) { //To post the Tweet and somes diagnostics
                          int status = twitter.wait(&Serial);
                          if (status == 200) {
                            Serial.println("OK.");
                          } else {
                            Serial.print("failed : code ");
                            Serial.println(status);
                          }
              } else {
                          Serial.println("connection failed.");
                        }
           delay(70000); // Server can only receive 1 tweet per minute. This value is in miliseconds
         }
}

Credits

Rafa Juárez

Rafa Juárez

18 projects • 39 followers
Very interested in prototyping of new ideas. 30 years experience in electronics.

Comments