The Idea

Create an Arduino Sketch to Tweet (via the Arduino Twitter Library) the current number of inquiries every time a push button is triggered.

Getting Started

Check out my blogpost on Getting Started with an Arduino Ethernet Board if you’re in trouble with the pre-settings.

Arduino Ethernet Board Twitter Button

Hardware Settings

As mentioned above we’ll need an Arduino with Ethernet connection to publish our Tweets on the web. Therefore a simple push button is used to trigger the event.

Connection Scheme & Breadboard


Software Settings

Required Arduino Libraries

At this point we’ll need some additional libraries. Download the Twitter Library and add it to your libraries folder within your Arduino IDE (Mac: Documents › Arduino › libraries or respectively on Windows: My Documents › Arduino › libraries).

After that import (Arduino › Sketch › Import Library…) the following libraries to your current sketch: SPI, Ethernet, Twitter.

» Download: Twitter.h (Version 1.3, ca. 5KB)
» Reference: Ethernet.h
» Reference: SPI.h

Authorize App via OAuth Token

Authorize Twitter App Using the Tweet Library to post messages to Twitter from an Arduino we’ll need to get access via a token: Get Your OAuth Token
FYI: You can revoke access at all times within your Twitter Apps Settings

Keep calm and code on

Take a look at the included examples of the Twitter Library you’ve downloaded above.

Insert your Twitter OAuth Token and your Ethernet IP address and give it a try!

As long as Twitter seems to reject repeated Tweets with the same content (returning an error 403) as mentioned by NeoCat (author of the Twitter Library for Arduino) we better get some dynamic values in our Tweet. So let’s take a closer look at the source code:

We’re including the libraries (the same way as it is done in the example):

Next we’re are defining the used elements:

Now, let’s do the setup and connect to Twitter:

And finally output the tweet via sprintf as we need to convert the int to a string(char):

Notice: Tweets are sent via a shared server. We’ve set the delay to zero within the loop() as we’ve included an if/else statement to administer the output. Please avoid sending a lot of requests and do not overload the server.

Source Code

» Download: Dynamic Arduino Tweet Button (Version 1.0)

Arduino Ethernet Board with a Twitter Button

Final Result

Every time someone is pushing the button a Tweet with the current number of inquiries is published on the connected/authorized Twitter Account. Now this can be used as a realtime counter for different actions (as long as Twitter is not down).
FYI: Simply re-upload the code to reset the number of the counter.