4
\$\begingroup\$

Disclaimer: Please be gentle - I'm a newbie with electronics.

Overview

I have a proprietary 24v DC analog sensor signal that I'm trying to interface with using a Arduino based microcontroller. The sensor is has only two connections which is used both for power and signalling.

Approach

I've searched various posts and sites regarding conversion of the 0-24v analog signal to the range 0-5v the ADC on the Arduino Uno (actually Freetronics Eleven with ATmega328P) can interpret.

From what I've pieced together:

  • The ADC is a 10bit for 0-5v so I have roughly 4.88mV per step (total of 1023 steps). The resolution is good enough for my needs.
  • I can use a simple voltage divider circuit to "scale down" to 0 - 5v range.
  • I should choose my resistor values not only to achieve the desired divided voltage, but also to suit the impedance of the ADC. I'm still lost with the whole impedance thing so I'm still unsure about whether to use R1 and R2 sized as say 4.7Kohm and 1.2Kohm or larger by an order of magnitude or two.
  • Voltage buffer / op-amp: I seen references to including this as part of the circuit, but again my ignorance only makes me dangerous at this point. I'm not certain why this is useful or what it achieves, but I think it seems to help address the mismatch of impedance from the 24v signal and that of the ADC? But I could be wrong.

One particular question that I have is about the fact that the ADC and the 24v sensor signal that I'm trying to interface is that they have different power sources, and apparently this is an issue because they don't share the same GND. Out of my depth, so some insight would be useful. The Arduino is running at 5v DC.

I realise SE prefers Q&A type of posts, but to me the above is context that fits together for the larger circuit - at least that's what I think.

I would really appreciate it if those with more understanding and knowledge could offer their insights and assert my thoughts above and even elaborate on it to further my understanding and clear up some of my misunderstandings.

Many thanks!

\$\endgroup\$
16
  • 1
    \$\begingroup\$ At the very least we need to know more about this mysterious "proprietary 24Vdc analog sensor", as well as how often you need to sample it, to be able to advise. \$\endgroup\$
    – Techydude
    Jun 28, 2015 at 7:00
  • \$\begingroup\$ @Techydude Apologies for the limited information. I don't have very much else myself. It's a wireless rain and ET sensor from Hunter that I'm trying to "re-appropriate" for a project. What I'm expecting to get from the sensor is likely going to be a PWM like signal, but I cannot confirm. Kinda what this is all about - so I can see if I can figure out a way to use it's data. Unfortunately I don't have access to expensive equipment like oscilloscopes or logic analysers, but I would like to try what I can with the basic ADC available etc. Don't know if that helps you question any though? \$\endgroup\$
    – Jaans
    Jun 28, 2015 at 7:16
  • \$\begingroup\$ do you mean one of these: hunterindustries.com/en-metric/irrigation-product/sensors/… ? \$\endgroup\$
    – Techydude
    Jun 28, 2015 at 7:19
  • \$\begingroup\$ yup - the wireless version of the solar sync. Specifically, the receiver module (WSS-SEN). For reference hunterindustries.com/sites/default/files/OM_WirelessSS_em.pdf \$\endgroup\$
    – Jaans
    Jun 28, 2015 at 7:23
  • \$\begingroup\$ There is much confusion here. the "Wireless Solar Sync Receiver" appears to be a battery-powered add-on to some Hunter product which interfaces with 2 wires to either X-Core or ACC controllers, and some other Hunter products need an additional intermediary 'Solar Sync Module' (in which case their link to the SSModule is also wireless). I assuming you want to interface a "Wireless Solar Sync Receiver" to your Arduino? If so, then I doubt you'll be receiving a 24Vdc signal from it. \$\endgroup\$
    – Techydude
    Jun 28, 2015 at 8:03

3 Answers 3

9
\$\begingroup\$

It seems like your first task is going to be determining what sort of signalling is being used, so what you need to start with is a "poor man's oscilloscope" in the form of a microcontroller with ADC. You're going to want to use it to measure both the voltage across the sensor wires and the current through them; if the wires are used for both power and communication, it's likely that the way it communicates is by increasing and decreasing the amount of current it consumes, in which case your most useful information will come by measuring the current waveform.

As you observed, the Arduino can measure voltages between 0 and 5 volts on its analog ports. In order to measure a wider range, up to 24 volts, we need a voltage divider, like this:

schematic

simulate this circuit – Schematic created using CircuitLab

The basic operation of a resistor divider is simple. Ignore 'Radc' for a moment, and assume 'IN' is connected to a voltage source. Current will flow from IN, through Ra and Rb, to ground; the amount of that current depends on the voltage at IN. We can calculate this with i = Vin / (Ra + Rb). The voltage where Ra and Rb meet will depend on the current flowing and the value of Rb - it's Vdiv = i * Rb.

