Go Down

Topic: Battery drain simulator (Read 801 times) previous topic - next topic


Hi everyone,

I have a project that uses a solar panel to charge a lipo battery and run the Arduino, among other things. I have code and a circuit that monitors the battery voltage accurately enough. My code will stop doing energy intensive actions if the voltage falls below a threshold.

My question is: how can I simulate battery drain?

I want to debug things while watching the voltage fall. I tried using a 10-turn potentiometer with very fine adjustment as a divider, but as soon as I start to turn the dial at all, the components start flickering. (I got it to mostly work with a Pro Mini drawing low current, but my full set up draws more.)

If my battery is at 3.8 vdc, is there a simple way to bring it down quickly (within minutes or seconds) to 3.3 so I can see if my code is behaving?



Perhaps I am a simpleton; to assure the code is behaving properly, why involve the complications of low battery into the equation?  I would alter the integer variable, via time based or otherwise, to view the outcome.  Once the base code has been established to operate in the expected manner, introduce the real falling voltage.  Perhaps you have performed this step already; if so, I apologize for interjecting.


Can you post your code and a circuit diagram?
How did you connect the pot?
What value pots do you have?

Simulating your input can be done in code with pot.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....


Yes, I can simulate the falling voltage within code (I have object-oriented code in C++ and I can inject a fake voltage) so I know it works that way. What I want to test now is the real deal.

I've attached a schematic of what I was testing. One reason for my real life test is that I'm going to introduce redundant solar panel/charger/battery and I want to see what happens to the circuit as one battery bank discharges. I'd rather not run it for a week to see the result.

I'm not so worried about the code, and it is spread across many files. I used a cheap 10k pot and then a less-cheap 10-turn 10k Bourns pot. I'm not sure I understand what you mean "in code with pot." I want to really be able to send the solar charger an input of 3.8 vdc and then dial it down to 3.3, 3.2, etc. Even if you take the charger out of the circuit, I want to send the 5v dc-dc step-up booster 3.8 vdc, then dial down until my code senses the battery is below threshold.

So, can I use my lipos and a pot (or something else) to simulate that drainage?



That setup could draw 300-500mA from the battery when GPS and WiFi is active
(6-8hours before a fully charged  batt is flat).
With that current, every 2-3ohm of the pot drops 1volt.
I doubt that you can adjust a 10k pot to <50ohm, so a 10k pot is totally unsuitable.

Why D2. It's only function is to make the boost converter work harder (and use more power).

A Mega is a poor choice for a solar/battery project.

Are you sure you can power those two devices from the pins of a Mega?

Most boost converters are not happy with a 10000uF capacitive load.

A 2watt solar panel might deliver 2watt (0.33A) in full sun.
Only ~1.4watt (4.2*0.33) of that could end up in the battery.
You might charge that battery in two full sunny days (if nothing is used).


Jan 19, 2018, 01:03 pm Last Edit: Jan 19, 2018, 01:18 pm by TomGeorge
What is your solar charger unit?

What does your mega actually do?
Apart from a WiFi and GPS, what does it do?
As stated earlier, a pot like that is not going to show as a variable battery voltage.

From what you have said;
  • You have a number of LiPo battery banks.
  • You have solar charger to charge them.
  • You want to measure the charge level in each bank.
  • You want the Mega to then control which bank gets priority charge.

I think you will be very disappointed with your 2W panel, you need more power than that to just run your hardware.

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....


Respectfully, I wasn't really looking for a critique of the whole circuit.  :)

My question is simply: how can I simulate battery drain?

I have a feeling Leo is correct and I need a very small variable resistance to do this. Any ideas?

I will answer some of the other points (but I really am just looking for a "drain simulator" idea):

I removed about half the circuit just for clarity (which back-fired). I've attached the whole thing now.

This is the third evolution of a robotic sailing drone. (I've sent 2 to sea already.) The Mega is used for the 4 hardware serials, which work better than software serial. It is in a low-power sleep mode 99% of the time. The peripherals are powered only one at a time, and not at start-up. The wifi does not go on the final project- it is used for my testing only. And the LDO is how I turn it off, I don't power it through Mega pins. The GPS draws 50mA so I use two pins to simply it.

I have run a similar rig on my roof for weeks successfully.

I got a bunch of help from this forum on the MOSFET arrangement. It is there so I can switch a 12vdc booster (the motor is actually 12v now, but I may change back to 6v).

I just noticed my A1 pin wire looks like it connects to GND, but it does not.

The diodes are Schottky and are there so that the better source will supply the step up booster.

I'm not clear why capacitors aren't desirable. The one after the step up is there to handle spikes in the Mega's needs. The ones after the chargers are to insure a smoother voltage for the analog pins measuring the voltage.

The "sail pot" detects the position of the sail.

I'm grateful for feedback, but again my question in this thread is about simulating voltage drop over time so that I don't need to wait to see how the circuit reacts.



I'm not entirely sure I understand the question, but I think you want to test the behavior of the Arduino software when the analog inputs (A0,A1) are at some levels.  Simply replacing those each of those inputs with the wiper of a potentiometer connected between Vcc and Gnd gives you a simple way to vary the voltage at those pins.

Putting circuitry around the batteries themselves is likely to confuse the solar chargers, so it's hard to say what's really being tested in that case.  If you really need to do accelerated cycle testing, perhaps using a smaller battery would do it, but then the charging currents might need to be changed.


what do you mean by the "real deal" ?

if the code relies on, say; int battVolt = analogRead(sensorReadingBatteryVoltage);
then simulating the decrease of battVolt by code is all you can really do.

if you want to model how it *really* decreases (like a graphed curve), then you should refer to the datasheet for how it behaves - failing which, you just have to actually do it for real - on site and live run.


Rather than put a resistor in series with the battery (which does not simulate the "real thing") you could use a much smaller capacity LiPo battery for testing purposes, which will discharge much faster.

But the real question is: what exactly do you want to learn? The discharge curve of LiPo batteries is pretty flat until the very end and if you allow the battery voltage to drop much below about 3.0 V, it will be destroyed.

Good reference material on LiPo batteries here.


I have already done testing within the code, i.e. injecting a fake battery object that returns a decaying voltage. I know that part works. But I've found that electrical circuits aren't as predictable as code (to me at least).

So what I really want to do is akin to what jremington suggests, use a small battery that discharges more quickly. But then I have to wait for it to charge back up to re-test. I don't own a bench power supply, but maybe that's what I need instead.

Not only will this test my code, it will prove that the higher voltage battery (when I use 2 banks) will take over when one falls. I can also plug my solar chargers into a simulated sun (wall plug) to make sure they respond accordingly.


Rather than use a variable resistor you may be better to use this sort of regulated circuit.

To get up to 3.7V or higher, your input voltage would be okay with 6V, 4 x AA batteries.
The max output of this circuit is the (input voltage - 2.5V).
Using this circuit all your current worries are taken care of.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....



I can also plug my solar chargers into a simulated sun (wall plug) to make sure they respond accordingly.
Do you have a series resistor in line with plug pack, as a PV is a current source, not a voltage source.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....


You could use a low value, high power resistor as a load to actually discharge your battery.

Use a MOSFET to switch it in or out of circuit.  You could then use PWM if you want to discharge at a lower rate.


Jan 20, 2018, 12:15 pm Last Edit: Jan 20, 2018, 12:46 pm by Johnny010

Go Up