Twitter Controlled Arduino Outputs - No PC - LCD Display + Sensor Data to Twitter

41,571

70

14

Posted

Introduction: Twitter Controlled Arduino Outputs - No PC - LCD Display + Sensor Data to Twitter

Control digital out pins by Twitter messages. Sensor readings sent back to Twitter.
MODIFIED BY JOHN DINGLEY FROM Twitter2LCD originally written by Fabrizio Granelli
See https://www.instructables.com/id/Displaying-Twitter-feed-without-a-PC/

*You can send text messages to the Arduino LCD screen from twitter if there is anyone is around at the other (Arduino) end you want to send text messages to.

*You can control the digital output pins of your arduino by sending it twitter "data" messages from same twitter page.

*Your Arduino can send twitter messages or data back from analog port sensors to the person who is using twitter on the other side of the world.



..............So full 2 way control with feedback!




* Allows twitter messages to display on an LCD display via arduino and ethernet shield. No PC required!
* ALSO ALLOWS CONTROL OF 4 DIGITAL OUTPUT PORTS VIA SIMPLE TWITTER MESSAGES

*This means I can control 4 relays for example just by sending a Twitter message.

* Arduino reads the twitter messages at 1 minute intervals and displays them on an LCD screen.

* They can be normal text messages to someone near to the Arduino OR if they have a D as first letter, they are read as "data" messages and used to control the Digital Output Pins.
* Also, the arduino can take measurements from sensors, for example a thermometer and Tweet the readings back to the remote operator who is sending the data/text tweets to the Arduino. So you have FULL REMOTE 2 WAY CONTROL VIA TWITTER


NOTE: IF YOU JUST WANT TO TURN THE OUTPUT PINS ON AND OFF REMOTELY, AND HAVE SENSOR DATA SENT TO TWITTER, YOU DON'T NECESSARILY HAVE TO HAVE THE LCD SCREEN PRESENT, the sketch will run fine, just don't bother connecting up an LCD module.

Step 1: What It Does

How to use it:
* Set up your twitter account. Choose a username that has 6 (SIX) characters in it, no more and no less.
* - To send a text twitter message to be displayed on the arduino-LCD display, just send it as normal.
* - To send a DATA message (to turn one of 4 LED's on the arduino digital output ports on or off) send a twitter formatted as follows:
* a) Start with a capital "D" , this tells the arduino this twitter has data in it which it needs to look for
* b) After the "D" , with no spaces enter FOUR digits. These must be 0 or 1.
* c) EXAMPLE: the twitter message D0100 will turn on LED 2, D1000 would turn on LED1, D0010 would turn on LED3, D0001 will turn on LED4
* Therefore you can modify this code to turn relays on and off or control anything you like.

NO PC REQUIRED AT ALL

Just require:
Arduino (I used a Uno) and Arduino 22
Ethernet shield
Ethernet cable to connect shield to your router box.
I use a standard Serial-to-LCD display. This connects to arduino with 4 wires in total so much easier to set up than a pure LCD screen. Arduino sends it text via a serial wire, using a print.Serial("yourtext"); type of command using SoftwareSerial library. LCD is actually optional, it will still work as a 2 way control system without it.

I have had trouble with some of the blue screened serial-to-LCD displays. I would get a completely standard green one from your Arduino supplier then you know it should work. Try to get one with 4 rows of text so everything fits on the screen.


In photo below you will see I tweeted the message D0101fgh to the Arduino. The Arduino sees the "D" at the front an therefore knows it is a data tweet not just a text message. It then looks at the next 4 characters after the D (which will always be 0 or 1), and these trun the 4 Output Pins ON or OFF.

[Note: The few random letters after the 0's and 1's are there because twitter will not send repeat messages that are the same as ones sent previously. A few random letters get around this (or regularly delete your tweets).

When the Arduino is tweeting data from the analog sensors back to the person using twitter on the other side of the world, it does the same thing but then automatically generates a few random harmless characters at the end of the message to achieve the same objective in the other direction.]

Step 2: Setup

Photo of Arduino + Ethernet shield + Serial-LCD display.

LED's on the 4 digital output pins we are using are there just to show which ones are ON and which ones are OFF.

So here Digital output Pin7 (in the pin sequence 4,5,6,7) is turned ON according to the "data" tweet it has just received, so 4th LED from the left (connected to Pin7) is indeed turned ON as you can see....it works.


(The 5th LED on the right is just there to flash once per second while one minute delay is running before it looks for the next Tweet message, you can set any time delay you like).

Step 3: Twitter Page

Here is a view of the Twitter page the person remotely controlling the Arduino will be using.

- As you can see the person has sent a "data" message to the Arduino (D0101) to turn on LED's attached to pins 5 and 7.

