For some time now the log sensor on our boat hasn't been working so we've had to rely on the GPS speed-over-ground reading and guess at what the tide is doing instead.
My plan to remedy this was to buy a new sensor, but when I took the old one out, I couldn't resist taking it to bits to see how it worked.
This got me thinking about taking the sensor output, convert it to an nmea sentence and Bluetooth it to whatever mobile devices we had on the boat.
This instructable is the realisation of this.
Step 1: How to Make a Very Small Pulse Into a Logic Level
The sensor shown in the picture is the old one that I stripped down. A NASA Marine Clipper log sensor. The paddle is one I knocked up to play with as the old one was shot.
It's a very simple two wire passive design that consists of a coil with an iron bar down the centre of the static part. The paddlewheel has magnets in two of the paddles that generate a small current in the coil when they pass.
You can see on the scope trace the output from the sensor. It's a very small signal, not at all suitable as a digital input. Furthermore, the slower the paddle turns, the lower the amplitude.
We need to convert this to a consistent and dependable logic level pulse before we can proceed.
Definitely a task for op amps.
The circuit I came up with can be divided up into five stages. I'll describe each stage briefly, what it does, and why it's there.
1. A high gain instrumentation amplifier configuration.
We need some serious gain on this section if we're going to turn this signal into a useful one. Fortunately we're not particularly interested in preserving the shape of the pulse so it doesn't matter if we drive the op-amps to the rails and clip the extremities of the pulses. In fact, it works to our advantage to do so.
2. A first order low pass filter
The frequency of the pulses we're interested in are relatively low.
The Bluetooth module (HC-06) transmitter creates higher frequency noise around 10KHz that appears on the input of the amplifier. This results in false readings of around 1900Kts
100Hz equates to about 18Kts. The hull speed of my boat is around
6.5Kts, so 100Hz seemed like a good point to roll off the higher frequencies.
The filter (a capicitor and a resistor) appears after amplifier stage and not before it for good reason.
If it were in front of the amp stage it would form a tuned circuit with the coil from the sensor and resonate away producing a steady stream of unwanted pulses. After the amp stage, there is no danger of this occurring.
3. A buffer
The buffer in this case could be removed. It is present because I had a spare op-amp and I didn't want it going haywire and affecting the others in the package. I could have just tied the inputs to the virtual ground, but it was easier to include it as a buffer.
4. A Schmitt trigger
Now we know what we can expect at the output of the first stages, we can think about turning it into a suitable logic shaped signal.
A Schmitt trigger is an excellent way of doing this. Without going into too much detail here, it triggers at two places. The first, when the input reaches a specified voltage will send the output low. And the second, when the input falls below a specified voltage will send the output high.
Since we're only looking for a pulse and logic gates trigger on either a rising or falling edge, we're not bothered whether the signal is inverted or not. As it happens, the signal is inverted by the instrumentation amp, and again by the schmitt trigger so it ends up the same way up.
5. A Zener diode
There is a slight hitch with the circuit so far because we're using a single rail 9V supply.
In order to run an op-amp, it requires + and - supply rails. Since were hanging a 9V regulator off the boats 12V supply, we don't have this.
The way to overcome this is to create a virtual ground that sits at 1/2 the supply voltage. This gives us +4.5V and -4.5V relative to our new ground and allows our op-amps to swing positive and negative.
For the logic signal however, we want a swing of 0V to 5V from the actual ground.
In steps the Zener diode to the rescue! It clips the output to 4.7V in this case.
Now because we know what the output of the Schmitt trigger is we now know that we will have a reliable swing between a logic 0 and a logic 1.
I have included a trace from the LTSpice model I used to simulate the circuit before I got my soldering iron out.
The key is as follows:
Green - input signal
Blue - output of the instrumentation amplifier stage
Red - The output after the Schmitt trigger and Zener diode.
If you're not familiar with LTSpice, it's well worth becoming acquainted. It's easy to use, very powerful and free.
You still have to do your calculations, but once you're in the right ball park, tweaking is quick and easy, and you don't end up with a big pile of components on your bench once you're done.
Step 2: The Arduino Schematic
Now that we've got an output from the log sensor that we can use, the next step is to hook it up to an Arduino.
The schematic pretty much says it all, but there's a few points worth mentioning:
The digital outputs of the Arduino are 5V, but the HC-06 expects 3V3 on its input. The 2K2 and 1K potential divider is there to make sure that it does.
Also remember the Aref pin needs to be set to 3V3, or the analogue input A0 won't have a reference.
The 100K trim pot is there so we can calibrate the sensor easily whilst sailing.
Step 3: The NMEA Standard
This is the standard structure for navigational data.
The data is sent as sentences that start with a $ and end with a carriage return line feed.
After the $, the next two characters describe the type of sensor the data is being sent from. In our case this is VW for velocity sensor, speed log, water, mechanical.
The following three characters describe the data to follow. Again, for us this is VHW for water speed and heading.
The values are delimited by commas.
The sensor is unable to return the bearing part of the sentence, so we don't write an entry in fields 1 & 3.
Also the Baud rate is a rather slow 4800.
Step 4: The Code
Now we have an input that we can work with, and we know the format we want the output to be in, we are in as position to be able to write the code.
Fortunately, a quick search uncovered Mike Holden's site
As as result, my sketch is based on a cut down version of his excellent code. Thanks Mike!
I say cut down, because he uses the Arduino's eeprom to store calibration data that can be set on startup. I chose not to use this part as it would require you to have a laptop on the boat to do the initial setup. Instead, I have used a 20-turn trim pot to calibrate the output as I reckoned it would be easier to set whilst charging up and down the harbour at slack water.
The Bluetooth module was added specifically as I wanted to send the output to a deck mounted Android tablet running our plotter app.
Step 5: The Result:
Well, here it is in all its glory.
The tablet is a Samsung Galaxy Tab 2 mounted in a detachable splash proof deck mounted case made from acrylic.
The log speed is displayed underneath the speed over ground.
You'll see that they are both reading zero. That's because were moored up. I had just taken one of the winches apart to grease the bearings, and as I did so, they made a run for it and escaped over the side.
Despite our best efforts, they're hiding three metres below, no doubt laughing at us.