Make Every Week: Message From a Bottle

A summer of tinkering has culminated with a conductivity and temperature sensor that texts its data from inside a Gatorade bottle.

The contraption consists of a Riffle, which is an Arduino-like board designed to fit through the mouth of a water bottle and a Fona cell-phone board. And a bottle.

The plan is to submerge several of these along a stretch of the Monongahela River as part of a sensor-journalism class at West Virginia University. It’s a work in progress, but you can [see how things are going]. My job was to build a working conductivity sensor that would report its findings live. Here are the components and how I made it go.

Update: We actually deployed some of these sensors in a river!

Riffle Setup

The brain is the Riffle, which is the brainchild of Don Blair and which is basically in beta testing. Don makes them by hand at MIT and a few folks are trying them out, including our class.

While chances are slim that you have a Riffle (yet), it has the same brain as an Arduino Uno, so everything here can be done with an standard Uno — except for the fitting-in-a-bottle part. It’ll probably work on other Arduinos, too, and some of those do fit into bottles.

Like an Arduino, my Riffle has a USB port, through which I can upload code just like with an Arduino. One catch — and this is important if you actually have a Riffle — a Mac laptop won’t automatically see it on the USB port. You need to install special drivers for the USB chip Riffle uses. It’s easy to do, and those details are here.

Fona Setup

Adafruit has a great tutorial for getting Fona up and running. Be sure to get a compatible SIM card. I’m using this one from Sparkfun.

Live texting the data is an exciting prospect, but I wanted to keep with the fit-in-a-bottle sprit of Riffle. Fona is too wide for a standard water bottle, but it almost fits through the wider mouth of a 32-ounce Gatorade bottle and it definitely fits with a couple of tweaks.

One is trimming down the mini-jack housing, which juts out a bit to the side. I just snipped it with wire cutters so it was flush with the edge of the board. I don’t use that jack, but I’m guessing it still works.

Two is that anything plugged into the JST battery plug will also make it too wide. This was troubling because the documentation says power must come from the JST plug. With a little investigation, I found I could also power Fona through the “Bat” pin, which solves that problem. (See more in the “Wiring” section below.)

Sensor Setup

To detect conductivity, I’m using a simple circuit that “clicks” at different rates depending on the resistance between to leads. The basics of that circuit are here, and the same circuit exists on this “daughter” sensor board Don designed.

The sensor board plugs into the Riffle and has a terminal for the conductivity leads, which I’m connecting with wires and alligator clips to two screws in the bottle cap. It also has a terminal for a simple thermistor, which measures temperature.

The sensor board has male pins that fit the Riffle. I added a female header to the 5 holes closer to the terminals because I’ll need acess to the one that has 3.3-volts of power.

Bottle Setup

First step: Drink 32 ounzes of Gatorade (feel free to share, that’s a lot of liquid).

I took the cap and put two screws into it, tightening them firmly without stripping the hole. I have no doubt that the type of screws and the distance between them will affect the conductivity readings. But because I’m interested in relative changes — is it going up or down — I completely ignoring this for now.

Then I poked a small hole for a thermistor and stuck it halfway through.

Finally, I took a hot-glue gun to the inside of the cap, and around the screws and the thermistor, to keep it water-tight. I’m not entirely sure this is the best way to go, and am open to suggestions. One issue is that the glue can end up where the bottle pushes against the cap, essentially making it leaky. I trimmed away the excess hot glue and am hoping for the best.

Update! In the comments below, Wendall Cochran suggested using machine screws and washers instead, which work much better! We used that technique for the actual deployment

Wiring it all up

Here are the fona pins:

And here are the pins on the end of the Riffle:

The wiring goes like this:

Here’s what I’ve done in words. Again, the Riffle’s brain is the same as an Arduino Uno, so all of the Riffle’s pins correspond to the same pins on the Uno.

  • Sensor board (the sensor circuit) is plugged into the lower row of holes on the Riffle

  • Fona Vio pin connected to Riffle 3v3, which is on the sensor board. Note that this doesn’t power the Fona, it merely tells it what voltage the microprocessor is using.

  • Fona RX pin connects to Riffle D1 on the upper row of holes.
  • Fona TX pin connects to Riffle D0 on the upper row of holes.
  • Fona Key connects to Riffle D13. This is used to turn Fona on and off.
  • Fona PS connects to Riffle D11. This provides the Fona’s status to the Riffle.
  • Fona Rst connects to Riffle D12.

  • Fona Gnd connects directly to the battery ground.

  • Fona Bat connects directly to the battery power.

  • Riffle’s power and ground provided through the JST jack on the back. These wires also go directly to the battery.

  • The two wires on the thermistor go to the therm terminal on the sensor board.

  • Wires with alligator clips are connected to the cond terminal and clipped to the two screws in the bottle cap.

A note on the power: All of the Fona documentation says it’s bad to power the Fona off a microcontroller’s board, and I found that to be true. I have had luck, however, powering both an Arduino and Fona off one Lipo battery — as long as each gets its own direct path to the power source.

The Software

Here’s the Arduino code that runs on the Riffle, which should also work fine on an Arduino Uno. I use the standard Arduino software to upload code — lying to the software by telling it that Riffle is an Arduino Uno.

As mentioned above, Riffle does require a separate USB driver to be recognized by the computer.

And there’s one more catch: The process of uploading uses the D0 and D1 pins on the Riffle (and an Arduino). When Fona is connected to those pins, as I’ve done, it makes the upload fail. I get an “out of sync” error. So to get the software on the Riffle, I have to pull those two wires off the Riffle, upload the software, and put them back. If you’re using a typical Arduino, like an Uno, probably best to use D2 and D3 instead, and change them where the appear in the code.

#define FONA_RX 1 // communications - wire to Riffle D1
#define FONA_TX 0 // communications - wire to Riffle D0

becomes:

#define FONA_RX 2 // communications - wire to Riffle D2
#define FONA_TX 3 // communications - wire to Riffle D3

Turn it On

Yeah, we almost sunk one of these in the river without flipping it on. Riffle has a power switch (Arduino Uno doesn’t), and it has to be on. That’s the position closest to the edge of the board.

All Together Now

The Online Logger

By replacing insert_phone_number_here with my phone number, I can get the sensor to text me directly. That’s awesome for testing and demonstration, but not really practical for data collecting.

So instead, I use Twilio to capture the text message and redirect it to my own node.js server which posts the data to this table on data.sparkfun.com. Here’s my writeup about doing this and here’s the server code I’m using for this project.

Admittedly, that’s a pretty covoluted way of getting the data online. My setup is actually capable of posting the data directly to the Sparkfun table, and learning how to do that is my next step. I’ll update this post when I get it to work.

Takeaways

  • This is totally doable.
  • It’s not expensive, and certainly not as expensive as professional conductivity monitors, but not dirt-cheap (yet) either. Losing on of these would be a bummer.
  • There’s no calibration or meaning (yet) for the conductivity values.
  • Keeping the bottle cap waterproof is harder than I thought.
  • Not everywhere has decent 2G cell service (it’s spotty in Mogantown, for example).
  • Definitely use the 32-ounce Gatorade bottle. The smaller bottles have smaller mouths, and Fona won’t fit.

Areas for improvement include:

  • Using right-angle header pins on the Fona will make getting the Fona into the bottle a lot easier.
  • Making an actual Fona-Riffle cable would help (I used attached jumper cables)
  • More elegant battery wiring


#MakeEveryWeek is a challenge to myself to do just that for all of 2015. The original post on the idea is here, and the running list of projects is here.

3 responses
This whole project makes me smile. It would work in Lake Harriet for late summer beach closings! Thought it interesting that keeping the bottle cap water tight was one of the most difficult problems.
I would use short machine bolts rather than screws. Epoxy flat washers in place, then secure ends with cap nuts.
Wendell, that's a brilliant idea. We took your suggestion and used it for the actual deployment! It worked perfectly. Details here: http://johnkeefe.net/monitoring-the-monongahela