# compare two analog voltages to reference - wind direction indicator

Hi,

I decided to learn and apply Arduino to solve a longtime project. I have background programming in Perl/CGI which seems to be very similar if not identical in many instances to the Arduino programming language. I have also done some Javascript in the past as well but am a bit rusty on that now. Any programming guidance and suggestions to the bellow intro and quick description of the requirements would be highly appreciated.

This would be my first Arduino project, and it involves two variable voltages that are 90 deg apart in phase (quadrature) that come from a hall angle sensor that need to be read (with the internal DAC) to measure its values, and each be compared to a reference to determine a resulting condition. So basically I am thinking of using two analog inputs, setup an internal reference, and then run the resulting values through a couple of conditionals and then apply some trig formulas according to the results of the conditionals to determine the value of the angle. The trig formulas are pretty simple and involve a calculated numerical value according to each analog input value and then to run it through an ArcTan function.

Once the numeric angle is determined I run that number through another set of conditionals to determine which of the 8 digital outputs to turn on that would indicate the angle bearing.

The application is meant to be able to interface a modern wind direction sender to an older display unit. The display shows the wind direction with 8 individual lamps that used to respond to 8 reed switches inside the sender unit that where setup in a circular arrangement and that would be triggered by a magnet that would move inside the circle according to the wind direction which could also trigger one or two adjacent switches to light the corresponding lamps. And if the resulting angular value falls between two of the main (N,NE,E,SE,S,SW,W,and NW) bearings, two adjacent outputs should be turned on in order to indicate an intermediate bearing to increase a bit the readout resolution, like for example for NNE would be achieved by turning on both the N and NE adjacent lamps.

The old sender unit got damaged and is no longer feasible to get a replacement, so I am trying to adapt a marine type sender that basically sends out these two variable out of phase voltages mentioned earlier and the intelligence inside its corresponding instrument would figure out where to point the needle of its dial by using a step motor. Since my indicator does not use a needle but rather 8 lamps, that is what I need to make this conversion for.

I have already written all the relevant code in a Perl scrip as a simulation and manually entering the two input conditions already works perfectly to "display" the correct wind direction outputs. So just wondering if I am on the right track here by considering to use an Arduino Nano which I just ordered off ebay. In the beginning was rather looking towards using a microcontroller chip, but after reading some of the quite easy to understand Arduino language and comparing it to the 200-300 (or more) page long uC datasheets I think I immediately knew what solution would be easier to implement.

Thank you.

Welcome to the forums. A nano can easily handle this task. What are the voltages of your two inputs and what is the voltage of the reference? If they are more than 5V, you will have to do something to scale them down before connecting them to the Nano.

Once that is done, it is just some math which will be about the same as your Perl math. The arduino uses C++ as the language, although many examples and such just use plain C.

There are many examples in the IDE (File->Examples->03.Analog->...) so I would suggest you check those out and maybe get them working and understand them before trying to connect to your sensor. You can use a POT to simulate your inputs.

If/when you get stuck, post your code and describe the problem and people will help. Also, please read the sticky post at the top of the forum about how to do this well. It helps people help you.

so I am trying to adapt a marine type sender

Would be a lot easier if we had some info on that sender. Post a link to it's datasheet.

JCA34F:
Would be a lot easier if we had some info on that sender. Post a link to it's datasheet.

+1

If the purpose is to detect direction and if it is a quadrature encoder its not obvious why the voltage varies, or what is the relevance of the different voltage levels.

...R

Sounds to me like the OP is describing a sensor like this:

However, the OP sounds a little confused (DAC instead of ADC for example) and I have no idea what that reference voltage is or why it would be needed.

I feel that, while it would work, using trig functions and floating point maths to get 8 outputs to switch on/off seems like overkill. I wonder if some simple algorithm involving only integer maths would work equally well.

Analog hall sensors should give, I think, a reading close to 512 with no magnetic field present. With a north pole field, the reading might go up towards 1023 and with a south pole it would go down towards zero.

So subtracting 512 from the reading of the two sensors would give two values between -500 and +500, approximately. Looking at the signs of the two values would determine which of the four 90 degree quadrants the wind is in. Then, taking the absolute values and comparing one value to the other to see which is greater would resolve the wind into 8 directions. Only one more step would be needed to get 2 lamps on to indicate 16 directions, I think, although I can't quite figure that out in my head right now, but can't be that difficult.

Sounds like one of those Bourns absolute encoders, 'cept they use I2C / SPI to communicate with the MCU.

