rough circuit for battery getting charged and discharged simultaneously

Battery is expected to receive supply from generator (variable input) and simultaneously it is getting discharged through a resistor. Can anyone help me to build rough basic circuit for this please
New to battery universe.

Which Arduino will you be using ?

Arduino Uno.. actually nominal voltage of battery is 40V and supply to it is varying from 30V for 10 sec then 50V for next 20 sec and again 30V for last 10 sec. So battery is getting charged for the middle 20 sec only and it simultaneously is expected to get discharged with 50 ohm resistance. I am unable to build ckt to show battery is charging through one ckt and discharging through another ckt at the same time.

Maybe a solar charge controller can help with this. This varying input with a continuous output is a typical use case for solar cells.

Hi wvmarle,
could you provide some details please.


solar charge controller.

It would also be useful to know what type of battery this is. Some battery types have very specific charging requirements and things can go very bad very quickly if these are not met.