Archive by Author

Arduino Weather Station

21 Mar

After not doing any Arduino fiddling for quite a while I have finally started a small project again. I have made a small weather station for measuring temperature and humidity levels in my home.

IMAG0092_2

The setup is based on an Arduino Uno with the standard Ethernet Shield (because it has an SD card reader) and a DHT-22 sensor that is connected as follows (following the docs):

  • Leg 1 (from the left) –> +5V
  • Leg 2 –> pin 2 (data input)
  • Leg 3 –> not connected
  • Leg 4 –> GND
  • 10k OHM resistor between +5V and data pin 2.

The code is pretty standard, a mixture of the SD library and DHT library code examples …  not really interesting. However, I have added a bit of code to calculate the dew point based on formulas I found on the web, which may be worth sharing here:

// Compute dew point (formula taken from here: http://www.wettermail.de/wetter/feuchte.html
// You need to include the math.h library

float temperature = 20.0; // Set to current temperature in *C (>= 0).
float humidity = 50.0; // Set to current % of relative humidity.

float a = 7.5; // For temperatures >= 0 *C.
float b = 237.3; // For temperatures >= 0 *C.

float sdd = 6.1078 * pow(10, (a * temperature) / (b + temperature));
float dd = humidity / 100 * sdd;
float v = log10(dd / 6.1078);

float dewpoint = b * v / (a – v);

So far the setup seems to work well, but the sensor readings regarding the temperature look a bit high (maybe influenced by the Arduino which gets warm over time … its probably better to place the sensor  away from the board, and not right on top of it).

Edit: In case you are interested, you can find the code of the project here: https://bitbucket.org/snippets/boden/xr746 (without the dewpoint computation).

Advertisements

How To Post To Status.net/Identi.ca From An Arduino

6 Oct

Just some brief notes on how to post status-updates to status.net from an Arduino with an ethernet shield. Status.net is an open source micro-blogging solution that is used for example by the Twitter alternative identi.ca (so it should work with identi.ca, too, but I have not tested it so far).

Posting to status.net is actually very straightforward. You just need to send a simple HTTP POST-request with your login credentials and the message you want to send (there are other optional parameters such as the source of the post or your geo-location, check the API description if you want to use those).

The message you want to send needs to be URL-encoded, which basically means that you have to exchange certain characters (!*'();:@&=+$,/?#[])with codes. For example, a whitespace becomes %20, so “This is a test” would become “This%20is%20a%20test”. Check this site to find out how to encode other characters.

Your login-credentials also need to be encoded, but this time as Base64. There are several websites that will enocode your credentials for you, check for example this site. Enter your credentials there in the form of username:password and you will get a result such as dXNlcm5hbWU6cGFzc3dvcmQ= which needs to be entered into the code. Obviously, username and password have to match an account at the server you are posting to.

If you got this, you are ready to go. Just start an Ethernet connection with your Arduino (using the Ethnernet library) to the IP address of your status.net server. You can find out how to use EthernetClient with Arduino here.

If the connection was initialized, perform the following HTTP request that is based on the examples described above:

client.println("POST /api/statuses/update.xml?status=This%20is%20a%20test&source=Arduino HTTP/1.0");
client.println("Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=");
client.println();

The first line defines the url of the statusnet api (the path may need to be adjusted to the correct url of your server), and adds the URL-encoded status message as well as the source of the post. The second line provides the basic HTTP authentification as a Base64 string. The third line sends an empty line to signal the server that the HTTP request is completed.

That should do the trick.