— golan @ 2:35 pm


(Due Wednesday, November 9):

  • Make an object which responds to a Tweet in an interesting way, or/and which sends a Tweet for an interesting reason. For example, you might have a small box in your fridge, that tweets whenever someone opens the door and the light goes on. Give careful thought to where your project “lives”, and who (or what) it responds to.
  • Create a YouTube video which documents your project. In a blog post, embed your video, and write some text (~100-150 words) about your project: what it does, why, and how.

Advanced students: feel free to consider using Pachube as a source for live data streams.


In this unit, we’re exploring the idea of the “Internet of Things“, and Things that Tweet, by making networked objects. These are things — artworks or what-have-you — that are connected to the Internet. They may act on signals they receive, or they may transmit signals from things they sense, or both. They can even act on a signal from the other side of the world! We’ll take advantage of open protocols like Twitter, open-source arts engineering tools like Processing and Arduino, and API’s like Twitter4j and the Java String API in order to do our work:

In order to do this project, you’ll need to have a Twitter account, and then create an authorized “App”. Basically, Twitter wants you to have fun, but they also want to keep track of what you’re doing, so that you don’t send lots of spam. (Computer programs are good at that.) You’ll need to get credentials by doing the following:

  • Get a Twitter account
  • Go to
  • Fill out the description of your application (e.g. “Caroline’sEMS2App”)
  • Agree to the developer’s license, fill out the CAPTCHA, etc…
  • Change your app settings (Settings tab) to “Read and Write”
  • Copy and paste your credentials: OAuthConsumerKey and OAuthConsumerSecret
  • Request, then copy and paste your AccessToken and AccessTokenSecret
  • Twitter4j will require those credentials in order for you to do stuff.


  • Please don’t use my (Golan’s) credentials, which happen to appear in the code examples linked below. I don’t want to be blacklisted because you sent a bunch of spam. Please get your own.
  • Limit your query rate! Twitter is pretty concerned with limiting the rates of queries you make. Your app can get blacklisted (for 15 days!) if you exceed 350 queries per hour. That’s why I have delay(12000) in the code examples that fetch data from Twitter.


(Please note that you’ll need to substitute in your own Twitter-Developer credentials for these to work.)

1. Here’s a simple demo of Tweeting from Processing:

2. Here’s code for Arduino + Processing, such that pressing a button on the Arduino sends a tweet via Processing:

3. Here’s an Arduino+Processing project that moves a servo in response to a tweet. The servo is set to a position which comes from a number parsed from the Tweet:

4. Here’s a Processing project that checks Twitter periodically to see if someone — anyone — has recently Tweeted a certain word. (I chose the word “finagle” because it doesn’t come up too often.) When that word is Tweeted, a signal is sent to an Arduino:


Here are some simple examples of String parsing… for example, if you were trying to parse Tweets:

// Testing to see if a Tweet contains a certain word
String tweetString = "I sure love bees";
String testString = "love";

int locationOfTestStringInTweet = tweetString.indexOf(testString);
if (locationOfTestStringInTweet != -1) {
  println ("Test string exists! (At character index: " + locationOfTestStringInTweet + ")");

// Converting a single number (encoded as a String) into an integer
String singleIntegerString = "123"; // that's a String, not an integer, folks

// If you want to be really safe, you have to make sure it's actually an integer.
// We do that with the try/catch business, which takes care of errors.
try {
  int integerFetchedFromString = Integer.parseInt (singleIntegerString);
  println ("The encoded integer = " + integerFetchedFromString) ;
catch(NumberFormatException e) {
  println("That wasn't an integer, silly!"); // you gots problems

// Parsing some numbers from a tweet.
// Here, I'm relying on an assumption that our tweet is correctly formatted, so no try/catch....
String tweetMixingStringsAndNumbers = "127 180 255 happy";
String arrayOfWords[] = split (tweetMixingStringsAndNumbers, " ");
int valueA = Integer.parseInt (arrayOfWords[0]);
int valueB = Integer.parseInt (arrayOfWords[1]);
int valueC = Integer.parseInt (arrayOfWords[2]);
String mood = arrayOfWords[3];
println("Commands: " + valueA + " " + valueB + " " + valueC);


No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2019 CMU Electronic Media Studio II, Fall 2011, Section A | powered by WordPress with Barecity