ophiothrix
Posts: 8
Joined: Fri Jan 04, 2019 8:45 pm
Location: Barcelona

Problem with connecting multiple voltage sensors to Pi

Fri Jan 04, 2019 9:35 pm

Hello and apologies if my questions are extremely daft :?

I have a "toy" solar energy set up and I'd like to build a battery monitor using Raspberry Pi. The battery bank consists of 4 batteries and I'd like to monitor them independently.

I'm using the MCP3008 ADC and voltage sensors that you see in a lot of on-line tutorials on voltage sensing with Arduino and RPi (like this for instance:
Image
The wiring is set up to use hardware SPI, as in this tutorial: http://kookye.com/2017/06/01/design-a-v ... ge-sensor/.

It works beautifully with a single sensor, but when I tried to connect the second sensor to the second battery, I got some fireworks :shock:

For each of the sensors I connect the + and - terminals to Pi's 3.3V and GND respectively. The S terminal connects to the corresponding channel of ADC. My intention was then to connect VCC and GND terminals to the positive and negative terminals of the battery.

After looking into it, I found that all GND terminals are all inter-connected. I.e. there is no resistance between them and the multimeter would read the battery voltage between the VCC of terminal 1 and GND of any other terminal. So I'd like to understand why this is happening and what I'm doing wrong. And, hopefully, how to rectify it.

My understanding is that these voltage "sensors" are rather simple voltage divider with resistors selected for a 1/5 ratio. So I'd be happy to ditch the sensors altogether and build my own voltage dividers, but then I'm not sure if I understand the wiring properly. Would I stick two resistors between the positive and negative terminals of the battery and take the Vout (in the picture below) directly to the Channel pin of MCP3008? If that is the case, I don't understand what the + and - pins are doing on the sensor.
Image.

If something is missing from my description of the problem, please let me know. Otherwise, you input would be very much appreciated!

Erklei
Posts: 4
Joined: Fri Apr 13, 2018 3:39 pm

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 9:22 am

As GND is connected to negative input, you shorted the first battery when you wired the second voltage sensor. You must connect all sensor negative inputs to system GND, which is also Rasp GND. Positive inputs you can connect to separate solar cells as long the input voltage is below 25V. Then you can get individual cell voltages if you subtract other cells. I am sure you understand it if you draw a schematic of it.

Are you sure the "+" on the blue board is wired to somewhere at all?

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 11:30 am

As a additional to the previous post:

You indeed to remember that you are measuring between the gnd and above. And the voltage need to be save for the adc.
And in your case the "pseudo-differential pairs" option of the mcp* is interesting. If you are using it in a correct and connect it in the right way. Then you can read each battery individual. Without reading the others.

And it is indeed better to make your own voltage divider.

ophiothrix
Posts: 8
Joined: Fri Jan 04, 2019 8:45 pm
Location: Barcelona

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 2:54 pm

Erklei wrote:
Sun Jan 06, 2019 9:22 am
As GND is connected to negative input, you shorted the first battery when you wired the second voltage sensor. You must connect all sensor negative inputs to system GND, which is also Rasp GND. Positive inputs you can connect to separate solar cells as long the input voltage is below 25V. Then you can get individual cell voltages if you subtract other cells. I am sure you understand it if you draw a schematic of it.

Are you sure the "+" on the blue board is wired to somewhere at all?
Thank you for the pointers!

You are right that the "+" pin doesn't seem to be wired to anything. Also "-" pin seems to be directly coupled to the GND terminal - there is no resistance between them and I get the same resistance between VCC and GND terminals, as I do between VCC and "-" pin. So my first thought was they they are redundant, i.e. the same terminal but with two options, either a pin or a screw terminal. But I'm still not clear what I should supply as the negative input. Is it GND from Raspberry? In that case I should be able to disconnect the negative terminal of the battery and read the voltage. But I'm getting 0 V, even though the "-" pin is still connected to Raspberry ground. On the other hand, if I disconnect the Raspberry GND from the "-" terminal, the voltage reading is all over the place, from 0 to 16.5 (which is the maximum, as I'm using 3.3V as Reference voltage). So it seems that the only wiring that's working (as in gives the realistic reading of the battery voltage) is the initial one: "-" pin goes to Raspberry GND and GND screw terminal goes to negative terminal of the battery.

The schematic of the sensor, as I understand it is that two screw terminals correspond to the GND and Vin of the voltage being divided. The S pin sits between the two resistors, i.e. Vout. But the role of the "-" pin is not clear to me. Is that what I measure the Vout against? Is that then a design fault that it's shorted to the GND terminal on the sensor?

Erklei
Posts: 4
Joined: Fri Apr 13, 2018 3:39 pm

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 3:04 pm

"-" and gnd are connected together. ADC takes all measurements relative to gnd. Therefore the voltage source and ADC must have same groud potential. "-" and gnd connections help to get them onto the same potential by connecting both system gnds together.

I recommend to build the voltage divider to breadboard by yourself. Then you understand how it works.

ophiothrix
Posts: 8
Joined: Fri Jan 04, 2019 8:45 pm
Location: Barcelona

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 3:06 pm

Brandon92 wrote:
Sun Jan 06, 2019 11:30 am
As a additional to the previous post:

You indeed to remember that you are measuring between the gnd and above. And the voltage need to be save for the adc.
And in your case the "pseudo-differential pairs" option of the mcp* is interesting. If you are using it in a correct and connect it in the right way. Then you can read each battery individual. Without reading the others.

And it is indeed better to make your own voltage divider.
Thank you Brandon.