Knowing this, we can construct a divider for any ratio we want simply by determining the relative values of Ra and Rb. But what about the absolute values? In principle we can pick any magnitude we want, but in practice there are several important considerations:

  1. It's likely that 'In' isn't a true voltage source, capable of supplying unlimited current, but instead has its own internal resistance, which we call the output impedance. If we draw enough power from it, it will cause the input to sag, producing inaccurate results and potentially affecting the rest of the circuit.
  2. Dissipating a lot of current through our divider by using small resistors also wastes a lot of power, and produces a lot of unwanted heat.
  3. It's likely that our measuring device isn't perfect either. Our equations above assume that the ADC doesn't put any load on the resistor divider, but that's not correct. Different types of input will load what they're measuring to different extents; this is where Radc comes in: it's a representation of the load that the ADC puts on the circuit, not a physical, discrete component. In the case of an Arduino, we can assume it's in the range of 10 kiloohms to 100 kiloohms, depending on things such as the sampling rate.

Point 1 above means that we want to make our resistor divider's impedance - the sum of both resistor values - much higher than the output impedance of the circuit we're measuring, so we don't affect our measurements. Point 3 above means that we want to make the resistance our ADC sees - Ra, in this case - much smaller than its own input impedance, so the ADC's impedance doesn't affect the measurements. If possible, then, we want to select a value in between - a resistance for Ra+Rb that's more than, say, 100 times the input circuit's output impedance, and a resistance for Ra that's less than, say, 1/100th the ADC's input impedance.

But what if those two requirements are in conflict? That's where an opamp comes in.

An ideal opamp (operational amplifier) has infinite input impedance - it doesn't disturb the signal it's measuring at all - and zero output impedance - its output is a perfect voltage source. Real life opamps differ from this ideal to a greater or lesser extent, but for our purposes it's close enough to true.

We can exploit these properties to make our measurement circuit better by putting the opamp between the resistor divider and the ADC input, like so:

schematic

simulate this circuit

Now, our resistor divider 'sees' a very high output impedance from the Opamp's input, and our ADC 'sees' a very low input impedance from the Opamp's output - the best of both worlds!

Choosing an opamp

But what opamp do we need? Well, we have a few requirements:

  1. We want to be able to power it from our Arduino's 5v supply
  2. It should be in an easy to solder package
  3. Input and output should go all the way from ground to the supply voltage - this is called 'rail to rail IO'
  4. It should be readily available and affordable
  5. It should be capable of handling signals up to the maximum speed of our ADC - about 10-20KHz.
  6. Its input impedance should be quite high

A quick search on digi-key reveals the MCP6241, which supports input voltages as low as 0.3 volts below the negative rail and as high as 0.3 volts above the positive rail (5v), and output voltages within 35 millivolts of the negative and positive rails, which is easily good enough for our purposes. This opamp's power pins can be connected directly to GND and VCC on the Arduino, with the remainder wired up as shown in the diagram above.

What about the resistor divider? Well, the MCP6241's datasheet says its input impedance is 1013 ohms - an absurd 100 teraohms, or one hundred million megaohms. This is high even for an opamp, and means we can use a resistor divider just about as large as you'd like - or so you'd think.

One final wrinkle in choosing our resistor divider value is that we don't live in an ideal world when it comes to constructing our circuit, either. PCBs aren't perfect insulators, and neither are breadboards; surface contamination will affect the resistance too, and if you touch your circuit, you can guarantee the resistance through your skin is a whole lot lower than a teraohm. All of this means that we should pick a resistor divider value that's much lower than the theoretical maximum - a good rule of thumb is something in the range of 100 kiloohms to 1 megaohm.

We want to divide our input so that 24 volts in is roughly 5 volts out, which means we need a ratio of 5/24=~20%. Suppose we set Rb at 100 kiloohms; that means that Ra should be 4 times bigger, or about 400 kiloohms. 402 kiloohms is a readily available value, which gives us a final division ratio of 100/(100+402) = 19.9%, meaning 24 volts in will measure as 4.78 volts out.

Measuring current

All of the above is aimed at letting you easily measure a 24 volt signal on your microcontroller without disturbing the input much. If you want to measure a current instead, your life is much simpler: determine the likely range of currents you want to measure, and pick a resistor that will create a small but measurable voltage drop at those levels. With your 24 volt system, anything up to 1 volt may be acceptable. Then, place that resistor between ground and your sensor's negative wire, and measure the voltage across it directly with your ADC, or via the opamp without the resistor divider if you wish.

\$\endgroup\$
4
  • \$\begingroup\$ What an answer!! Nick, thank you for explaining so patiently and for the detail and relevant reasoning. I've gained an understanding from your answer (admittedly after slowly reading it again 5 or 6 times) that is very practical. The impedance as it relates to the signal, via the voltage divider and what's ideal for the ADC makes a lot more sense now, as does the op-amp's role. Even if nothing comes of it, I'm learning :) I'll order the MCP6241 and try it out. \$\endgroup\$
    – Jaans
    Jun 28, 2015 at 12:02
  • \$\begingroup\$ As for the current signal, given that the multi-meter showed around 10mA, a range of 5-50mA should be a rough starting point. Admittedly I'm a little uncertain with the this aspect of measuring the current as a signal. Say I use a 2.4kOhm resistor in the way you suggest, am I measuring with the ADC across this resistor only? or from the GND side of the resistor and the positive side of the 24v signal? Thanks again for your help. \$\endgroup\$
    – Jaans
    Jun 28, 2015 at 12:12
  • 1
    \$\begingroup\$ To measure current, you put the resistor in series with the signal you're measuring. In this case between the return wire of the sensor and your (shared) ground. The voltage across the resistor that the current flow creates is what you measure, and is called the "burden voltage" - again it's a case of tradeoffs, you want to minimize the burden voltage because of its impact on the device you're measuring, but maximize it for measurement accuracy. \$\endgroup\$ Jun 28, 2015 at 16:25
  • 1
    \$\begingroup\$ 50 milliamps through 2.4 kiloohms is 120 volts - obvously way too high! You want something closer to 20 ohms, which will give you a burden voltage of 1 volt at 50 milliamps. \$\endgroup\$ Jun 28, 2015 at 16:26
