Instructables

How to tweet from an Arduino using the wifi sheild

Hey, I am a big fan of Instructables. I have consistently used it for the past 3 years and now its time for me to write one myself. 


Here we go. This instructable is for those who want to make some inanimate object tweet automatically. Like say for example you are building a robot and you want the robot to tweet to you or to the world. This obviously means your robot needs to have access to the internet and should have a logic controller. This instructable is specifically about how to use an arduino (logic controller) with wifi shield (the stuff that connects to the internet) to tweet to the world.

Hope you will find it useful.
 
Remove these adsRemove these ads by Signing Up

Step 1: Arduino - whats it? (skip if you know)

Arduino is the quickest way you can attach logic to your project. Say for example you want your light outside your room to switch on automatically when the sun goes down. How do you do it. You want some sort of sensor that detects sunlight. You also want your light that you want to turn on/off. Most importantly you want a controller where which can read data from sensor and appropriately command the light to turn on/off . Arduino is one such controller. In fact arduino is the most popular and easiest way to implement your controller. 

If you are new to arduino you might want to check out this instructable - http://www.instructables.com/id/Intro-to-Arduino/

If you want to get a feel for what are arduino used for and want to spark some ideas - check this out - http://www.instructables.com/technology/arduino/

Here the official arduino website- http://www.arduino.cc/         (you might be a little overwhelmed if you are a complete newbie with electronics. In which case you might want to check out the intro to arduino instructable first)

The picture shows two of the most popular arduinos
terra8232 months ago

is anyone else getting a 404 on the URL request?

terra823 terra8232 months ago

to specify, I'm receiving a 404 Error on the twitter code above:

connecting ...

HTTP/1.0 404 Not Found

Date: Fri, 16 May 2014 16:18:28 GMT

Server: Check Point SVN foundation

Content-Type: text/html

Connection: Close

Last-Modified: Mon, 14 Mar 2011 14:45:46 GMT

Content-Length: 204

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE> 404 File Not Found </TITLE>

</HEAD>

<BODY>

The URL you requested could not be found on this server.

</BODY>

</HTML>

failed : code 404

jmpm46196 months ago
Is there anything more compact then arduino w wifi shield? if I was looking for a wifi capable device?
echoalex (author)  jmpm46193 months ago

There are many but what works for you will be totally dependant on your requirements

ali_meghdadi4 months ago

Have you ever faced Arduino stopped from tweeting? mine goes whole day but I guess it's ram will be full and stops tweeting!

echoalex (author)  ali_meghdadi3 months ago

Yeah sometimes its needs to be reset. Let me know if you figured out a way to do it otherwise.

ali_meghdadi7 months ago
Hi ,
If I want to tweet corresponding to a situation which means I need to tweet many times, what change should I make in above code?
ali_meghdadi9 months ago
Hi,
Thank you for your comprehensive description.I did what you mentioned. But the red LED on my wifi shield is on and yet I do not get the tweet! I would be grateful if you answer.
echoalex (author)  ali_meghdadi9 months ago
Hello,

If the red LED is on, then you have an issue connecting to the wifi. Notice on the picture I marked red LED as an error. If your connection to the internet works you need the green LED to light up.

This could be due to the following reason
- wifi protocol missmatch - there are 3 versions of there protocol - no authentication. WEP and WPA - the code for connecting to the wifi is different for these 3 protocol. Arduino example has example code for each of these 3. Make sure you get the right protocol.
- wifi authentication - make sure you got the wifi username and password right.

Hope that helps.
(removed by author or community request)
echoalex (author)  ali_meghdadi8 months ago
I have not tried with the new version but it looks like it works great with the latest version according to comments by others.

for data logging, you can use an SD for more permanent log. or just print to the debug using Serial.print(var);
stanleyatala12 months ago
Hi ... Googling I found the problem ...!

Apparently with the latest versions of the IDE does not work well the library twitter.
Download the version 1.0.3 and everything is OK ..!

http://arduino.cc/en/Main/Software

