OpenSprinkler Pi v1.02 Released

I’ve made a minor update to OpenSprinkler Pi (OSPi), and the new version v1.02 has improved design of the separation pillars in order to make use of the screw holes available on Raspberry Pi rev. 2. See the picture below:
This way, the Raspberry Pi rev. 2 can be more securely attached to the OSPi even with just two screws.

If you own a Raspberry Pi rev. 1 instead, don’t worry, you can still attach it to OSPi using the two edge screws (see the picture on the right below), in the same way as the original OSPi. To do so, you will need to move one of the separation pillars. See the picture on the left below (sorry, the arrow is pointing in the reverse direction).


So in sum, the updated version OSPi v1.02 allows you to make better use of the screws holes available on RPi rev. 2 while still being compatible with RPi rev. 1.

Cheap 16×2 LCD with LED Back light

Recently I was looking for a cheap 16×2 LCD, and I found several interesting models on eBay that come with great price. I purchased one with blue backlight. The total is only $3.49 including shipping. The product was shipped from Hong Kong, so it took about 2 weeks to arrive. Here are two images of the front and the back:

The model number is 1602a and the spec is easy to find online by searching the model number. It’s HD44780 compatible, so it can work directly with the Arduino LiquidCrystal library. The blue LED backlight looks quite pleasant. Here is an example:

One downside is that the back LED is a bit noticeable (see the glow on the right edge of the display); also, the text will be almost completely invisible if the LED is turned off, so the LED has to remain on, consuming more power.

Making it work with Arduino is straightforward by following the LiquidCrystal example. I made small changes to the pin assignment. Here is what I did: LCD RS, Enable, D4, D5, D5, D6 pins are connected to Arduino pin 12, 11, 8, 7, 6, 5 respectively. Normally the display contrast (V0) pin of the LCD is connected to a potentiometer in order to adjust the contrast voltage. After some experiment, I found that the desirable voltage is about 0.65V, which can be supplied by the forward bias voltage of a standard diode, such as 1N4148.

In order to control the back LED brightness, I made use of a transistor (2N3904) and Arduino’s PWM (pulse width modulation) to adjust the effective voltage supplied to the LED. The transistor serves as a current sink, and its base is connected to Arduino pin 10 to apply PWM control. This is very standard design, refer to the schematic below. With this, I can easily control the brightness of the backlight. Just to demonstrate it, I wrote a simple program based on the Scroll example provided in Arduino. The program scrolls text left and right, meanwhile I use a timer interrupt to brighten and dim the backlight. See the video below.

Some ghosting artifacts are noticeable as the words move left and right. The video probably exemplified them, the actual LCD looks better than the video.

Update: It’s ok to connect Arduino pin 10 directly with LED- or LED+ to supply the PWM signal without using a transistor. Arduino’s I/O pins can source or sink more than 20mA of current, which is sufficient to drive the backlight LED. Other microcontrollers might not be able to do so directly from their I/O pins.

In summary, this is an decent and inexpensive LCD, which works nicely with Arduino. Right now it occupies 7 Arduino pins (1 of them has to support PWM), but this number can be reduced to 3 by using a shift register. The schematic and source code for the example program are attached below. Comments and suggestions are welcome!

Download Arduino source code lcd1602a.pde.


Meet the Arduino WaterValveShield

After finishing the previous minty water valve controller, I decided to make it an Arduino shield. This way, I can easily stack it onto other shields and extend its capability. I also added a few input buttons, and a DS1337 real-time clock, so that it can keep up with accurate time. Now the circuit has become much smaller, so I can’t produce it with home-made PCB any more(sadly…). Instead, I ordered professionally made PCBs from Laen, and here you are, meet the Arduino WaterValveShield!

PCB board:

Components soldered:

Close-up view:

Connected to a serial LCD display

The schematic:

You can download Eagle schematic and PCB design here. Feel free to use it and/or modify it, but be kind to give me some credit for it 🙂

Parts list with Mouser/Digi-key links: 

As for sketch code, refer to my previous posts for code to control the valve and read input buttons. To interface with DS1337 RTC, I use this excellent RTC library.

Next steps:

Multiple button inputs using Arduino analog pin

At times I feel short of digital pins on the Arduino to handle multiple button inputs. Here is an easy way to use 1 analog pin to handle many input buttons. The way it works is very straightforward: use a resistor network as voltage dividers, and then let each button feed a different voltage to the analog pin. Thus by detecting the voltage we can tell which button has been pressed.


Download the corresponding Arduino sketch code.

As a downside, it cannot handle simultaneous button presses. To do that, one could potentially use resistors at doubly increasing resistance (1K, 2K, 4K, 8K…). Hence by checking the detected voltage, we should be able to tell which buttons are pressed simultaneously.

Minty Water Valve Controller

I’ve always been fascinated by minty projects — circuits that fit neatly into a mint tin. There is an entire webpage on Make that documents such projects. For a long time I’ve been thinking of my own minty project: what can I build in a small mint tin?

Recently an idea came up: I had a new lawn installed in my backyard a couple of weeks ago, and I needed to start watering the lawn regularly everyday. I was looking into some automatic watering option like this one, but it provides limited functionality and does not suit my need. So I thought that perhaps I can build a water valve controller myself; and best of all, I can fit the circuits entirely in a mint tin. Voila, here comes my minty water valve controller!

