I’ve been using the Particle Electron for a bit of time now and one of the things I want to do is to measure voltage. What kind? Ultimately AC and DC. I’m sure its not as easy as connecting an analog pin to the voltage source. I’ve search the forum and google for a few days and haven’t found anything that starts on my “level”. I’m more of a software guy and have enjoyed learning a lot about hardware.
Initially I’d like to measure a voltage source of 12VDC.
Pointers to what’s been written about this topic or advice is greatly appreciated.
As for measuring AC I have not done it with the Photon yet, I have done it on other types of boards. Basically I used a small transformer (like a door bell transformer) to step the 120 vac down to as low as you can find, say 6 vac, hook the output to a bridge rectifier to convert it to DC.
Measure the rectifier output with a DC voltmeter.
Then use the a voltage divider to give you a dc voltage (< 3.3 vdc) that is proportional to the AC voltage that feeds the transformer primary. Some door bell transformers have an AC plug that will plug directly into a wall receptacle.
Feed the positive (< 3.3 vdc) signal into an analog pin, the negative side of the bridge to the Particle ground pin.
Write the code to read the pin which will give you a number, convert to a voltage value, a little code to convert that to an AC voltage (most of the code should be available here in the forum).
I’d like to do something similar, but I need to measure a voltage range of 24-37 VDC and a current up to 10 amps. I’d love to use a commercially available board, like the INA219 voltage & current sensor chips, but that is only good to 26 volts DC and 3.2 amps. Is there a board that will handle a higher power?
This is a solar panel application with the Particle Electron.
@undergrounder996, the INA169 is designed to output a proportional voltage for measured current. The device is a unipolar (only for DC current and voltages) “high side” current sensor. It senses current by measuring the small voltage drop across a low-value sensing resistor connected to the “high side” of the measured circuit. That means it’s between the battery/DC source and the circuit being powered. A “low side” sensor would be between the other side of the powered circuit (typically GND) and the actual GND.
If you look at the datasheed for the AttoPilot, you will see that the sensing resistor is 1.0 milliOhms for the 45A current range. The INA169 senses the voltage drop across that resistor which, by Ohms law, is proportional to the current flowing through it. The output of the INA169 is scaled to a max of 3.3v. You will also notice a voltage divider made up of three resistors which scales the voltage being measured so that it remains below 3.3v.
With the 45A and 13.6V configuration, the output values are 242.3mV / Volt measured and 73.20mV / Amp measured. Using two analog inputs of the Electron, you can then convert the ADC values to their respective equivalent current and volts.
Here is a nice article from Sparkfun on measuring current with the INA169.
I’m not sure you could use their breakout board directly as the copper traces most likely can’t handle 10A. The voltage part of the measurement is done by a voltage divider so you can use AttoPilot’s divider design for the 50V range.
BTW, the AttoPilot website is not working so they may be out of business.
You can also explore using hall affect (magnetic flux) sensors for measuring current. These don’t affect the circuit they are measuring.
@undergrounder996, there are a couple of things you need to know about the devices you chose:
The voltage divider board MUST NOT have an input voltage exceeding 50V as the output will exceed the max 3.3v analog input of the Electron. At 40V, the input to the ADC will be 2.5V.
The ACS712 is an older part which is labelled as “Not for new design”. If you plan to make a product, keep this in mind. This device is 5v powered and measures bipolar currents so the “zero” output sits at Vcc/2 or 2.5v. The board you specified outputs 100mV / Amp. So at 10Amps, the output will be 2.5v + 10*100mV = 3.5V which will damage the Electron’s analog input. A resistive voltage divider could be used at the output of that board to scale the output to 3.3v like in this application note from the datasheet (minus the diode which you don’t need).
@undergrounder996 What exactly are you trying to accomplish with measuring the voltage of the solar panel?
Are you using a Solar Charge Controller?
If you use a Victron MPPT solar charge controller which cost $99 you can tap into the data output stream that provides solar panel input voltage and current + battery voltage and the current flowing into the battery.
The voltage input on the 15A unit is 75v and these charge controllers work really good.
If you don’t like that, then do you really need the voltage of the solar panel but maybe just the wattage that it’s pushing into the battery?
If so then you could just measure the battery voltage and the current flowing from the solar charge controller into the battery using the standard INA219 chip since your battery voltage will be below the max input on the INA219.
@peekay123, Thanks for the information. For the voltage divider, my application cannot exceed 37VDC, so I should be safe there.
A few questions about the current measurement with the ACS712:
Not sure what “not for new design” means. How much longer will it be available? Is there a way to find the replacement?
I thought I read that the Electron’s pins were 5V tolerant. (datasheet).
All pins except A3 and DAC are 5V tolerant (when not in analog mode). If used as a 5V input the pull-up/pull-down resistor must be disabled.
I’m not really sure what that means, though.
The other option would be to run the ACS712 in the other direction, so that the output would go down as the current increases. (i.e. switch the input leads). Would that work?
I’m surprised measuring current and voltage is turning out to be so difficult. Maybe it’s just my amp and volt ranges.
This is an existing setup in a remote location, so I was hoping not to alter the existing control scheme.
There is no battery. The solar panel provides power directly to where it is needed. The purpose of the current and voltage monitor is to keep track of the performance of the panel, to know if it’s degraded, dirty, etc.