PART 2 – The Microcontroller
Like most electronics hobbyists, I’m a big fan of the Arduino. Power, flexibility, expandability all in an easy to use form. The first time I ever used one, it was like I had discovered a whole new way of making my electronics interface with the real world. But, it’s easy to reach in your bag of tools and grab an Arduino — even when it’s the wrong tool for the job. Given it’s direct lack of wireless interfacing capabilities, I would have to buy Wifi or XBee for the Arduino. Not the option for me.
Instead, I chose to move the basic end-unit interfacing out to the garage and keep the brains and the user interface on my existing linux server. The WiFly gives me that.
http://rovingnetworks.com/products/RN_XV
The WiFly a simple, small drop-in module designed to replace the functionality of an XBee with a 802.11b/g radio. The 802.11 output power is even user-configurable. An “XBee killer” someone called it. It features 8 GPIO pins and 3 analog (ADC) pins. It does Wifi out of the box with minimal configuration. Like many microcontrollers, however, it is 3.3v instead of the more user-friendly 5v. I chose to purchase a 5v interface from CuteDigi for $7. With this interface, I can toss it on my standard breadboard and use the basic 5v digital knowledge I already have
— sometimes, I don’t like to learn when I’m trying to learn.
Setup is easy:
Plug 5v into pin 1, ground into pin 10. Tie pin 8 to high to enable adhoc networking mode.
When the module comes up, it is already broadcasting an SSID:
I use the free version of MochaSoft’s telnet client. Nice program. If I needed it for more than 30 seconds to set up one of these, I might actually buy it. In ad hoc mode, the WiFly will assign your iPhone an IP address. You need to set up your telnet session to connect to 169.254.1.1, port 2000 (the WiFly default in ad hoc mode).
The config is shown above. I use WPA2/PSK, so setup was a whopping 4 commands for me:
$$$ (enter command mode) set wlan auth 4 (WPA2/PSK mode) set wlan ssid ABC123 (obviously, use your ssid) set wlan passphrase 0123456789 (use your WPA2 key) save
If you use WEP (shame on you!!), your config is a little different. You’ll use a value of 1 for wlan auth, and instead of set wlan passphrase xxx use set wlan key xxx
Disconnect power, unhook pin 8 (turn off ad hoc mode), and reconnect power. Give your module at least 30 seconds to find and join your network. 30 seconds later, I look in /var/lib/misc/dnsmasq.leases and there is my module:
1326462274 00:06:66:71:cf:6e 192.168.xxx.108 WiFly-EZX *
Now wasn’t that easy!!!







I think the 5v breakout board from cutedigi.com only converts power and UART signals to 3.3v. So the pin 8 signals and pin 11 inputs are 5 volts. This could damage the board, couldn’t it?
Scott,
I think you are correct. I’ve found that the BIG warnings from Roving Networks datasheets all involve the sensor inputs which are strictly limited to 1.2v. The regular GPIOs are supposed to be limited to 3.3v. However, when I look at the actual RN-XV module, I see resistor divider networks on each of the GPIO input pins. I’ll probably need to do a little more research to make sure these limit the voltage as I suspect they do.
I can tell you that, empirically, they work perfectly.
Tod,
I can verify also that this works because I have it working on my garage door. Thank you for the great design. I added a second reed switch to tell if the door if fully open, fully closed, or in between. I also added an LM35 thermometer so I can monitor the temperature in the garage.
The readings from the ADC seem to be about 3 times smaller than the output of the sensor. I assume this is because of the resister divider networks.
Scott
Tod,
When I look at the datasheet for the RN-XV, it says on page 5 that the resistors are only installed on the sensor inputs not on GPIO. So I don’t think the resistor divider network is present on those GPIO pins, right?
Joe
Joe,
After reviewing the datasheet, I do tend to agree with you. The circuit should probably be modified to put a resistor divider on the door sensor. Maybe a pulldown (10k?) and a 5k switched by the reed to +5v and the GPIO pin between the two.
Mine has run for months without it, but I can imagine that the lifespan on my wifly might be shortened by this higher voltage.
tod
Tod,
Similarly then the relay is really being driven by 3.3V instead of 5V, right? Not sure how that might affect the reliability of operation if the relay is only being supplied with 3.3V instead of 5V.
Joe
Well, a relay is a binary device — it’s either on or off. My system has had no problems with activating the relay. At 3.3v, the current is even lower than at 5v, so I can’t see any long-term negative impact either. I think this part of the circuit is fine as it is.
tod
Hi Tod,
I was thinking less so that the relay will be damaged but more so that with 3.3V instead of 5V that sometimes the relay might not reliably activate, no?
Joe
It’s been 100% in my setup. And it’s used multiple times per day.
Thanks for the great writeup.. I’ll be ordering some parts soon and building one of these to control both of my doors. Just an FYI, I plan to add one of these (or similar)
http://www.sainsmart.com/sainsmart-2-channel-signal-relay-module-board-for-arduino-uno-mega-2560-r3-1280.html
or
http://www.sainsmart.com/arduino-pro-mini.html
to control the door. The relays are a bit overkill, but the specs show it’ll trip easily at 3.3v output from the GPIO pins.
Also, for giggles, I fired an email to RovingNetworks tech support. I asked if there was any way they might add a timed latching function on the GPIO pins. So, a pin could be set high for a short time (1000ms), and automatically be set back low. That way, you won’t have to rely on the server turning the pin back off when controlling the door.
eg..
> set sys latch 1000 0×0100 0×0100
Shane
That’s an interesting idea. The great thing about that device is the ability for it to update it’s own firmware. Let us know what they say!!
Thanks a bunch for this tutorial. I am very excited about getting this thing built. I have purchased the parts but I am having a bit of trouble getting the WiFly going.
I am able to connect to it in adhoc mode and configure the device. When I disconnect pin 8 and power cycle it, the WiFly doesn’t connect to my network. It stays in adhoc mode. If I issue the join command I am able to get it connected. I verified that it was connected by looking at my routers device list and pinging it. The problem is that when I try to telnet to the WiFly, once it is on my network, I get this as a reply.
“Connection closed by foreign host.”
Power cycling the WiFly sets it back to adhoc mode.
Any help you can provide is greatly appreciated. Thanks again for the great project.
Ryan,
Make sure you “save” before power cycling and I’d also recommend disconnecting power _before_ you disconnect pin 8. The telnet should be to port 2000 and you should see the *HELLO* string.
If you’re still having problems, send me a picture of your setup and schematic and do a “get everything” on the wifly and I’ll review.
tod