3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Use Twitter to control Arduino Uno via Visual Basic 2010

Use Twitter to control Arduino Uno via Visual Basic 2010
«
  • twitterVBarduino.png
  • twitter app create 2b.png
  • twitter app create.png
  • twitter app create 2.png
  • twitter app create 3.png
  • twitter app create 4.png
  • twitter app create 5.png
  • twitter app create 8.png
  • twitter app create 6.png
  • twitter app create 7.png
  • last photo ←
»
UPDATE Mar 29,2012: The TwitterVB libraries once published on http://twittervb.codeplex.com have been unpublished by their developers.  A while ago, I was hoping to spend time to update this guide for an alternative solution. I have not found the time as my project backlog is constantly increasing and my workload is not decreasing. Some users say it's possible to find TwitterVB floating somewhere in cyberspace. 

This guide is a skeletal VB/Sketch app that shows how a Tweet can control Arduino Uno using Visual Basic 2010 and Arduino Sketch.

No net shield is needed for this. Just a PC with internet connection and Arduino Uno. 

So you can develop apps based on this utility to send a tweet with a special keyword from anywhere in the world, and the PC running this app or your mix of the app will monitor and intercept it then send it to the Arduino Uno to turn a light on, shut down a PC, turn the music on, etc.  

The app presents the user with a form to enter the name of the Twitter user ID to monitor and the keyword/code in the Twitter status line to look for, as well as the the COM port number used to communicate with Arduino, and whether to turn pin 13 on or off. 

Most of this code is mixed from work of others such as DWRoelands (http://twittervb.codeplex.com/) and Jason (http://jdsitecare.com/1041/twitter-api-vb)


These are the main steps I followed to accomplish this integration:

- Create a Twitter account. You will need a Twitter user ID to register a Twitter application: http://www.twitter.com

- Register a Twitter App: https://dev.twitter.com/apps/new (make sure you create it as Read/Write). When done, twitter will provide you with info that you will need to plug into the VB code to allow it to access your Twitter account/status. 

- Download & install Visual Basic 2010 Express: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express

- Download the TwitterVB.dll library (TwitterVB-3.0) : http://twittervb.codeplex.com

- Create a new Visual Basic project and change Advanced Compile Option's Target .NET Framework from 4.0 to 3.5. Then add the SerialPort control to Form1

- Connect your PC to Arduino Uno

- Connect your PC to the internet

- Use the VB 2010 and Sketch code I supplied to test integration. You can then change it to suit your requirements.

- Run twitter2VB2arduino and fill form then click Monitor Twitter button. The VB app will search Twitter and if a match is found it 
will send either 1 or 0 (depends on your selection) over serial port to Arduino Uno to turn PIN 13 on or off. 

NOTE:  Efficiency of VB and Sketch code was compromised in pursuit of simplicity. I am sure there are better ways of doing this Instructable so please feel free to share your thoughts. 

--------------------- Arduino Uno Sketch ----------------------------------------

// Mixed by: Hazim Bitar and based on many examples
// NOTE: For some reason if I keep the Serial Monitor open, I get a COM port access denied error on VB app

int valPin = 13; 

void setup() {
  Serial.begin(9600); // COM port speed 
  pinMode(valPin, OUTPUT);
}

void loop(){
  while (Serial.available() == 0); // keep looping if nothing is sent over serial port
  int valAct = Serial.read() - '0'; // if there's data read it 
  Serial.print(valAct);

  if (valAct == 1) { // test for 1
digitalWrite(valPin, HIGH); // turn on LED
}
else if (valAct == 0) // test for command 0
{
digitalWrite(valPin, LOW); // turn off LED
}
else
{
// do nothing
}
Serial.flush(); // clear serial port
}
  
---------------- END OF SKETCH --------------------------------------


--------------------START OF VB 2010 CODE ------------------------
' Mixed by Hazim Bitar / email: techbitar {@} gmail {dot} com / date: 24 Sep 2011
' Based on the good work of DWRoelands http://www.codeplex.com/site/users/view/DWRoelands and to Jason http://jdsitecare.com/1041/twitter-api-vb/

Imports TwitterVB2
Imports System.IO
Imports System.IO.Ports
Imports System.Threading

Public Class Form1
    Dim twitter As New TwitterAPI
    Dim PinCommand As String = "z"
    

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        s.Close()
        s.PortName = "com" + txtCOM.Text
        s.BaudRate = 9600
        s.DataBits = 8
        s.Parity = Parity.None
        s.StopBits = StopBits.One
        s.Handshake = Handshake.None
        s.Encoding = System.Text.Encoding.Default

        For Each Tweet As TwitterStatus In twitter.HomeTimeline
            'txtTweets.AppendText(Tweet.User.ScreenName + vbNewLine + Tweet.Text + vbNewLine + Str(Tweet.ID) + vbNewLine + Tweet.CreatedAt + vbNewLine + vbNewLine)
            If Trim(LCase(Tweet.Text)) = Trim(LCase(txtCommand.Text)) And LCase(Tweet.User.ScreenName) = LCase(Trim(txtUser.Text)) Then
                TweetCreated = Tweet.CreatedAt
                If btnOFF.Checked = True Then
                    PinCommand = "0"
                    s.Open()
                    s.Write(PinCommand)
                    s.Close()
                ElseIf btnON.Checked = True Then
                    PinCommand = "1"
                    s.Open()
                    s.Write(PinCommand)
                    s.Close()
                End If
                 ' DEBUG: MsgBox(txtCommand.Text + " | " + txtCOM.Text + " | " + txtPIN.Text + " | " + txtUser.Text + " | " + PinCommand + " | " + TweetCreated)
                Exit For
            End If
        Next
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         twitter.AuthenticateWith("Your ConsumerKey", "Your ConsumerSecret", "Your TokenKey", "Your TokenSecret")
        ' the above keys and tokens are generated by Twitter when you register your application

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub


End Class

-------------------------END OF VB CODE -----------------------------------
3 comments
Dec 8, 2011. 5:36 PMhightekrednek2396 says:
I'm not able to get the twittervb. The project hasnt been published yet and the one on googlecode is gone. so how did you get it?
Jan 8, 2012. 3:39 PMledone says:
Good thing I downloaded the DLL before it was removed. Good job with this instruction guide.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
33
Followers
18
Author:techbitar
Did I unplug the solder iron?