Watering Plants with .NET


I first became interested in microcontrollers after seeing a presentation by Ian Lee at the Nashville .NET User Group. If you don't know, a microcontroller is basically a programmable chip for controlling electronic circuits. Electrical engineers have been using microcontrollers like BASIC Stamp and PIC in their circuits for decades, but the Arduino has made them more accessible to consumers and hobbyists. The Arduino Uno is a development board containing an Atmel microcontroller chip as well as some supporting peripherals such USB and Ethernet ports. Arduino also provides an IDE that allows you to program the device using a C-like language.

There are now even microcontrollers targeting .NET developers. These allow you to program them in C# using the .NET Micro Framework. NETMF contains a subset of the .NET class libraries and adds its own APIs for microcontroller-related functionality. Having lived comfortably in a bubble of Microsoft frameworks and managed code for a number of years, these seemed like an ideal starting point for me - I could explore the world of microcontrollers without even leaving Visual Studio!

There are currently two lines of .NET microcontrollers: Netduino and Fez. The original Netduino uses an Arduino-like form factor and headers meaning that it is theoretically compatible with the wide range of Arduino shields (extension boards) already in existence. The Fez uses a different type of extension socket based the Gadgeteer standard, which is supported by Microsoft. For my first project, I decided to go with the Fez.


I was going on a couple of week-long trips and wanted a way to water my patio tomato plants while I was away. My basic idea was to use a microcontroller connected to small electric pumps to transfer water from storage buckets into my tomato pots once a day.

Here is my list of materials:

One nice thing about Gadgeteer is that it provides you with a visual design surface on which to lay out your components. It then generates a class containing references to all the component instances so that you do not need to create and configure them yourself. Here is the design for my relatively simple project:

Gadgeteer Board

I had two plants, so I used one relay to control each water pump. The code was pretty simple and looked similar to the following:

while (true)  
    // Turn on first relay for 40 secods
    _relays.Relay1 = true;
    _relays.Relay1 = false;

    // Turn on second relay for 40 seconds
    _relays.Relay2 = true;
    _relays.Relay2 = false;

    // Wait for a day

One challenge in any type of project like this is getting components that do what you want. The biggest unknown in this project was the water pumps. I had difficulty locating a suitable pump (most of the ones I found were designed for fountains or aquariums and were AC-powered), but the ones I ordered off Amazon (with fingers crossed) worked surprisingly well. My only regret was that due to the varying diameters of the inlets and outlets, I couldn’t connect them in series for greater pumping power.

To drive the pumps, I could have connected them to another DC adapter, but I was paranoid about having water-immersed components connected to an outlet while I was away from home. Fortunately, I found a 12-volt lantern battery from Rayovak was readily able supply the level of current required by the pumps.

Here is a short video I made of the system in action:


Initially I had high hopes for this project. I was going to leverage the HTTP API of the NETMF to expose a web interface that I could use to monitor the system while I was away. Unfortunately, I had decided to use the newer Fez Hydra, and it so happened that the drivers for its associated ENC28 ethernet module were not ready for prime time, thus my plans were thwarted. So if you decided to invest in a Fez board, you might want to go with an older model like the Spider until the issues with the Hydra are resolved.

The Gadgeteer platform provides a nice turnkey solution to getting a simple project up and running quickly. However, if you want to interface a controller with your own circuits, you might want to look at a board with Arduino-style headers, such as the original Netduino or the Fez Cerbuino. That way you can use jumper wires to connect the device directly to your breadboard.

Being able to use .NET and C# to program the microcontroller is a nice amenity if you come from that background. However, if your project is just toggling relays or something like that then you probably don’t really need the full power of .NET. In that case you may want to look into the Arduino, since it has a larger community around it. Another advantage of the Arduino is that its $5 DIP-style Atmel chip can be easily used independently of the Arduino board by sticking it on a breadboard, custom PCB, etc. Finally, with the release of the Raspberry Pi, you can now get an entire computer running Linux and equipped with GPIOs for about $30. I may just opt use the Pi as my "microcontroller" in future projects, since it seems like a very inexpensive and capable device.

Luke Sandell

Read more posts by this author.

comments powered by Disqus