Step 2: Arduino

Picture of Arduino
// simpleTweet_00_a

 simpleTweet_00 arduino sketch (for use with
 simpleTweet_00 processing sketch) by @msg_box june2011

 This script is intended for use with a magnetic reed switch,
but any on/off switch plugged into pin #10 will readily work.

The Arduino is connected to a circuit with a sensor that
triggers the code: Serial.write(n); where n = 1 or 2.
The Processing sketch listens for that message and then
uses the twitter4j library to connect to Twitter
via OAuth and post a tweet.

To learn more about arduino, processing, twitter4j,
OAuth, and registering your app with Twitter...
visit <http://www.instructables.com/id/Simple-Tweet-Arduino-Processing-Twitter/>
visit <http://www.twitter.com/msg_box>

This code was made possible and improved upon with
help from people across the internet. Thank You.
Special shoutouts to the helpful lurkers at twitter4j,
arduino, processing, and bloggers everywhere, and
to the adafruit & ladydada crowdsource.
And above all, to my lovely wife, without
whom, none of this would have been possible.

Don't be a dick.

const int magReed_pin = 10; // pin number
int magReed_val = 0;
int currentDoorState = 1; // begin w/ circuit open
int previousDoorState = 1;

void setup(){
pinMode(magReed_pin, INPUT);

void loop(){

void watchTheDoor(){
magReed_val = digitalRead(magReed_pin);
if (magReed_val == LOW){ // open
currentDoorState = 1;
if (magReed_val == HIGH){ // closed
currentDoorState = 2;

void compareStates(int i){
if (previousDoorState != i){
previousDoorState = i;
delay(1000); //