Over time I’ve received some questions regarding the hardware design of OpenSprinkler. Here are some common questions and my answers:
Why using a switching regulator?
Since OpenSprinkler uses a single power supply (i.e. 24VAC sprinkler transformer), it is necessary to step down 24VAC to 5VDC and 3.3VDC in order to provide power to the circuit. The simplest and most common way is to use a 7805 linear regulator. But here is a catch: due to the relatively high current consumption of the ENC28J60 Ethernet controller, the whole circuit draws about 150 to 180mA current during operation. Using a linear regulator in this case will cause a lot of power waste. Specifically, (24-5) * 0.18 = 3.42 Watt will be wasted on heat due to the voltage conversion. This is pretty bad. That’s why I made the conscious decision to use a switching regulator to achieve higher efficiency. The switching regulator in this case is estimated to have 75% efficiency, so the power waste is more like (5 * 0.18 / 75% – 5 * 0.18) = 0.3 Watt. Much better and green!
Why having both 5VDC and 3.3VDC supply voltages?
This is because the LCD requires 5V supply, and the rest of the circuit requires 3.3V. The microcontroller can work with both voltages, but the ENC28J60 Ethernet controller and the RFM12B transceiver require 3.3V. That’s why the circuit provides both 5VDC (VIN) and 3.3VDC (VCC).
Why using triacs to control solenoids? What about relays?
While a lot of other sprinkler control circuits found online use relays to switch solenoids, I made the conscious decision to adopt triacs. There are many reasons this is more preferable. First, triacs are semi-conductor components, so they are much smaller than relays, more durable and act much faster. Second, they are low-cost and significantly cheaper than relays. Third, they are also slightly more power efficient: each triac requires only 5 to 7 mA holding current to switch on solenoids, while relay coils often consume more current. In fact, a sophisticated design can use an AC triggering circuitry to trigger triacs only during zero crossings, further reducing the power consumption. All in all, triacs are great choices for switching low-voltage AC devices.
Why does OpenSprinkler v1.2 adopt a USBtiny programmer?
If you’ve noticed, the previous versions of OpenSprinkler relied on external FTDI programmer. That was designed to be compatible with standard Arduino and variants. The main advantage of FTDI is that it not only does re-programming, but also it is a USB-to-Serial converter, which allows the microcontroller to easily send and receive messages from your computer. However, it also has two main downsides. First, it is expensive: an FTDI programmer or cable can easily cost more than 15 bucks, and we don’t like to stock it due to the cost. Second, using FTDI requires a bootloader, which takes away some (512 bytes) program space from ATmega328. Therefore we have decided to go with an on-board USBtiny ISP programmer based on ATtiny45. We like this solution a lot better because this way every OpenSprinkler board has a built-in USB programmer, so you don’t need to worry about purchasing a programmer separately. It is low-cost and does not require a bootloader, so it’s a win-win choice.
The trip to Maker Faire Bay Area this year was a great success. This is the first time that I participated Maker Faire as a commercial maker. The two-day event was completely overwhelming to us. I was basically talking to people non-stop: showing demos, explaining technical details, outlining future plans, answering questions, and of course also accepting payments and handing out kits. It was a wonderful experience. I am really glad to have made new friends, many of them gave me generous comments, feedback, and encouragements. That’s the most fun part of the Maker Faire — connecting to people and discovering new ideas. Perhaps the only thing I felt sad about is not being able to go around and check other makers’ exhibits. We were so occupied at our own booth that I barely had any time to even get water. So tips for next time: bring a lot of water, and food too 🙂
(Above: picture at the Maker Happy Hour.)
So what’s happening with OpenSprinkler since Maker Faire? Well, first of all, fulfilling orders and responding to questions have taken a lot of my time. Then, I am really trying to focus and get some time to finish the new interval scheduling program, which I see as the most flexible program that can accommodate many different scheduling need. What has been bugging me is the issue that the newly added features require a lot of program memory space, and the small 32KB flash size of ATMEGA328 doesn’t leave me much to spare. Particularly, the webpages and javascripts are currently all stored in program memory space, and I’ve been playing around to find a way to offload them to somewhere else, such as the external EEPROM. Today, a solution finally came into my mind. While searching for ‘client side include’ (CSI), I realized that it is pretty simple to include, in an html file, a javascript that is stored on a remote server. For example, using:
allows me to include a large javascript file that exists on a remote server and thus does not have to be stored in the microcontroller’s program space. When you access a page on OpenSprinkler, the client (i.e. your browser) will retrieve the webpage automatically upon reading that line. Ah ha, a darn simple way to offload big java scripts from the microcontroller. Why didn’t I think about it before!
Of course the problem with this approach is that if the remote server is down, you can’t really do much. The probability of this happening is usually extremely small. But still, it is a good idea to put webpages related to the most essential functions on-board, while using the remotely stored javascripts for beautifying webpages etc. In any case, this provides a good way to make the precious program memory space available for adding new features.
Just to give you an idea of what’s happening, here are two snapshots of the new schedule webpages I am working on:
The idea is that you can define many ‘schedule items’, each of which consists of Time (which can be a weekly schedule, odd or even day schedule, or every N day schedule), selection of stations, start time, end time, interval, and duration (down to seconds). You can add as many such items as you want, subject to the EEPROM size. These pages are not looking beautiful yet, but with the trick mentioned above, they can potentially look much more fancy.
Something else I’ve been working on is reverse engineering RF signals sent from remote temperature and humidity sensors as well as wireless rain sensors. There are lots of these off-the-shelf remote sensing transmitters that you can buy at very competitive price in retail stores. These transmitters typically work in 434 MHz RF range. I’ve found a simple method to reverse engineer their RF signals, and I’ve successfully decoded data from a temperature and humidity sensor. Hopefully I will be able to figure out the rain sensor as well. It has been great fun, and I will devote a couple of posts soon to describe how I did it.
Update: check out the RFToy — an easy-to-use standalone gadget to control remote power sockets. Also, support for remote power sockets have been added to OpenSprinkler firmware 2.1.1.
Note: the RF transmitter used in this article is available for purchase in the shop page.
In a previous post I described a way to use an Arduino to interface with remote controlled power sockets. The idea was to make use of the original remote control, and a high-side transistor switch to simulate button presses. This approach is generic: you don’t need to know how the remote control signal is encoded, instead, just treat the remote control as a black box and simulate the button presses. However, the downside of this approach is that it requires soldering wires and components to the remote control, which is quite a bit of work.
Update: check out the RFToy — an easy-to-use standalone gadget to control remote power sockets. Also, support for remote power sockets have been added to OpenSprinkler firmware 2.1.1.
Recently, inspired by the JeeLabs KAKU remote switch article, I figured out a new way to interface with these remote power switches. The method published by JeeLabs uses an RFM12B transceiver, which is cool because my OpenSprinkler design has a reserved spot for RFM12B. Unfortunately after many experiments I was unable to get it to work with my switches. However, I did succeed by using a 433MHz RF transmitter purchased from SparkFun. So below I document the process of how I did it.
To begin, I took apart the remote control. The goal is to reverse engineering the signal sent from the remote control, so that I can use an Arduino to simulate the same signal. This will allow me to use a program to control the power sockets. The schematic of the remote control circuit can be found in the previous post. Basically it consists of an encoder IC (HT2262 or PT2262) and a 433MHz RF transmitter circuit.
By connecting an oscilloscope to the circuit I was able to analyze the signal patterns. Details can be found in the video attached at the end of this post. Below are the patterns I observed when button 1 is pressed (corresponding to power socket 1).
The signal consists of two basic patterns: a short HIGH followed by a long LOW, which I call a ‘0’ all together, and a long HIGH followed by a short LOW, which I call ‘1’. The long part is roughly 500us and the short part is roughly 160us (so it’s about a 3:1 ratio). Each signal sequence consists of 25 bits: the first 16 bits are always ‘0000 1111 0101 0101’, which I call the ‘signature’; and the next 8 bits are the ‘command’, which correspond to the index of the power socket; finally, there is always an ending ‘0’.
For example, the entire sequence to toggle socket 1 is
0000 1111 0101 0101 1100 0001 0
the entire sequence for socket 2 is:
0000 1111 0101 0101 0011 0001 0
and for socket 3 it is:
0000 1111 0101 0101 0000 1101 0
Again, a ‘1’ means a 500us HIGH followed by a 160us LOW, and a ‘0’ means a 160us HIGH followed by a 500us LOW. When a button is pressed, the sequence is repeated several times, for robustness I guess.
Interestingly, you can OR the command part in order to toggle two or three sockets at the same time. For example, the sequence below will simultaneously toggle socket 1 and 2:
0000 1111 0101 0101 1111 0001 0
Next, to simulate the remote control signal using an Arduino, I used a 434MHz RF transmitter from SparkFun. This transmitter has only 4 pins: Gnd, Vcc, Antenna, and Data. The data pin can be connected to any digital pin on the Arduino in order to send the control sequence as analyzed above.
For demonstration, I used Arduino pin 10 to send the control sequence through the Data pin. The connection is as follows: VCC->+5V, GND->GND, DATA->Digital 10, ANT->a short wire. The supply voltage for the RF transmitter can be anywhere between 1.5V to 12V. The higher the voltage, the longer the transmission range. Normally 5V should be good for at least 15-20 meters. If you want the highest range, use a +12V power adapter to power your Arduino, and connect the RF transmitter Vcc pin to the Arduino VIN pin. Alternatively, you can add a voltage boost converter to bump +5V to +12V.
Below you can download the Arduino program I wrote. The code should be easy to follow.
If you have a different remote controlled power switch, you can follow the same procedure to find out the control sequence, then modify the program accordingly. A video demo is provided below:
Note: the RF transmitter (434MHz) is available for purchase in the shop page.
Update 1: apparently if you look at the datasheet of PT2262, which I found a copy here, it explains how the encoding pattern is computed. The ‘signature’ part has to do with the status of each pin from A0 to A7 on PT2262 – whether the pin is connected to GND, VCC, or floating, and the ‘command’ part is determined by the status of each pin from D0 to D3. I compared the circuit with the datasheet and verified that the pattern I observed from the oscilloscope matches the calculation. Also, according to the datasheet and the resistor value I found on the remote control, it looks like the long delay should be about 400us and short delay 133us, which is a bit different from the 500us and 160us observed from the oscilloscope. Also, the ending ‘0’ in my sequence turns out to be a ‘sync’ bit, which is 133us high followed by 4200us low. The fact that my original sketch has worked means there is a some level of tolerance in the timings. So they do not have to be highly accurate.
Update 2: new version of remote control. A reader of this post, Chuck, sent me a question that the sketch doesn’t seem to work with his remote control. After researching this issue, we found that the new version of the remote has changed to use SMT components and also has changed the coding pattern. Chuck sent me an image of the back of the PCB. From the image and the datasheet of PT2262, I figured out the new coding pattern. Basically, the ‘signature’ part of the code has been changed from
0000 1111 0101 0101
to
1101 0111 0101 0101
More technically, the coding pattern can be derived from the connections of Pins 0-7 of PT2262. In the newer version (from the PCB image on the left), the first 4 pins are connected as HIGH, FLOAT, FLOAT, HIGH, whereas the older version is connected as LOW, LOW, HIGH, HIGH. Here HIGH means connected to Vcc, LOW means connected to Ground, FLOAT means unconnected. Taking a look at the datasheet, you can easily figure out the actual code: LOW -> 00, HIGH -> 11, FLOAT: 01.
Chuck sent me his modified code, which you can download here.
I went to a local cafe for brunch today, and I couldn’t be more delighted to see this poster at the cafe:
So is this where the name ‘Arduino’ came from? Not really. According to Wikipedia, the name of the open-source microcontroller Arduino comes from the following:
Founders Massimo Banzi and David Cuartielles named the project after Arduin of Ivrea, the main historical character of the town.[8] “Arduino” is an Italian masculine first name, meaning “strong friend”. The English version of the name is “Hardwin”.[9]
The poster is actually an advertising poster made by Italian artist Leonetto Cappiello. The painting was done in 1922 for La Victoria Arduino. There are apparently multiple posters, which you can find here. In any case, a pleasant surprise to find the name of my friend ‘Arduino’ on the poster 🙂
After several months of hard work, my first ‘serious’ Arduino-based electronics project is up on the project page now. Check out the OpenSprinkler – An Open-Source Sprinkler Valve Controller. This is a collaboration between me and Chris Anderson (editor-in-chief of Wired Magazine). A video demo is included below. For details and how to order a kit, please refer to the project page.
Update: check out the RFToy — an easy-to-use standalone gadget to control remote power sockets. Also, support for remote power sockets have been added to OpenSprinkler firmware 2.1.1.
For a while I’ve been looking for a way to switch household power line (110V) devices. One of the simplest options is to use a relay that is connected to the power line. This is easy in concept but quite dangerous to work with. You don’t want to accidentally touch the power line wire and shock yourself. A much better option is to use the powerswitch tail, which insulates the relay and the relevant circuity inside a plastic enclosure, leaving only two MCU pins to interface with. Much safer. But you still have to run wires between your MCU and the power socket. I am more interested in an wireless option.
Recently I purchase a set of remote controlled switch sockets from Amazon. It comes with one remote and three sockets, each of which can be individually switched. The whole package is quite cheap. The way this works is that you plug the sockets into the wall, and when you press a button on the remote, the corresponding socket will switch, thus turning on or off the device connected to the socket.
I took apart the remote control and found that the circuit is quite simple. It’s based on an HT2262 remote control encoder and a 434 MHz transmitter circuit. In fact, the schematic of the circuit is well documented in the datasheet of the encoder:
From the schematic, it’s quite clear that when a button is pressed, the input voltage is fed to one of the encoder pins (as well as the VCC pin of the encoder). Then the encoder will send the signal to the RF transmitter circuit. The RF signal will be received at the power socket side and decoded. Very simple. Now, to use my Arduino to interface with this power switch, all I need to do is to simulate a button press by sourcing a positive voltage to wires labeled SW1, SW2, SW3 etc. It turns out that the HT2262 can work with a fairly wide range of voltage: from 4V to 18V. Clearly the 5V output from an Arduino IO pin falls within the acceptable range. So I can simply connect those wires individually with Arduino I/O pins, and write a program that outputs HIGH momentarily when I need to switch a device. The only downside is at 5V the transmitting range is limited. The higher the input voltage, the longer distance it can transmit. So a more flexible design is to have a ‘source’ driver to supply higher than 5V to the encoder.
Update: check out the RFToy — an easy-to-use standalone gadget to control remote power sockets. Also, support for remote power sockets have been added to OpenSprinkler firmware 2.1.1.
This can be done by using a transistor based high-side switch. Here is a schematic:
Basically, when the IO pin outputs low, transistor Q1 (NPN) turns off, and its collector is in high impedance status. Hence Q2 (PNP) is also off. Now, when the IO pin outputs high, Q1 conducts, driving the gate of Q2 low. Therefore Q2 also conducts, sourcing +12V voltage to the encoder. The reason to use such a high-side driver is to be able to switch a high voltage (>=12V) using a relatively low-voltage (<=5V) control signal from the MCU.
I implemented this method on a small proto-board. Since the remote control has 3 buttons, I made 3 copies of the above high-side driver, and the entire circuit fits nicely inside the remote control cover. I soldered five wires out: +12V, GND, and three control wires. A picture is shown on the left.
With this modification, I can now switch power line devices such as home lights and heaters using a microcontroller. Better, I can connect the remote control with my OpenSprinkler Controller, thus I am able to control power line devices through a web interface. The video below show a demo. Enjoy!
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.
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.