3
\$\begingroup\$

The ADC will be happy with < 10K of source impedance. If you have a voltage divider R1 R2 connected to a voltage source the source impedance is 1/(1/R1 + 1/R2).

The ratio should be close to 3.8:1 for the application.

So you can pick R1 = 38.3K 1% and R2 = 10.0K 1% (from standard E96 values).

Source impedance (seen by the ADC) is 7.9K, ratio is such that 24V -> 4.98V.

Provided a 48K load (10K + 38.3K) does not unduly affect your 24V signal, you should be fine.

\$\endgroup\$
3
  • \$\begingroup\$ Appreciate the feedback - I'll give that a go. Any issue about the sensor having a separate power supply not sharing GND with the ADC? \$\endgroup\$
    – Jaans
    Jun 28, 2015 at 9:08
  • 1
    \$\begingroup\$ There has to be a (one only) common ground somewhere. Without a schematic I can't imagine all the ways things could be wrong and the few ways they could be right. \$\endgroup\$ Jun 28, 2015 at 14:36
  • \$\begingroup\$ OK, noted - thanks. Will look into isolation amplifier option as suggested by @jim-fischer. \$\endgroup\$
    – Jaans
    Jun 29, 2015 at 4:28
1
\$\begingroup\$

One particular question that I have is about the fact that the ADC and the 24v sensor signal that I'm trying to interface is that they have different power sources, and apparently this is an issue because they don't share the same GND.

Yes, this is definitely a concern. If the grounds for the 24 VDC and 5 VDC systems are galvanically isolated from each other, and must remain so for safety reasons, then you'll need to use an isolation amplifier circuit (for example) to safely connect the scaled down voltage provided by the resistive voltage divider output on the 24 VDC side to the ADC input on the 5 VDC side.

Sampled 24V out -> [IA] -> ADC in (5V side)

For more information, perform an Internet search on galvanic isolation and isolation amplifier IC, for example.

\$\endgroup\$
9
  • \$\begingroup\$ Great - thanks for that Jim! I'll look into these. To check, I think I don't have a shared GND because: ADC is on ATMega328P which is part of a customised circuit powered by 24Vac transformer (using TRIACs to switch 24Vac outputs). Obviously that circuit converts the 24Vac to 5Vdc for the microcontroller, but no 24Vdc is available to tap into. So, to get 24Vdc I use same transformer, apply rectifier, filter caps and voltage regulator. Surely they don't share GND given the separation of the MCU and the sensor 24Vdc source at the transformer 24Vac output? Excuse my ignorance, if that is wrong. \$\endgroup\$
    – Jaans
    Jun 29, 2015 at 4:26
  • \$\begingroup\$ I'm not comprehending your circuit's topology from your verbal descriptions alone. It's said that "A picture is worth a thousand words", so can you provide a schematic diagram figure that shows the basic circuit topology you're describing? Maybe draw by hand a simple version of the circuit topology, take a picture of the schematic with your smartphone, upload the image from your smartphone to the Internet (e.g., to imgur.com), and provide us a link to the uploaded image file so that we can take a look at it. \$\endgroup\$ Jun 29, 2015 at 8:10
  • \$\begingroup\$ I sincerely hope this mock-up doesn't make it harder to understand. See this link for a schematic-like diagram where each "circuit" is under their own "block". (Note to self: Work on learning the correct balance of too much or little detail, but I digress :) \$\endgroup\$
    – Jaans
    Jun 29, 2015 at 13:06
  • \$\begingroup\$ Block 1 (red) is the mains power supply & transformer. Block 2 (blue) is a rectifier and voltage regulator to convert output from block 1 to DC. Block 3 (brown) is microcontroller that "switches" 24Vac outputs based on programming and inputs from it's I/O pins. Block 4 (green) is the 2-wire sensor that I'm trying to interface and read some voltage / current signals from. Block 5 (black) has two versions, one to get sensor voltage or the other to get current signal as inputs to the I/O pins for the microcontroller (block 3). Whether the various GNDs can be common is the question I guess. \$\endgroup\$
    – Jaans
    Jun 29, 2015 at 13:14
  • \$\begingroup\$ Oops! Here's the link: i.imgur.com/PmAMQM1.png \$\endgroup\$
    – Jaans
    Jun 29, 2015 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.