Thursday, April 25, 2013

Helping our Office Plant with an Arduino (Part 1)


I'm always searching for new ideas for nice and simple M2M or Internet of Things (IoT) examples. A month ago I had a good idea. I came to our office and saw the plant next to my desk and it only had a few leaves. Maybe we watered this plant not often enough and I wanted to change it. Wouldn't it be nice if the plant waters itself or at least sends a message?

How can I measure the soil moisture?

I thought about this idea and my first question was, how I can measure the soil moisture with simple tools. Luckily the answer was only one google search away. I just had to stick two nails or other long and thin metal sticks into the soil and connect it with an Arduino like this:
moisture sensor circuit

Because I didn't had any nails in the office, I used two paper clips. My colleagues looked a little bit confused, after I connected the Arduino with our dying plant. This was my first try:
 

And with a few lines of code, I got my first readings.
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.print("Soil moisture: ");
  Serial.println(analogRead(A0));
  delay(1000);
}

Until now, it is nothing new. There are already some Arduino gardening examples on the internet. Also with light and temperature sensor or with pump which starts automatically when the soil is dry. There is something more needed for an M2M solution. I have to connect it somehow with a network.

Next Steps

In our office, we have some GBoards. These are Arduino based boards with a built-in GSM modem. This will help to connect it to the M2M Developer Platform, which is a cloud-based M2M application platform. Have a look at the M2M Developer Community which is part of Developer Garden. Here you can find the GBoard, the Developer Platform and some other interesting things about M2M and the Internet of Things.

My first M2M Demo

Target: 
Developing a simple energy control Demo with an M2M Development Kit, where a switch can be turned on and off via the internet.

Used Hardware:

For this demo the Cinterion EGS5 Development Kit and a simple switch, which can be switched via a RS232-port are used.

You don't need this swich. If you just want to test, you can simply connect a resistor and an LED to the port, like in the picture below.

The Software:
This demo consists of two parts. One part is the Java™ application on the module and the other part is the Website and a simple text file on a server.
A Java™ Application is running inside the Module. If the program is started, some static variables (e.g. destination host and connection profile) will be initialized. Then, every ten seconds, a loop is executed. In this loop, the Http connection to the server is set up and as input stream it receives the bytes of a text file. These bytes will be converted to characters and combined to a string. If this string is “on”, the COM-port is opened and if this string is “off”, the port will be closed. Any other string will close the port if it is opened and then the application will be terminated.

The Website is simple. It loads the text file and look up the word, which is in this file. Then the labeling of a button and a picture of a light are automatically adapted. When the button is clicked, it changes the word in the text file to the opposite (from “on” to “off” or vice versa). At the same time the button and the picture are updated again.

Picture of the DeveloperKit with an LED