Hi geeks!,

Last week I tried to watch my plants by measuring the soil moisture level then send tweets using Arduino.



I searched the Internet and finally I found 3 ways that I can use to build my project.

Today I will share these methods with you in this blog.

First, Using Arduino UNO with Ethernet shield.

Second, Using Spark core.

Third, Using Arduino UNO with 1Sheeld.

Let’s start with posting tweets using Arduino UNO and Ethernet shield.



Internet Module



Ethernet Shield ($34.55)

Step 1: Connect your Arduino UNO to Ethernet shield.

Step 2: Connect your Arduino to your PC using USB cable and connect your Ethernet shield to the network using RJ-45 cable.

Step 3: Let’s code 🙂

We can use TwitterClient example in Ethernet library, but I suggest another simpler library we can use, which is Twitter Library.

Step 4 : Download and install Twitter Library from this link http://playground.arduino.cc/uploads/Code/Library-Twitter-1.3.zip)

Step 5: Use SimplePost example from Twitter library.

/* Post a simple message to Twitter */ #include <SPI.h> #include <Ethernet.h> #include <Twitter.h> byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x92, 0xA4 }; byte ip[] = { 192, 168, 100, 9 }; Twitter twitter("Replcae this text with your token"); char msg[] = "Hello from Arduino & Ethernet Shield!"; void setup() { Ethernet.begin(mac, ip); Serial.begin(9600); delay(1000); Serial.println("connecting ..."); if (twitter.post(msg)) { int status = twitter.wait(&Serial); if (status == 200) { Serial.println("OK."); } else { Serial.print("failed : code "); Serial.println(status); } } else { Serial.println("connection failed."); } } void loop() { } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 /* Post a simple message to Twitter */ #include <SPI.h> #include <Ethernet.h> #include <Twitter.h> byte mac [ ] = { 0x90 , 0xA2 , 0xDA , 0x0E , 0x92 , 0xA4 } ; byte ip [ ] = { 192 , 168 , 100 , 9 } ; Twitter twitter ( "Replcae this text with your token" ) ; char msg [ ] = "Hello from Arduino & Ethernet Shield!" ; void setup ( ) { Ethernet . begin ( mac , ip ) ; Serial . begin ( 9600 ) ; delay ( 1000 ) ; Serial . println ( "connecting ..." ) ; if ( twitter . post ( msg ) ) { int status = twitter . wait ( & Serial ) ; if ( status == 200 ) { Serial . println ( "OK." ) ; } else { Serial . print ( "failed : code " ) ; Serial . println ( status ) ; } } else { Serial . println ( "connection failed." ) ; } } void loop ( ) { }

Step 6: Configure your Ethernet shield with your Internet network

Change the Mac address in the code with your Ethernet shield Mac address, you will find your Mac address on the back of the shield. Change the IP address with yours. Create your Twitter token to post a message using OAuth.

http://arduino-tweet.appspot.com/oauth/twitter/login

Put your generated token.



Step 7: Type your tweet.



Step 8: Upload your sketch.

Congratulation ! Now check your Twitter account and you will find your new status.

Let’s move to the second method using Spark Core



Internet Module



Spark core ($39).

Step 1: Power the core.

Plug the included USB cable into the Spark Core and your computer. The Core should start blinking blue.

Step 2: Install the App

You can search for the mobile app named “Spark Core”, or you can click one of these links:

iPhone Android

Now use the app to sign up for an account!

Step3: Connect your Core to the Cloud!

Make sure your phone is connected to the WiFi you want to use (it’ll show up in the SSID blank on the app), then enter your password and click CONNECT!

This may take a little while- but don’t worry. It should go through the following colors:

Blinking blue: Listening for Wi-Fi credentials

Solid blue: Getting Wi-Fi info from app

Blinking green: Connecting to the Wi-Fi network

Blinking cyan: Connecting to the Spark Cloud

Blinking magenta: Updating to the newest firmware

Breathing cyan: Connected!

Step4: Use Spark IDE to write your code

Use this link to write code and upload it to the Core. Log in with the same email and password you used to sign up in the app.

Step5: Get a token to post a message using OAuth.

Go to this site and follow Step 1. Save the long string you get (OAuth Key), you’ll need this later!

Step6: Coding 🙂

Write the following code into a new Sketch in the WebIDE.

