This is my first post on Arduino that I purchased recently. In this project I am capturing temperature information using LM 35 sensor and tweeting it through a .net program.
This is my how my weather station looks like in twitter:
To set this up you will need following hardware and software
1. Arduino Uno Board, three wires, bread board and a USB cable
2. LM35
Software :
1. Visual Studio (express will also work)
2. TweetSharp library
Essentially you need these things to talk with each other.
1. Setting up LM35 sensor on Arduino board.
2. Arduino program that writes to serial port.
3. .Net program that reads from serial port.
4. TweetSharp library to tweet the temperature information.
I would say implementing above three was not difficult, most of the code is already available as a form of sample code in web.
Let me try to explain step by step in case you any one wants to try this:
Setting up LM35 sensor on Arduino Board
A search on web and you will find lot of articles showing how to set up LM35 on breadboard. This is how I set this up.
You need three wires, one for connecting to ground in Arduino Board. Second to 5Volt voltage input on Arduino Board and third for connecting to Analog Input.
Arduino Program to write temperature to serial port
I used following program to write temperature information to serial port, its easy to understand and calculates value in both Celsius and Farenheit.
http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/
.Net program to read serial port data
System.IO.Ports.SerialPorts is the class which reads serial data. If you are using Winforms then you can simply drag and drop the SerialPort from toolbox. This is how you can use serial port to read data
a) Declare the serial port
private System.IO.Ports.SerialPort serialPort1;
b) Initialize
private void InitializeSerialPort()
{
this.serialPort1 = new System.IO.Ports.SerialPort();
serialPort1.PortName = “COM7”; // In my system Arduino is on COM7 port
serialPort1.BaudRate = 9600;
serialPort1.Open();
this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived);
}
c) Read the serial port data in data received event
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
temperatureReceived = serialPort1.ReadLine();
}
Tweeting the temperature to your twitter account
If you are able to read data through serial port then next thing to do is to tweet your results. These are the steps required to set up twiiter application and development environment.
1. Login to you twitter account in twitter developer portal
http://dev.twitter.com/
2. Go to my applications and create new applications
3. Fill in the required information to create the application
4. On the details page click on “Create my access token”
because twitter requires OAuth authntication you need to copy paste values from settings screen to appsettings of you application.
<appSettings>
<!–Keys for OAuth authenticiation–>
<add key=”ConsumerKey” value=”ConsumerKey”/>
<add key=”ConsumerSecret” value=”ConsumerSecretValue”/>
<add key=”AccessToken” value=”AccessToken”/>
<add key=”AccessTokenSecret” value=”AccessTokenSecret”/>
</appSettings>
There are lot of libraries available to tweet using .net, after trying couple of libraries I found TweetSharp to be very straight forward. Here is the link to download TweetSharp
https://github.com/danielcrenna/tweetsharp
I followed this blog to set up the c# code required for tweeting.
http://geekswithblogs.net/TarunArora/archive/2011/06/19/tfs-2010-sdk-integrating-twitter-with-tfs-programmatically.aspx
Once you have set up the source the last thing to do is tweet the temperature value, here is the code.
private void Tweet(string currentTemperature)
{
twitterService = TwitterProxy.ConnectToTwitter();
var result = twitterService.SendTweet(String.Format(“The current temperature in my home is {0} degree celsius, – Bangalore, India : {1}”,
currentTemperature, DateTime.Now));
}
After doing this you should see the temperature posted on your twitter account, you can modify this program to send direct message instead of tweeting.
Possibilities
I feel this is a basic and a good project for getting started with Arduino and your first step to InternetOfThings. These are various ways I can think off to enhance it, if you have some more geeky ideas, I would love to hear them.
1. Plot a graph for temperature changes and post it live on web.
2. Make Arduino Wireless and let it talk to a system directly.
3. Attach a display to Arduino to show the current temperature.
4.Once the temperature has reached below a certain limit (<24), make sounds, blink LED’s… etc.
5. Display location information by converting your IP address to location or you can also attach a GPS with Arduino.