Hello everyone, and first of all, yes now realize that I messed up stating DAC instead of ADC, just a mistake that just got through as I was focusing more on proper redaction of my text. But I am clear on the concepts, still much appreciate the heads up to avoid misunderstandings.

The voltages of the real life sender that i have to work with vary up to 8V due to the corresponding instrument using this voltage to both power and receive the data from the sender. So will have to scale the sender output voltages down so as not to exceed the 5V limit of the Arduino analog inputs. Thinking a 2:1 ratio should work since I understood there is a 1024 point resolution on the reading anyhow, so plenty of leeway if only 8 outputs have to be switched on/off within the whole 360 degree range. Another thing to perhaps try is to lower the power supply voltage to the sender and see if it still performs, or find a way to modify it, which I have yet not tried. The sensor chip itself is rated for 5-6V operation anyhow.

The angle sensor used inside the sender is a 2SA-10 2 axis angular sensor, best and easy to understand PDF app notes I found so far is here:

http://www.diegm.uniud.it/petrella/Azionamenti%20Elettrici%20II/Sensori%20e%20trasduttori/Data%20Sheet%20-%202SA-10.pdf

This web page also has some useful info that helped me to better visualize the operation of the sender:
https://gmw.com/product/2sa-10g/

Datasheet of the chip itself here:

After reading the app note and understanding the math, then verifying it on my HP25 I went ahead and wrote the Perl code that emulates the results that I need and it all works "on paper". It was then that it became overly clear that a micro controller should be the most logical and easier solution to get this done. If I was able to get my Perl code working, I should be able to learn how to program the same for a micro controller as well.

As someone mentioned, I don't consider the use of this sensor an overkill, I did not even plan for it, its just what I have readily available in the form of a very robust marine grade surplus wind vane (Raymarine part number A28167) that senses both wind speed and direction and is very commonly seen on top of the masts of almost any sailing vessel. I was already able to interface the speed output into my display unit (Heathkit ID-1590), as it is simply pulses very similar in frequency to the ones from the original sender and that just required some minor conditioning and a recalibration for the proper speed indication to work.

So I have been pondering for a long time how to also be able to make the wind direction work, and given that i only had two wires plus common to work with tried using different schemes of analog voltage comparators, multiplexers, etc. At some point also was considering installing 8 small hall sensors inside the Raymarine sender to replace its existing electronics. But so far nothing that really got past an idea in my mind. Then some weeks ago while revisiting the above datasheet (guess we are all having some "extra" free time nowadays) I much better understood my options and as mentioned earlier that definitively a micro controller option would be the most viable solution. And what better way to start off my fist experience in this field with this motivating project.

I have been in electronics (mostly with audio, RF, analog and digital circuit projects) for probably around 40+ years, but had so far never ventured into anything in micro controller territory. So yesterday by chance decided to look into it again and ended up looking up a bunch of online info to get started and ended up choosing the Arduino technology, ordered a Nano from ebay, and posted on this forum.

Just wanted to quickly get this follow up out there, but over the weekend I will again read carefully all the comments and suggestions given above and post further information as needed. Thanks again for the welcome and all the input so far.

The angle sensor used inside the sender is a 2SA-10 2 axis angular sensor, best and easy to understand PDF app notes I found so far is here:

http://www.diegm.uniud.it/petrella/Azionamenti%20Elettrici%20II/Sensori%20e%20trasduttori/Data%20Sheet%20-%202SA-10.pdf

That PDF says that output is single linear variable voltage that is proportionate to the angle. That should be very straightforward to work with.

...R

Reposting pasted URLs as links. This forum does not do that automatically, you need to press the link icon.

http://www.diegm.uniud.it/petrella/Azionamenti%20Elettrici%20II/Sensori%20e%20trasduttori/Data%20Sheet%20-%202SA-10.pdf

https://gmw.com/product/2sa-10g/

Robin2:
That PDF says that output is single linear variable voltage that is proportionate to the angle. That should be very straightforward to work with.

...R

If you look closer the sensor chip has actually two (x, y) output voltages and on the diagram these go into a box marked as "micro controller" that then converts it to one signal. That box is what I am trying to build.

That box is what I am trying to build.

Seems to be reinventing the wheel - but I wish you success.

I'm not going to be able to help with the programming but to my mind the few words I have quoted here contain more useful information than the rest of the material you have posted in your Original Post and in Reply #6

...R

Robin2:
Seems to be reinventing the wheel - but I wish you success.