(attached screenshot)
Greetings ...!
Captura de pantalla 2013-07-29 a la(s) 22.06.01.pngCaptura de pantalla 2013-07-29 a la(s) 22.06.07.png
I can verify that it was the IDE version. Downloaded 1.0.3 and solved my problem on another project. Thanks for your notes stanleyatala!

(arduino wifi shield connected but not tweeting)
echoalex (author)  stanleyatala9 months ago
Awesome !! :)

Yeah I think I had some version issues as well when I did it.. Great to see that you got it to work. Great job!

Alex
Alex, thank you very much for your comments.
I'm going to be attentive to your new instructables ... (when you can).
Greetings.!
hello echoalex, I have an unrecognized problem:
(first; sorry by my english, I speak Spanish..)

-My Twitter account has the app arduino Ok (http://arduino-tweet.appspot.com).
-I use your library.
-I change in the the sketch, "Token" by indicated Ok.
-I change ssid / pass by my wlan Ok.
-Compile and send the sketch to Arduino Uno + Wifi Ok.
-The shield is connected wifi Ok (ping).
-By the way, I opened my WLAN ports Modem.

but I can not make it work ...!
I have the serial error:

connecting ...
connection failed.

(attached print)

The app still works (authentication) Ok or The library is still in force??
You have any advice for me?, Pls
Captura de pantalla 2013-06-23 a la(s) 06.09.44.pngCaptura de pantalla 2013-06-23 a la(s) 06.10.37.png
echoalex (author)  stanleyatala1 year ago
Hey Stanley,

I have not used that library for about 6 months now. For the tweeting tree project I have created my own website backend instead of going through http://arduino-tweet.appspot.com. So I am not sure if that library is functional now. The reason I moved to my own backend is because arduino resets when processing large text operations. So now I am using arduino for just data logging on my site and from my site i send the tweet. so it looks as if the arduino/tree is tweeting.

Back to your problem. Obviously twitter.post(buf) inside your if condition is the one that is giving you the problem. Check the twitter.h and twitter.cpp . It is possible that with the wifi shield under active development, the code could have been altered. Check it out.

From my experience, if you can code a web page, then data dump your sensor data to your site and write your tweet logic on the site. If you can code php, I can send you my website code and new arduino code. I might write an instructable on that but that will take a while

Hope that helps. Feel free to ask if need more clarifications.

Alex
www.makeystreet.com
jatinbatra1 year ago
Dude this is cool, i want to control motors over wifi can u guide me what to do?
echoalex (author)  jatinbatra1 year ago
Thanks man ... !! If you want to control the motors wirelessly you can use zigbee. But if you still want to use wifi to control, the hard way to do that is to write a webpage which has the instructions for the motor and using the arduino wifi shield to keep polling that webpage.

You can program the webpage in any way you want. I hope that made sense. I would be glad to elaborate if necessary.
It would be great of you if you could eleaborate and expalin me coding how to do that, i'm a very begginer in arduino actually
echoalex (author)  jatinbatra1 year ago
hmmm .. There is a bunch of pieces to the puzzle. I will try my best to elaborate.

What your wifi shield does is that it connects to the internet and sends out a regular http request- which means that you can check google, facebook, twitter or any website. It is capable of loading the source files from the server.


So now imaging you have your own website and the arduino wifi shield connects to your website. So theoretically your arduino can now see what is on your website. Now imagine your website to be a big blank page with only one character in it. So now your arduino is able to read this one character.

Now let's say, that in your arduino logic, the letter - 'a' means motor rotate clockwise , 'b' as stop and 'c' as counter clockwise. If you can somehow change the content of your site, now you can remotely control your motor. This will require some amount of web development skills.

Having said all this - you dont have to build a website. There are opensource codes that connects to your twitter account and reads your tweets. eg - http://www.instructables.com/id/Tweeting-WiFi-Radio-Control-Panel/ . There are many more. Now you can write the character in your tweets and control the motor.

I hope this was useful ! All the best with your project. I would love to see what you make!
cool, I'd love to get one of these wifi shields!
echoalex (author)  amandaghassaei1 year ago
You should :)