Before describing how to build it, let me highlight some features of it:

  • A single li-poly rechargeable battery drives the circuit and a 24v latch solenoid
  • An Arduino pro mini programs the valve control
  • An RF module enables wireless control
  • Above all, it fits neatly into a mint tin

Here is a video demonstrating the controller in action:

The Design

For the water valve, I picked the Orbit yard watering valve. It’s widely available in home improvement stores, and it is cheap. It has two pins: applying +24v opens the valve, and -24v closes the valve. It uses a latch solenoid, drawing power only when you open or close it. This makes it very power efficient.

To use a single li-poly battery to drive the valve, I needed a voltage booster to raise the 3.6v provided by the battery to 24v momentarily before connecting to the valve solenoid. For this I chose an LT1303 DC/DC step-up converter, but any similar converter will do as well. Switching between applying +24v or -24v to the solenoid is achieved by using some MOSFETs. I can’t use small BJT transistors because they won’t handle the large impulse current through the solenoid (as high as 5A). Darlington transistor would work but I prefer MOSFETS for their power efficiency.

To program the valve, I use an Arduino pro mini. It’s adorably tiny and perfect for a mint tin project. I initially wanted to use the 3.3v/8Mhz version, as it can be directly powered by the 3.6v battery. But later I found that the wireless RF module only works with 5v anyways, so in the end I went with the 5v/16Mhz pro mini. This requires another voltage booster to raise the 3.6v battery to 5v. Fortunately I didn’t have to build another voltage booster for it; instead, I reused an existing minty boost which I soldered a while ago. I took off the tiny circuit board from it. Again, it fits cutely inside the space-limited mint tin.

The wireless module I used is an RF link 434MHz transmitter and receiver from SparkFun. They are small and easy to use. In particular, the receiver is quite thin and can sit comfortably along one side of the mint tin.

The schematic of the circuit is included below:

Parts List

  • LT1303 DC/DC step-up converter
  • AOP605 complementary MOSFETs (each contains 1 N-channel and 1 P-channel)
  • 2N2222 BJT transistor
  • 1N5817 and 1N4001 diodes
  • RF link 434MHz transmitter and receiver
  • Li-poly rechargeable battery
  • Various resistors, capacitors, and inductor as specified in the schematic.
  • (note that the 2200uF capacitor C2 must be rated 25v or above)

The circuit directly draws power from the 3.6v battery. I use the Arduino pin 6 to control the shutdown pin of LT1303. This way, I turn on the voltage booster only when I need to open or close the valve. The voltage booster outputs roughly 24.4v.

Arduino pin 8 and 9 are used to control opening or closing of the solenoid. Both pins are set to low at start. Next, setting pin 8 to high causes +24v to apply on the solenoid, opening the valve; on the contrary, setting pin 9 to high causes -24v to apply, closing the valve. Don’t try to set both pins to high at the same time, as it may short the circuit and cause damage.

Both the Arduino and the RF receiver are powered by the 5v output from minty boost. The data pin of the RF receiver is connected to Arduino pin 9 (which supports PWM).


I soldered the initial prototype on a perf board. I made a mistake in connecting the MOSFET IC pins. This produced a spark and instantly fried the IC. Well, careful playing with 24v. After fixing the issue, the circuit worked like a charm.

But the perf board looks a bit ugly and is too bulky for the mint tin, so I decided to design a custom PCB using Eagle CAD. This is the first PCB I’ve ever designed and made, so I felt quite a bit excited. I used the toner transfer method to produce the PCB. Playing with etching chemicals was not very pleasant. Here are two snapshots of the PCB:


I picked some mint tin cans from Whole Foods. They have beautiful cover images. Assembling everything to the tin proved to be tricky than I thought: it’s not that I can’t fit everything, but because working with a bunch of wires and fixing buttons to the side of the can in such a small space made me feel like sowing embroidery. Tweezers are absolutely must-have tools. Also, I puts lots of electric tapes inside the tin and on various circuit parts to cover exposed area. You don’t want to accidentally short wires and cause trouble. Finally, I used hot glue sparingly to fix parts together. Below are snapshots of the parts before and after they are assembled into the tin:

Additionally, I added a power switch on the front and two buttons on the right to allow for manual control of the valve. Everything packs neatly!


Here is an annotated snapshot showing where each part is located:


As the tin is not water-proof, I use a zipper plastic bag together with a paper clamp to seal it. I built a simple RF transmitter circuit on a breadboard to test the wireless control. It did work, but the range is currently limited to about 5 meters. I attribute this to the low voltage (3.6v battery) I used to power the transmitter. I am sure using 12v will increase the range a lot.

The whole circuit is reasonably power efficient. I’ve run it for two days and it is still working. The battery I use is a 900mAh rechargeable battery. A nice feature I would love to have in the future is to have it solar powered. This will completely eliminate the need to recharge the battery manually.

There are currently plenty of pins left on the Arduino unused. This provides some space to possibly control more valves using the same Arduino. But I am unsure if everything can still fit neatly in a mint tin anymore. Perhaps surface mounts are the way to go.

I haven’t programmed the Arduino to timer control the valve yet, but this should be straightforward. Some more advanced features can be included, such as installing a rain sensor to delay watering when it rains; or even better, use weather reports from online websites for intelligent watering! The wireless feature of the controller makes many options possible.

Code and Schematic Files

The Arduino code, Eagle CAD schematic/board files are attached below. Enjoy!