- They have also received some twitter messages from the Arduino showing data values from a sensor on Analog Pin 1 (value displayed is 1023 at the moment).

To stop twitter rejecting the repeat readings from the analog sensor which are still 1023 - the same as previous readings, my code puts the reading in brackets so it is clear to the person looking at it, then puts some random numbers between 1000 and 9999 at the end to make the total tweet NOT the same as any of the previous ones, so Twitter accepts it as a new message and displays it OK.

Step 4: Setting Up

Now for the setup.

You will be pleased to hear that you do not have to do any port-forwarding with your router or anything like that.

However, you do need to set up aTwitter account for your remote control arduino project, which from now on we will call your "machine account".

Also you need to use your normal PC to find out some information about your own router (the box that your phone cable goes into and your PC is also connected to to allow it to "talk" to the internet).

LIBRARIES
In Arduino on the PC that you will use to program your Arduino board with (via the temporarily attached USB cable) there is a folder called Libraries.

Inside this folder there are more folders for different functions. These are the individial libraries containing code for specific specialist functions the Arduino will perform. You need to add some extra folders like these to the main libraries folder.

Here is a list of the library folders you will need to add to your main arduino "Libraries" folder:

SPI.h (this one should already be there)
Ethernet.h (this one should already be there on later versions of arduino)
EthernetDHCP.h
TextFinder.h
SoftwareSerial.h  (this one should already be there)
EthernetDNS.h
Twitter.h


a) TextFinder is available from here:     http://www.arduino.cc/playground/Code/TextFinder
b) EthernetDNS and EthernetDHCP are found here:     http://gkaindl.com/software/arduino-ethernet/dns
- Click to download their file called Arduinoethernet. Extract the files. Open the folder and inside you will find
more folders. Get the ones called EthernetDNS and EthernetDHCP and copy these folders into your main arduino "libraries" folder.
c) Twitter.h library is found here:  http://www.arduino.cc/playground/Code/TwitterLibrary
d) Ethernet.h library is already in the libraries in latest versions of Arduino


RIGHT

Having done this you need to log on to www.twitter.com and set up an account.
NOTE: for my program to work without being modified, you need to choose yourself a 6 (SIX) character long Username (no smaller and no longer !) From now on we will refer to this account as your "machine account."

NEXT: You need to find out what your twitter account "Token" is as you will need to write it down and insert it into the Arduino sketch later.

In the Arduino sketch there is a line like this:
Twitter twitter("275938231-D93Q2mTtMv3vg4quP25qOe1Lp5eER09ZdHsbibOE"); //this one is my jddat2 token where jddat2 is my 6 digit twitter username. You need to get your own twitter token and insert it here instead of mine


HOW TO GET YOUR TWITTER TOKEN?
a) Log onto Twitter (www.twitter.com) and set up an account for these data transfers. We shall call this your machine account
 from now on.
b) Make sure your username has SIX (6) characters in it else the arduino data reader code below will need to be modified.
c) Then, open this web tutorial: http://tronixstuff.wordpress.com/2011/03/08/moving-forward-with-arduino-%e2%80%93-chapter-30-%e2%80%93-twitter/
d) It tells you what to do to get a Twitter TOKEN for your "machine account" that you have just set up.
e) Once you have your token, write it down as you will later enter it between the " and " in line of code in my sketch (see later on)  that starts with Twitter twitter("..............


Page 1 of web tutorial (c) screenshot attached.
Click where it says "this page".................. 

Step 5: Get Twitter Token (2)

This is what you should now see

Step 6: Get Twitter Token 3

This now comes up, click on "Allow"

NOTE: I think you should be logged on to the Twitter account you have just set up while you do this (minimise the Twitter window)

Step 7: Get Twitter Token 4

Finally it gives you your token.

Copy and paste it somewhere safe as we will need this later to insert into the Arduino sketch.

This is my test token for this instructable, yours will be different.

Step 8: Get Your Twitter RSS Feed

OK, now you have to get something called your Twitter RSS feed number

On Twitter page below, see the RSS feed icon (you have to click on your user name (top right of Twitter page) select the "switch to Old Twitter" option to see the RSS feed icon like this)
NOTE: This "Old Twitter" format option will end soon so at end of this instructable (pages 18 onwards) I have described an alternative way to get your RSS feed number from the "new" Twitter display page - a bit more involved but you can still do it.

So if you have managed to get the "old Twitter" display option up on screen as in example in photo, right-click on the RSS feed icon bottom right.

Step 9: RSS Feed 2

Now you see a window like this

Click on "properties"


Step 10: RSS Feed 3

Final step for this:


As you can see in the midst of this is a 9 digit number - write it down as your Twitter RSS feed number

Step 11: Find Out About Your Router

Don't worry this is boring but we are nearly there with this information gathering, just go through it methodically:

We now need to find out some last bits of information.
You need to find out some strange things called your ip and your gateway and your subnet addresses:

There are probably easier ways to do this but this is what I did:
- Open this website: http://portforward.com/help/setup_static_ip_address.htm
- Download their software called PF Setup Static IP Address
- Run the program, a window will open displaying properties of your system, in particular your router (example screenshot shown in photo)
DO NOT ALTER ANYTHING , JUST LOOK AT THE VALUES AND WRITE THEM ALL DOWN, they include your router ip address, the gateway address and the subnet mask among others.
- Close program down, you can delete it later. Not needed again




Step 12: CODE: Now Add Info to Arduino Sketch

If you have got this far well done .

Now, open the Arduino sketch. It is attached as a text file so you will need to paste it into a blank Arduino sketch compile it for your board save it and upload it to your board in normal way.

However first you will need to look at the sketch and insert some of the numbers you have just collected and written down in previous few steps:

1) There is a line of code after
char myStringBuffer[80];
which starts like this:   byte mac[] = { OX90, OXA2     and so on.
This is the MAC address of your ethernet shield. You need to change the numbers in the brackets to the ones written on your shield on the sticky label attached to the shield (newer shields). Apparently it may well work OK even if you don't bother changing it but this is what I did anyway.

2) There is a line of code:  byte server[ ] = {199, 59, 148, 10};          This is the ip address of the Twitter server in California. In the original instructable on which this part is based they had a different number here which I could not get to work. I googled until I found this number which DOES work (April 2011). Not sure if it changes occasionally, this is why I point this out.