I'm not going to be able to help with the programming but to my mind the few words I have quoted here contain more useful information than the rest of the material you have posted in your Original Post and in Reply #6

...R

With all due respect, if all I have to work with is the two varying voltages coming from the sender, how is that reinventing the wheel? Or do you mean to say that I can buy a micro controller with the code already in it that will do the job?

And BTW the whole idea is to learn from the experience, even if I where making the same old wheel.

As someone mentioned, I don't consider the use of this sensor an overkill

Am I that someone? You can call me Paul! And I wasn't saying the sensor was overkill. The sensor is what came in the wind vane. I was saying that using floating point maths and trigonometric functions like arctan2 is overkill for converting the 2 analog values from the sensor into 8 digital outputs. It would work but it would give you the wind direction to umpteen decimal places, when you only need a precision of maybe 22.5 degrees for your lamps. Wind vanes aren't much more accurate than that anyway, if mine is anything to go by, swinging around all the time as it does!

I'm not sure what Robin means by reinventing the wheel in this case. You need something to translate those 2 analog input signals from the sensor to 8 digital output signals. Original replacement senders are not available, and arduino can do it instead.

Robin2:
That PDF says that output is single linear variable voltage that is proportionate to the angle. That should be very straightforward to work with.

I don’t think that’s what it means, Robin. That functional block shown in the data sheet isn’t internal to the sensor chip, it represents an external MCU, e.g. an Arduino, translating 2 analog signals into either one analog or digital output signal.

PaulRB:
I don't think that's what it means, Robin. That functional block shown in the data sheet isn't internal to the sensor chip, it represents an external MCU, e.g. an Arduino, translating 2 analog signals into either one analog or digital output signal.

My mistake. I had assumed the microchip was part of the sensor.

One wonders why it isn't

...R

PaulRB:
..../....

I feel that, while it would work, using trig functions and floating point maths to get 8 outputs to switch on/off seems like overkill. I wonder if some simple algorithm involving only integer maths would work equally well.

..../....

Hey Paul, yes I seem to have misread your first post where you mentioned the "overkill". I had just quickly skimmed over all the recent posts since last night, and somehow had gotten the impression that you meant that the sensor type was an overkill. Sorry about the confusion, and thanks for your input.

Anyway, I think that so far have gotten some nice encouragement from this thread's responses to move ahead. Guess I'll have to wait until the Arduino arrives to start coding and debugging as time permits. The code I put together in Perl is really quite simple, of course that is just the bare basics and would still require translation to C and adding all the required Arduino commands to handle IO etc. Figure will move ahead as I go along and post here if I get stuck and have any specific programming questions. So far the Arduino Programming Language Reference page has been very clear and useful, yet another reason I chose to go with an Arduino.

Thanks again.

-Alex

Well, your perl script may be simple, but it’s going to be running on a 64 bit cpu that runs at several GHz and has floating point hardware built in. Nano has a 8 bit cpu, runs at 16MHz and has no floating point hardware, it all has to be done in software.

If you only take 1 reading every few seconds, no problem, but if you need to take hundreds of readings over those few seconds, so you can take an average, because the vane is swinging around, the slow maths might become a problem. Maybe not. Try it and see.

I think it would be ideal if I could process around 1 reading per second, just to get it as close as possible to real time. Not much point in knowing where the wind was going 5 or 10 seconds ago.

What would the the other options, get a more powerful Arduino board? On the other hand I could just give it a try with the Nano as you pointed out, and see how it behaves. I assume the bulk of the code I would end up would be pretty much compatible with other Arduino versions anyhow, if I really needed to upgrade hardware.

I was also thinking of taking apart the Raymarine ST60 wind instrument to get a glimpse at the PC board and see what chips are in there. Perhaps that would give an idea of the required processing power. I know for a fact that even with that instrument there is a noticeable lag of about 0.25 seconds while the position information gets processed and the indicator needle actually points in the right direction. Or perhaps its the mechanical indicator needle that is driven by a stepper motor that is causing the brief delay.

Anyway, I'll give it a go with the Nano. I ordered this one:

I was also thinking that it would be useful to have some form of display during debugging, I was wondering what would you guys recommend to get that can be easily interfaced to the Arduino? Perhaps one of those multi-line LCD modules? Or does the IDE allow to display results to allow debugging?

Yes, usb connection to a laptop and use of serial monitor in the IDE is the standard method of debugging. But an LCD could also be handy. Get one with an i2c backpack for convenience.