Linear Voltage Increase


i am stuck on my project and really appreciate any help. I want to control voltage output from an external power source with my Arduino. I want to start at 0V and increase to the power sources max (which is in my case 20V).

I tried it with a motor driver but it turns out that i don't get a smooth curve and i did not now that the driver does not smooth the output so it still has its PWM characteristics. With that PWM solution the voltage gets from 0 to about 14V nearly instantly and then increases to 20V over time. (Measured with a Voltmeter, there is and will be no motor, i just need a somewhat linear voltage curve).
The code is pretty straight forward:

for( int i = 0; i < 255; i++ ){
  analogWrite(DC_MOTOR_PIN, i);

My circuit is pretty much like this, just a bit simpler as i have a "XY-MOS" Mosfet which is not available in Tinkercad. In that example it seems to do what i want it to do (see voltmeter): Login | Tinkercad

Anyway, seems i need another solution but my electric knowledge is pretty much non existing so really hope to get some help here. If i need to answer more questions please ask them, i do not know what may be important...

Don't trust your DVM on PWM.

How much current?
How much ripple?

For voltage only (no current) PWM with a simple RC low pass filter can work.
For no current and no ripple use a digital pot.
For voltage and current use a controllable power supply.
Or measure the effective voltage and control the PWM by a (PID...) regulator.

Hi, @erythana
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Can you post your circuit diagram in your NEXT post please, TinkerCad needs registration to view.
You should be able to EXPORT your diagram as a jpg image.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:


Current is unknown. I have three of these batteries in series:

Resulting in 18Volt and the current flows through my body because im building a Ionothoporesis-Device, therefor the resistance of my body is unknown and i guess therefor i cant tell the current.
Unfortunately, i do not know what a ripple is.

I guess i need a controllable power supply then? (Though that sounds like it is something bigger than a controller?) :E

Alright, will do.

Arduino Uno (but doesn't matter i guess)
Motor controller:
External power source:

(I hope it is correct, first time doing this. The pink wire, the common ground, might be wrong, but it also happened without it)

OK, so now we know what the actual purpose is, making answers more practical.

The body resistance is relatively high (probably in the Kilohm range) and the current relatively small (a few milliamps). The lantern batteries you cite are way more than capable, even the "smoke alarm" batteries implied in the diagram would likely suffice for this purpose.

"Ripple" refers to the voltage - and consequent current - going up and down as the PWM switches on and off. For many purposes such as controlling LEDs and motors, it does not actually matter that the output is continually switching between full on and full off.

For your application it is relative - such a dramatic switching would likely cause unpleasant nerve stimulation but a smaller variation would be acceptable so you can use PWM. You will need a circuit to smooth the PWM to a fairly consistent voltage (0 to 5 V) and use that voltage into an amplifier to achieve your higher (18 V) range.

The motor controller you cite is not however suitable for this.

Ripple is a minor regular fluctuation of a DC voltage.

The body resistance is typically in the 10k range. Check with your multimeter and the cables in each hand with wet fingers.

20 mA current through a body can be dangerous, e.g. when passing through heart or brains. Voltage below 40V is considered harmless even if it can have noticeable effects. DC is more dangerous, it can cause spasms so that a person can not get rid of the contacts.

The current that will be flowing will be very small - eg 20V / 10k = 2mA
A motor controller designed for handling 15 AMPS is totally unsuitable.

I'd suggest you try this

how it works
you generate pwm on A3 - its filtered by C1R4 and the voltage on the base of the transistor controls the voltage across R1 - so controlling the collector current.
PWM=100% will give about 4V across R1 - you can choose R1 to provide the current range you need. With R1=22 ohm you could potentially reach 4V / 22 = 180mA.
However a value of 100 ohm gives 4V / 100 ohm = 40mA which is probably more realistic - depending on the way you are making contact & skin resisitance.

R2/R3 feed a voltage back to A0 so by subtracting from 20V you know both the current and voltage across the terminals.

Thanks, now i have numbers to these statements! I did know that the resistance is high, but i did not now what "high" means in that case. Ohms, Kiloohms, Megaohms? Now i know! :slight_smile:

Jeah, my initial test, without trying to control the voltage was... interessting. Just submerging into and outo the water gave me shocks and crampings, once in there it was fine. Dont want to have that all the time during treatment :smiley:

I will measure that today after work, thought it varies by that much that it doesn't make sense to measure.

Are the 20mA dangerous dependent on voltage or in general?

Thanks for the numbers! I thought it would suit my needs as i do not have a real consumer (other than the resistance in my body) and that the current would be more like a short circuit, so really high. But with the bodies resistance it absolutely is not like this, didn't think of that...

Thank you for the circuit, trying to work that out! Is there a chance you also have some sort of Fritzing diagram of that? Would be easier for me to understand that as i do not know every component in the diagram. Anyway, i guess a good time to learn that...

Also, you are stating that i have up to 180mA here, i guess the danger with that is only in conjunction with the voltage?
As of the contact with the circuit, i submerge both of my hands into salt water, so the conductivity is pretty good

Right, that controller is overkill. Nonetheless it makes a difference whether the electrodes are fed by DC or AC. With DC they can polarize and change resistance dramatically. That's why an H-bridge will be the better approach. It also increments the AC amplitude to twice the battery voltage, possibly saving a battery. The code for a real AC bridge will be a bit difficult, I fear.

However the OP is talking about iontophoresis so the resistance will be substantially lower due to large contact area and wet electrodes. :astonished:

Again, you have missed what is actually being discussed here. :roll_eyes:

Have you Googled;

Iontophoresis arduino

Tom.... :smiley: :+1: :coffee: :australia:

So, does that mean that i just oversized the controller? I looked up a lot of modules but couldn't find a suitable one which allows me to control nearly 0 to 20V range.
Also i thought the current is high, maybe i "filtered" them out because of that...

Wow, actually i did not. As i didn't find a lot of information about Ionothoporesis in general i didn't expect such a thing at all.

So, by looking at that, the only difference here is probably another controller? Definately going for that build now though :slight_smile:
I guess that one should also handle my batteries with 20V just fine?

Edit: By looking at his code i just realized that there is no fiddling around with PWM, just turning the voltage on and off on those pins (full voltage and changing of polarity), basically meaning that i probably wouldh ave the same effect with getting shocked anc cramping when reaching into the water?

Thanks for the link, I couldn't find out what that word means.

""Time spent on reconnaissance is seldom wasted." (variously attributed to the Duke of Wellington, Rommel, or the sixth century Chinese general and strategist Sun Tzu,

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.