If I were to make my own voltage divider, would it be sufficient to take the Vout to the Channel pin of the ADC? Given my current understanding of the sensors I'm working with, this would be equivalent to connecting battery's "+" and "-" to the VCC and GND terminals of the sensor and the S pin to ADC, but that does not seem to give a correct, or even stable voltage reading.

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 3:21 pm

Hey,
I think the best way for this is that you make a (concept) schematic on a peace of paper or ..
So, that it is easier to understand and you might see a problem occur when you draw this diagram.

ophiothrix
Posts: 8
Joined: Fri Jan 04, 2019 8:45 pm
Location: Barcelona

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 3:24 pm

Erklei wrote:
Sun Jan 06, 2019 3:04 pm
"-" and gnd are connected together. ADC takes all measurements relative to gnd. Therefore the voltage source and ADC must have same groud potential. "-" and gnd connections help to get them onto the same potential by connecting both system gnds together.

I recommend to build the voltage divider to breadboard by yourself. Then you understand how it works.
Thank you Erklei.

So if I build a voltage divider, I would have to connect the battery "-" to Raspberry/breadboard GND rail as well as to the "-"/GND end of the voltage divider circuit. Which is fine for a single battery. But if I wanted to then add the 2nd battery, wouldn't I encounter the same problem, where "-" of both batteries is connected and I'm shorting them?

I'm sorry if I'm being really thick here. Thanks again.

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 3:52 pm

Does this concept circuit give you a better idea, of what you need to do? And this is not the advance option I was talking about btw.
McpRpiBattMeas.png
McpRpiBattMeas.png (21.83 KiB) Viewed 639 times
Note/Tip: You can not use four the same voltage dividers.

ophiothrix
Posts: 8
Joined: Fri Jan 04, 2019 8:45 pm
Location: Barcelona

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 4:48 pm

Brandon92 wrote:
Sun Jan 06, 2019 3:52 pm
Does this concept circuit give you a better idea, of what you need to do? And this is not the advance option I was talking about btw.

Note/Tip: You can not use four the same voltage dividers.
Thank you Brandon. This is very helpful for getting my head round it. But in the end the problem was painfully obvious and had nothing to do with the sensors or wiring on the Pi side. My four batteries are wired in 2 series of 2 batteries. So what I was doing by trying to connect the second "-" terminal, was breaking into the middle of the series and shorting one of the batteries. At the moment I was able to hook up two batteries that don't have any conflicting poles. To monitor the remaining 2, I will need to follow your suggestion of taking the differential. But I will need to first wire my own voltage divider, as the sum of voltages will exceed 25V.

Many thanks again to you and Erklei for helping me think this through!

ophiothrix
Posts: 8
Joined: Fri Jan 04, 2019 8:45 pm
Location: Barcelona

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 4:55 pm

Brandon92 wrote:
Sun Jan 06, 2019 3:52 pm
Note/Tip: You can not use four the same voltage dividers.
Could I bother you to clarify this last statement? I can't use the same voltage divider, i.e. connect each of the 4 batteries to the same single divider? Or does that mean that each of the voltage dividers has to have different resistances? I.e. R1≠R3≠R5≠R7 and R2≠R4≠R6≠R8?

Thank you.

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 5:47 pm

ophiothrix wrote:
Sun Jan 06, 2019 4:55 pm
Or does that mean that each of the voltage dividers has to have different resistances? I.e. R1≠R3≠R5≠R7 and R2≠R4≠R6≠R8?
Yes this statment is true. *For example V1, V2, V3, V4 are 10V each. And the maximum input voltage of the ADC is 5V. So. you make R1,R2 so that it will divide the voltage by 2. So at Vbat1 you measure nicely 5V. But when you use the same values for R6,R7. Then you will have a problem. Because, between the ground and Vbattery is 40V. So, at Vbat4 you would measure 20V. And that is to much for the input of the ADC.

By the way, what for kind of batteries are you using. Because 25V sound like a bit of a extraordinary one. And is it save for this type of batteries to be used in a parallel setup?

*in the ideal world

ophiothrix
Posts: 8
Joined: Fri Jan 04, 2019 8:45 pm
Location: Barcelona

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 6:16 pm

Brandon92 wrote:
Sun Jan 06, 2019 5:47 pm
By the way, what for kind of batteries are you using. Because 25V sound like a bit of a extraordinary one. And is it save for this type of batteries to be used in a parallel setup?
They are standard 12V lead-acid batteries. So the bank is "nominally" 24 V. But 12V is only orientation. At 80% charge the 12V battery actually has 12.5V voltage. So two batteries connected in series would give 25V. And during the charge cycle the battery voltage actually goes up to over 14.5V and even higher during equalisation process (over 15 V). So I would need to set up the divider to cope with up to 32V, just to give it some safety window.

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Problem with connecting multiple voltage sensors to Pi

Sun Jan 06, 2019 8:56 pm

A okay. So, you want something like this:
McpRpiBattMeasV2.png
McpRpiBattMeasV2.png (19.49 KiB) Viewed 583 times

ophiothrix
Posts: 8
Joined: Fri Jan 04, 2019 8:45 pm
Location: Barcelona

Re: Problem with connecting multiple voltage sensors to Pi

Mon Jan 07, 2019 1:52 pm

Brandon92 wrote:
Sun Jan 06, 2019 8:56 pm
A okay. So, you want something like this:
Yes, exactly. Thank you!

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Problem with connecting multiple voltage sensors to Pi

Tue Jan 08, 2019 7:10 am

No problem. Let me know if you have more questions.

Return to “Automation, sensing and robotics”