// Message to Post char msg[] = "Hi, I'm a tweet from a Spark Core!"; // OAuth Key #define TOKEN "OAuth" // Twitter Proxy #define LIB_DOMAIN "arduino-tweet.appspot.com" TCPClient client; void setup() { delay(1000); client.connect(LIB_DOMAIN, 80); client.println("POST /update HTTP/1.0"); client.println("Host: " LIB_DOMAIN); client.print("Content-Length: "); client.println(strlen(msg)+strlen(TOKEN)+14); client.println(); client.print("token="); client.print(TOKEN); client.print("&status="); client.println(msg); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 // Message to Post char msg [ ] = "Hi, I'm a tweet from a Spark Core!" ; // OAuth Key #define TOKEN "OAuth" // Twitter Proxy #define LIB_DOMAIN "arduino-tweet.appspot.com" TCPClient client ; void setup ( ) { delay ( 1000 ) ; client . connect ( LIB_DOMAIN , 80 ) ; client . println ( "POST /update HTTP/1.0" ) ; client . println ( "Host: " LIB_DOMAIN ) ; client . print ( "Content-Length: " ) ; client . println ( strlen ( msg ) + strlen ( TOKEN ) + 14 ) ; client . println ( ) ; client . print ( "token=" ) ; client . print ( TOKEN ) ; client . print ( "&status=" ) ; client . println ( msg ) ; }

Step 7: Token replacment

At the top of the code you’ll see a line called #define TOKEN “OAuth”. Replace the word OAuth with the long string you got in Step 1. (Be sure you keep the quotes around your OAuth string!)

Step 8: Save, Verify and Flash your code



Step 9: Check your twitter account

You can only send around one tweet per minute, so don’t run this code in the main loop!

Finally, let’s move to the last method using 1Sheeld with Arduino UNO, ths one is the easiet way, you only write 1 line of code!



Materials List

1Sheeld ($55)

Step 1: Adjust 1Sheeld

Warning! If you have the Arduino Due or any board that works on 3.3V, you must switch your 1Sheeld to operate on 3.3V since it may damage your board. To switch 1Sheeld to 3.3V locate the toggle switch on the top of the board and switch it to the 3.3V position.

Step 2: Place your 1Sheeld on your Arduino board then plug the Arduino to your laptop or PC

Step 3: Download 1Sheeld Application onto your smart phone. Our app is available on the Google play store at http://1sheeld.com/app

Step 4: Download 1Sheeld library

Download OneSheeld library to your computer through this link

Step 5: Extract the folder, copy it, and paste it in your Arduino libraries directory.

Step 6: Write your Sketch

Open the Arduino IDE on your computer, choose Twitter example from OneSheeld library.

/* Include 1Sheeld library. */ #include <OneSheeld.h> void setup() { /* Start communication. */ OneSheeld.begin(); Twitter.tweet("I'm tweeting from Arduino via 1Sheeld!"); } void loop() { // Put you own code here } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /* Include 1Sheeld library. */ #include <OneSheeld.h> void setup ( ) { /* Start communication. */ OneSheeld . begin ( ) ; Twitter . tweet ( "I'm tweeting from Arduino via 1Sheeld!" ) ; } void loop ( ) { // Put you own code here }

Step 7: Upload your sketch

Here comes the most important part of the whole tutorial, switch 1Sheeld to the Uploading-mode (this is the switch labeled UART Switch on the board) before you upload your sketch to the Arduino board to avoid serial conflicts between 1Sheeld and Arduino, then press the Upload button in the IDE.

Upload mode is turned on when the UART switch is pushed away from the 1Sheeld logo.



Once you have completed your upload you need to switch 1Sheeld back to the operating mode. Don’t forget! If you don’t switch the UART Switch back to the operating mode your project will not work properly as you will have no communication between 1Sheeld and the Arduino board.



Operating mode is turned on when the UART switch is pushed closest to the 1Sheeld logo.

Step 8: Use 1Sheeld Application

Open 1Sheeld application on your Android smart phone. The application will first scan over bluetooth for your 1Sheeld, it will take a few seconds and the phone will find it. Once it appears on your screen as 1Sheeld #xxxx, you will be required to enter the pairing code (the default pairing code is 1234) and connect to 1Sheeld via bluetooth.



NOTE: If you are having trouble please make sure the bluetooth is turned on for your Android phone and that the Android phone is close to your 1Sheeld.

Step 9: Access Shields

Select the shields you would like to use in your Arduino sketch (project) and press on the multiple shields icon at the top right of the app.

In this case, use Twitter Shield then login using your account.

Now let’s compare between the 3 methods to choose the suitable method to use.

Price Size of Code Complexity Security Arduino + Ethernet Shield $34.55 35 lines Medium Low 1Sheeld $55 14 lines

Actually 1 line of code 🙂 Very Simple High Spark Core $39 28 lines Medium Low

Here’s a tutorial video on how to post on Twitter with 1Sheeld: