 # How to detect voltage between 100v - 130v DC?

In a circuit I am building, I will have a source voltage of somewhere between 100VDC and 130VDC. This voltage will vary at any time and is not predictable. PWM will be used to turn a mosfet on/off at a rate that will turn the higher voltage into 36VDC EXACTLY to supply a load.

For example, if the source voltage is detected to be 100VDC, then the arduino board will calculate that a MOSFET will need to be turned on 36% of the time in order to supply 36VDC for the load. (36vdc / 100vdc)

For example, if the source voltage is detected to be 123.5VDC, then the arduino board will calculate that the MOSFET will need to be turned on approx. 29% of the time in order to supply 36VDC to the load. (36vdc / 123.5vdc)

The thing that I am struggling with is... How can I detect the source voltage?? I know that the lowest it will ever be is 100vdc and I know the highest it will ever be is 130vdc, and it can be anywhere imbetween these two values. Please help me understand how I can get my arduino board to detect the exact voltage that the source voltage is at any time?

Thanks.

That's a sufficiently high voltage that safety is a major concern (what is the source of voltage? how much current could it source at max?).

that's not as easy as you imagine... you may need a PID algorithm (there's a library)

a simple voltage divider with a big (in both senses) resistor on the upper side may work but safety remains a concern

you may need an optocoupler and a P-channel mosfet on the 130v+ line for switching

if you are trimming a solar system you are wasting a HUGE amount of precious power

screwpilot: that's not as easy as you imagine... you may need a PID algorithm (there's a library)

a simple voltage divider with a big (in both senses) resistor on the upper side may work but safety remains a concern

you may need an optocoupler and a P-channel mosfet on the 130v+ line for switching

if you are trimming a solar system you are wasting a HUGE amount of precious power

There's no need for PID because this is not a closed loop control I think (yea, the load may affect a bit the supply but when it gets steady, there shouldnt be any more varations, I think those 100-130 V variations come from another reason, maybe due solar energy or something like that).

You just need to find the function that outputs duty cicle and its input is grid voltage level. I'd graphic some points and see if it is linear or an Hyperbole (you already have two points, (100,36) and (123,29)). Arduino should compute that function without trouble each time the voltage changes, then you get a fixed duty cicle to each voltage between 100 and 130 VDC.

And as suggested before, I'd use big resitors as voltage dividers and an opamp to adjust voltage between 0-5V and be readable by arduino analog pins.

2W resistors should be sufficient for a step down voltage divider. We're not talking about driving a load with a lot of current so the dissipation should be minimal.

a regulator without a feedback?????????

screwpilot: a regulator without a feedback?????????

I don't think regulation has been mentioned yet. for all we know the output is simply driving a servo to move a needle on a meter.

The thing that I am struggling with is... How can I detect the source voltage?? I know that the lowest it will ever be is 100vdc and I know the highest it will ever be is 130vdc, and it can be anywhere imbetween these two values. Please help me understand how I can get my arduino board to detect the exact voltage that the source voltage is at any time?

[u]Voltage Divide[/u]r

Let VIN = 130V Let Vout = 4V Let ILOAD = 1 mA (0.001 A)

RTOTAL =Vin/ILoad = 130Vdc /0.001 A = 130 k ohm

Vo / VTotal = 4V/130V =0.03076 R2 = (0.03076) * Rtotal = 4 k ohm R1 = Rtotal - R2 = 130 k Ohm - 4 k ohm = 126 k ohm

R1 (from Vin to R2) = 126 k ohm R2 (from R1 to GND) = 4 K ohm Vout = connection point of R1 and R2

P(R1+R2) = 1 mA * 130V = 130 mW (use 1W or 2W for safe margin) Analog input max voltage = 4V dc @ 130V in.

so raschemmel… if I am understanding your description of the solution correctly… I have drawn this circuit diagram of how I would have things wired up. Is this correct?

In your calculations… Rtotal = Vin / Iload
Can you explain this? Where is Iload? is this the current through R1? Did you pick 1mA for any specific reason?

So using the resistor values you have provided, when Vin = 130vdc, then Vout =4vdc. Is this how I can calculate what the Vout will be when Vin = 100vdc?

R2 / Rtotal = Vout / Vtotal
4000 / 130 000 = Vout / 100v
Vout = 3.077vdc.
So when Vin = 100vdc, then the arduino will get a 3.077vdc signal at the analog input pin. Correct?

For everyone else following this thread… The source voltage is coming from an induction motor converted to a permanent magnet generator. The voltage produced by this generator fluctuates depending on the speed that the generator is turning. I need the constant 36vdc to power LED lighting. By measuring the supply voltage (100 - 130vdc), I will be able to program the arduino board to turn a power mosfet on and off at the correct rate in order to produce the 36vdc needed for the LEDs. If the supply is at 115v, then the mosfet will need to be turned on (36/115) x 100 % of the time, or 31.3% of the time. If the supply is 130v, then the mosfet will need to be turned on (36/130) x 100 %, or 27.7% of the time. Hope this makes sense to everyone.

It makes sense, but I don't think it will work that easily. Will your LED driver tolerate 130V pulses? You can approximate a 36V supply by feeding a capacitor. But the pulse width required will vary greatly with load. Is your LED light source variable? And even if not, would you build in a way to "unload" the capacitor?

Paulcet: It makes sense, but I don't think it will work that easily. Will your LED driver tolerate 130V pulses? You can approximate a 36V supply by feeding a capacitor. But the pulse width required will vary greatly with load. Is your LED light source variable? And even if not, would you build in a way to "unload" the capacitor?

I kind of left my question vague at the start of this thread for this reason.. I really just wanted the answer to my voltage sensing question without having to explain every other detail about the system.

But since I've got my answer, I guess I can humor the rest of you and discuss my whole circuit. To answer your question.. I will basically be buildling a "switching voltage regulator". In order to get my switching regulator to output the most stable 36 volts possible, I needed to know the supply voltage being fed to it. Now that I know how to accurately detect the source voltage with the arduino, I will be able to make a switching regulator that will use this information when creating the 36 volts dc.

It doesn't matter weather my LED load can handle 130vdc pulses.. The load will never see those pulses. What the load sees will be a smoothed out version of the pulsed supply voltage. This will be accomplished with appropriately sized capacitors and inductors, or simply a low pass filter. Much like how an AC waveform is rectified and smoothed to create DC voltage.. The PWM pulses can be smoothed as well.

localbroadcast: I kind of left my question vague at the start of this thread for this reason.. I really just wanted the answer to my voltage sensing question without having to explain every other detail about the system.

But since I've got my answer, I guess I can humor the rest of you and discuss my whole circuit. To answer your question.. I will basically be buildling a "switching voltage regulator". In order to get my switching regulator to output the most stable 36 volts possible, I needed to know the supply voltage being fed to it. Now that I know how to accurately detect the source voltage with the arduino, I will be able to make a switching regulator that will use this information when creating the 36 volts dc.

It doesn't matter weather my LED load can handle 130vdc pulses.. The load will never see those pulses. What the load sees will be a smoothed out version of the pulsed supply voltage. This will be accomplished with appropriately sized capacitors and inductors, or simply a low pass filter. Much like how an AC waveform is rectified and smoothed to create DC voltage.. The PWM pulses can be smoothed as well.

You should look some schematics of buck dc converter.

localbroadcast: I will basically be buildling a "switching voltage regulator".

Is there a compelling reason to roll your own rather than buy one?

JimboZA: Is there a compelling reason to roll your own rather than buy one?

is that a serious question???

If I build my own, I can customize the output voltage and current so that it matches my needs exactly. If I want to tweak anything, like say, run the LEDs at 35 volts instead of 36 volts, I can make this change much easier on a regulator I've built vs. modifying a regulator I've bought.

An obvious benefit is the price. Switching regulators, especially at the amperage I'm going to be building, can get pretty expensive. Building it myself will dramatically reduce the cost.

The buck converter is a great circuit to incorporate into my system here. Thanks for the tip. It's basically whats I was going to be building, but now that I know that it is called a buck converter, I can google that term and come up with lots of circuits that are already built and working to compare with. It should help me figure out the correct size of the inductor and capacitor to use in the filtering aspect of my switching regulator. Thanks.

I actually found a great site Buck-converter design demistified

This site goes step by step allowing you to size all the needed components.

localbroadcast: is that a serious question???

Yes it was, why wouldn't it have been?

That’s a lot of potential to monitor. Consider this opto-coupler for ISOLATION:

https://www.fairchildsemi.com/datasheets/H1/H11F3M.pdf

Connect a pull-down resistor to an Analog input and one end of the H11F3, connect the other to 5V.

Choose a suitable resistor on the photo-diode side to give you between 2 and 20mA through the diode.

so raschemmel.. if I am understanding your description of the solution correctly.. I have drawn this circuit diagram of how I would have things wired up. Is this correct?

YES. The circuit schematic is correct, but the values will change in the future (in Reply#21)

In your calculations... Rtotal = Vin / Iload Can you explain this? Where is Iload?

The arduino ADC input A0

Let VIN = 130V (Vin of the Voltage Divider) Let Vout = 4V Let ILOAD = 1 mA (0.001 A) (ILoad here was the Voltage Divider current)

RTOTAL =Vin/ILoad

= 130Vdc /0.001 A = 130 k ohm

is this the current through R1?

NO YES

Did you pick 1mA for any specific reason?

Not really. I just picked a very low value. After reading your reply I decided my answer was useless without proof of load current so I redid it after looking it up. (Yes. My bad.)

So using the resistor values you have provided, when Vin = 130vdc, then Vout =4vdc. Is this how I can calculate what the Vout will be when Vin = 100vdc?

YES.

R2 / Rtotal = Vout / Vtotal 4000 / 130 000 = Vout / 100v Vout = 3.077vdc. So when Vin = 100vdc, then the arduino will get a 3.077vdc signal at the analog input pin. Correct?

YES 4 V is to 130 V as x is to 100V Simply multiply 0.03076 * whatever voltage you are interested in to calculate the input voltage you should get with that voltage. ie: (0.03076)*(100) = 3.077 V dc.

Vout = 4V is chosen to be the input voltage to the ADC for 130 V.

Your post title says nothing about rest of your circuit. You post was how to detect the voltage. (which I answered)

You asked how I picked 1 mA. The answer is I pulled it out of the air.

After you asked me I decided to look it up:

The ADC current is actually 140 uA @ 25 deg C so: (Section 35.11, Figure 35-40, page 608)

ATmega328 datasheet

[u]Voltage Divider[/u]

Let VIN = 130V Let Vout = 4V Let ILOAD = 0.140 mA (0.000140 A)

RTOTAL =Vin/ILoad = 130Vdc /0.000140 A = 928571 k ohm = approx 1 Mohm.

Vo / VTotal = 4V/130V =0.03076 R2 = (0.03076) * Rtotal = 0.03076 * 928571 ohm = 28562.8 = 28.6 k ohm R1 = Rtotal - R2 = (928571 ohm - 28.6 k ohm) = 900008.1 ohm = 900 k ohm

R1 (from Vin to R2) = 900 k ohm R2 (from R1 to GND) = 28.6 k ohm

Vout = connection point of R1 and R2

P(R1+R2) = 140 uA * 130V = 18.2 mW (use 1W for safe margin) Analog input max voltage = 4V dc @ 130V in.

You have to calibrate your system to the exact ADC current. R2 should be a 10k fixed resistor in series with a 30k pot to give a good range of adjustment. (You can play around with combinations like a 20k fixed and a 20k pot (wired as a rheostat) etc You have to calibrate the circuit using a voltmeter and adjusting the pot until the calculated value read by the arduino matches the value displayed on a DMM. Once you get that far you can turn off the power and measure the resistance of the pot wired as a rheostat (only wiper and one terminal used). If you can find a pot 5k above the measured value then you can replace the 30k pot with the a lower value. Either way the calculation is a first approximation and you have to determine ILoad (the ADC current) empirically. When the ADC reports the value you are reading on your DMM then the circuit is calibrated. The ADC current is consistent at the same temp.

Using fixed PWM is not a buck converter. Merely switching a MOSFET on and off gives you an instantaneous switched power, but won't regulate voltage to 36V.

Let's say the voltage generated is 100V. So you set the output of the Arduino PWM to 36%.

But what you get at the LEDs is 100V on for 36% of the time, not 36V. No, you can't just add a capacitor to smooth it. Why? Because the amount of charge when the MOSFET is on depends on the current of the source minus the load current, and the discharge depends on the load current. To keep the capacitor from merely charging up to 100V almost immediately, you'd need to add some resistance. But once you do that, you lose all advantage of using a switched regulator. It doesn't matter if you merely use a linear regulator or switch in a lower resistance 10% of the time, the same efficiency results.

When you add an inductor as an energy storage device, kind of like a flywheel, it changes everything. The voltage you get out is -not- merely the PWM percentage, but a complex relationship between the amount of inductance and the difference between the generated voltage and the output regulated voltage, and the amount of current drawn by the load.

There are ICs designed specifically for this task, to take an input that may vary over a much wider range while supplying a constant regulated current to a bunch of LEDs in series.

Polymorph… you seem to be confused. The use of a mosfet to pulse the source voltage on and off (100v for example) to create a lower voltage (36 volts in this case) is a very well accepted way for voltage to be regulated. These are called switching regulators, and can be many times more efficient than linear regulators. I don’t plan on just throwing any old capacitor in there to smooth the 100v pulses down to a constant 36vdc… It’s a little more complex than that… but not much more complex. I’ve attached a schematic of a basic stepdown converter. This is what will turn those 100v pulses into a smooth 36vdc. There are a number of calculations used to determine the sizes of the capacitors, diodes, and inductor. Once you figure out the correct components to use, there aren’t any other obstacles!

I will not be using the arduinos PWM output to create the on / off switching action of my switching regulator. The arduino will be used to control the switching, but I will be using my own code to create the exact timing of the pulses. This way I control the switching frequency, which can affect the efficiencies and component sizes…

raschemmel… Thanks for the updated calculations. I still am having some difficulty following what you’ve done…

You say that:
Rtotal = Vin / Iload

Shouldn’t it be:
Rtotal = Vin / Itotal

Itotal = IR1
IR1 = Iload + IR2

? ? ?

Do you follow why I’m getting confused with your calculations? 