3) There is a line of code below this as follows:  Twitter twitter("enormous long string of text and numbers");
You need to insert your twitter TOKEN that you have just carefully obtained and saved somewhere into this code between the " and "

4) In the Void loop of the arduino sketch I have highlighted an area where you have to insert 9 digits into a statement.
client.println(GET http://www.twitter.com etc etc
You must insert the RSS of your twitter account you have just created into this line of code so your 9 digits replace the ones that are there now. You will have obtained your RSS 9 digit number earlier on and written it down safely.


5) FINALLY(!) Scroll down towards the bottom of the sketch and you will find a section that starts with
void transmittweet1 ( ) {  

It now says:
byte ip[ ] = {     This should be Ok as it is
byte gateway[ ] = {  Change these values to the values you wrote down earlier for your Gateway IP address
byte subnet[ ] = { 255, 255 etc       Change these values to the values you wrote down earlier for your Subnet address


HOORAY you have now finished modifying the Arduino sketch. All the above is also commented in the code so you can see where you need to insert the new numbers you have collected in the previous steps.

Compile it and save it and upload it to your Arduino.

Main problem may well be you have a library missing that you have to go back and find, if it doesn't compile right away. If a library is missing it will tell you in the error code.

Step 13: Connections


In photo I have the following

Ethernet shield connected on top of Arduino

Arduino connected temporarily to a laptop so I can upload sketch to arduino.

Ethernet cable between Ethernet shield and my router

Power supply to Arduino.

The serial-LCD display is connected by 4 wires:
+5V from arduino to display to power it
A wire from display to GND on arduino
Tx and Rx are Digital output pins 2 and 3

REMEMBER: IF YOU JUST WANT TO TURN THE OUTPUT PINS ON AND OFF REMOTELY, AND HAVE SENSOR DATA SENT TO TWITTER, YOU DON'T NECESSARILY HAVE TO HAVE THE LCD SCREEN PRESENT, the sketch will run fine, just don't bother connecting up a serial-LCD module.

NOTE: Before you embark on this project, it is worth checking your LCD display is connected up and working OK with your arduino. There are examples of serial LCD displays and how to connect them on Arduino website. Go through one of these tutorials with their test code and check it works. Usual problem is that Rx and Tx are crossed over, try them the other way around.
This is the exact serial-LCD module I used in this instructable:
http://www.robot-electronics.co.uk/acatalog/LCD_Displays.html

Finally I have some LED's to show the status of my digital output pins that I am trying to control with messages sent from Twitter.

They are attached to Digital Output Pins 4,5,6,7 (via suitable resistors). If you don't know what resistor to use (but you do know what LED you have bought) you can use any of a number of online calculators such as this one.
http://led.linear1.org/1led.wiz
Just set the Voltage to 5 Volts.

Another LED is on Pin 9 which simply flashes when the Arduino is waiting 1 minute before looking for the next Twitter message.

Step 14: Connections to Router

This photo shows the other end of the ethernet cable going from ethernet shield into back of your router box

NOTE: Your main PC does not have to be turned on, only the router has to be working once this has all been set up.


Step 15: Arduino Sends Data to Twitter

Here the Arduino has read the value on Analog pin 2 (currently 1023 on the scale of 0-1023)and is sending it to your twitter page:

Step 16: Arduino Data to Twitter

Here is the data appearing on the Twitter page.

You can also see that the person using Twitter has sent a data file (beginning with a D so the sketch "knows" a data twitter is coming) back to the arduino to turn on the second and fourth LED's in the sequence of 4 (Pins 5 and 7).

Step 17: Arduino Responds to the Data Twitter

Here you can see the pins coming on as a response to the data twitter that the user has just sent.

Remember, the tweeter has added a few letters to end of the data tweet so it is not the same as previous ones (which Twitter would refuse to send again)

Also, if you send a text tweet to the Arduino, in case a human being is around nearby and you want to send them a message, then that is OK too.
Probably best not to start your text tweet with a capital "D"

Step 18: Deleting Tweets

You will end up with a lot of tweets after a while!

This is how you delete a tweet

Step 19: Getting RSS Feed (alternative Method) (1)

The option to "Select old Twitter" display format (with RSS feed icon in that page) is going soon.

This will describe how you get your Twitter RSS feed number from the new front page (where there is NOT an RSS feed icon you can just click on).

Step 1:
In your internet browser somewhere there should be an RSS feed icon.
Click on it..........

Step 20: Getting RSS Feed (alternative Method) (2)

It now asks you if you want to subscribe to this feed.

Click on "subscribe to this feed" option

Step 21: Getting RSS Feed (alternative Method) (3)

It now asks you if you want to subscribe, - you do!

Step 22: Getting RSS Feed (alternative Method) (4)

Now you are given a "view feed properties" option bottom right of this pop up box, click on it....

Step 23: Getting RSS Feed (alternative Method) (5)

Finally, the properties box comes up and inside is your 9 digit Twitter RSS feed code, write it down somewhere to insert into the Arduino sketch.

Share

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
  • Gluten Free Challenge

    Gluten Free Challenge
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

14 Comments

Is there any other method to find my twitter rss code? Since twitter has been updated and none of these methods worked for me.

Hi,

I’m irinakim and I’m work in the Wiznet.

Thank you for using our product.

We are collecting so much data using our product.

And I will post the this project on our Web site.( http://wiznetmuseum.com)

Can I post your product on our Web site?

Thanks been using it for awhile. Works great! kinda a noob on coding. Can you asisst in helping me get the code to update more than 1 sensor. I have a dallas temp sensor working currently. The 4 control pins run things on my aquarium. Want to be able tosee more sensor data on twitter and then be able to react. thanks Kenny

I'm a noob but got this partially working. I decided to skip the lcd portion so that I can get the basic sketch working. It compiled without any problem. I monitor the twitter feed and get the expected "Analog Pin 1 reading = [0] 3365" ( I have pin 1 shorted. I get 1023 for 5V as expected). I can see the led hooked to pin 9 blink as expected. I decided to turn on the serial monitor on the pc to monitor the serial out. I get something like this:

OKOK.
Connection failed
Disconnected
TEXT TWEET COMING
9206
connecting ...
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Vary: Accept-Encoding
Date: Fri, 12 Oct 2012 03:13:02 GMT
Server: Google Frontend

The number after "TEXT TWEET COMING" corresponds to the random number in the twitter feed. When I tweet D1000 or other combinations, none of the leds on pins 4,5,6 or 7 light up.

It is definitely sending the analog value to the twitter feed but I can't seem to control the 4 digital output pins.

Any help would be appreciated.

Great UploD Mn. Kinda a noob here. My code keeps hangin up. For for awile and keeps hanging. Any ideas?

I sometimes get this error when trying to read the tweets.

Rate limit exceeded. Clients may not make more than 150 requests per hour

How to handle this problem??

hi, i wanna ask something.. instead of using arduino, is it possible if i use just the atmega8 to build this project? one more thing, i'm a very noob when it comes to programming.. so, could somebody please help me design this project step by step (i know that there is already step by step guide given by the project owner but the truth is i really do not understand especially the codng part).. i would really appreciate if somebody could help me.. thanks in advance..

Hi,
I love tis instructable very much and used it as basis of some projects I did.
Unfortunaly it doesn't compile on the Arduino 1.0 IDE.

What do I need to do to make it work under arduino 1.0

Addie

I just used your project as a templet to control relay for my Xmas tree. I turned off the tweet back and im running it with out a LDC screen and im loving it :D Thanks a lot for putting such a nice ible together

woow.. thanks for sharing :)

I jut tried this, but I got problem to change twitter to old version eventhougt I clicked my username on the top right..
so How I can look RSS feed??
Is it anyway else?