Smartphone controlled charging
I have an older smartphone that I use exclusively as a hotspot for my private wifi network. This means that I should always leave the phone connected to its charger, but I don't like that. So I decided to add a circuit that automatically connects the charger when the charge level drops below 30% and instead disconnects it when the charge exceeds 70%. Here is a photo of the device in operation:

The circuit is connected, as seen in the photo, to the audio output of the phone. Why? The reason is simple. I have programmed an App for Android that runs "in the background", that is, even when it does not appear on the video. Every 3 minutes the App performs a “service” which simply consists of reading the battery charge level and the “plugged” condition ( charging ). If the level is lower than 30% and the operating status is - not charging - then it plays an audio file with the DTMF telephone tone relative to the digit “4” which starts the charge; if, on the other hand, the level is higher than 70% and the operating status is - charging - then the DTMF tone that is reproduced is that of the digit “8” which interrupts the charge in progress.
Let's see the wiring diagram, divided into sections; the first part is the circuit that interfaces with the phone's audio jack output:

I bought a pair of 3.5mm 4-pin jacks with wired wires and USB-A output. Once disassembled, I saw that the USB plug contained a small CS with some components, so I cut the wires and connected a connector, as seen in the figure. The colors written on the diagram correspond to my jack, but they are NOT necessarily the same as those of another plug. Check the correspondence of the 4 contacts with a tester. This circuit mixes the two left-right channels and amplifies the signal. The 120 Ohm resistors at the input are used to charge the smartphone output. Without them, the phone does not notice that it has a connected circuit. To tell the truth, in an A5000 smartphone (year 2011) any jack is inserted activated the audio output. Well, you see the circuit output connects, via a capacitor, to the next DTMF tone decoding module. Here it is below:

The UM9204 chip is very common (and very old) and I got it from a circuit presented on an old page of mine . The operation is simple: the audio signal present on pin 7 (dtmf in) is analyzed and if it corresponds to one of the DTMF tones used in telephony (mix of precise frequency pairs) the DV line (data valid) is brought to a high level and on the lines D1..D8 the combination in binary relative to the digit appears. Note: the "0" comes out as ten (binary 1010). Now, we will use the DV, D8 and D4 lines for our purpose. Obviously, the D8 line will not be high only when the tone relating to the digit "8" is present, but also for the "9" and "0", as well as the D4 line will be high with the digits "4", "5”, “6” and “7”, but for this application there is no problem.
The DTMF tone emitted by the phone lasts about 200mS (the .ogg files I generated with Audacity , an excellent open-source software for processing audio files) and therefore the DV, D8 and D4 signals are temporary, while we need a stable command signal, both for the on and off conditions. So, we need a flip-flop and we make it with the most classic of logic gates: NAND. Here is the circuit:

A classic Flip-Flop set / reset. The section on the right is the actual flip-flop, the one on the left we need because the set-reset needs a low level to activate and instead D8 and D4 go to a high level, as well as DV. So, the section on the left behaves like this: on pin 11 and on pin 3 in idle conditions we have a high level and the output - drive in- is in a stable state (it can be high or low, it depends on the previous condition). When the dtmf decoder receives a tone “4”, the DV and D4 lines become high and remain there for about 200mS. The output 11 of the first NAND goes to low level and consequently the output 8 goes to high level (driver on) AND IT REMAINS THERE, thanks to the other NAND that switches pin 6 to low level. The opposite happens if the tone "8" is detected. In this case DV and D8 will go high and consequently pin 3 will go low, making the flip-flop switch, so the output - drive in - will go low (driver off). In a set / reset flip-flop it is not permissible for both the set (pin 10) and reset (pin 4) lines to go low at the same time! If this happens, the result will be that the output - drive in- it will go high, but the condition will not be stable, it will only become high when the set / reset lines return to the high state, but the output (pin 8) does not necessarily remain high, it could become low depending on which signal is disabled first.
Now that we have our machine almost complete, we need the driver that will bring the 5V power supply to a USB connector where we will insert the phone charging cable. Here is the scheme:

The mosfet is in an 8 pin smd package, so I had to use an adapter. As usual, my circuits are optimized to work with the components I have available in my small mobile lab. I only had the B3942s, so I used those. The operation is elementary: when the signal - drive in - becomes high, the 5V of the external power supply ends up on the USB connector, going to recharge the phone. If the signal - drive in- it is low, the 5V is disconnected and therefore the phone no longer charges. I also put a red LED to have an indication of the charging phase. A note for jumpers J1, J2 and J3. Reading the USB specification, each charger should have a chip capable of negotiating the charging current. In practice, this exists on very few devices, but there are two modes that should work even without data exchange over USB. The first is to close jumper J1 (and only him!) By shorting (with a small resistor) the data lines D- and D +. This activates the "charger" mode, ie give me all the current you can. Closing instead J2 and J3 (not J1) we will put the D + and D- lines to GND independently of each other with 15K resistors. In this way, the basic charging mode should be activated, with a maximum absorption of 100mA.
Do I forget something? Oh yes! To work, this circuit must be controlled by an App... Here is a screenshot:

The panel is minimal: we see 4 buttons and a checkbox. To start, touch "service start" and the checkbox will become "checked" which means that even closing the application, the service will continue to run in the background and check the battery status. What is the "service stop" for? Since the background service is always running, if we really want to close the App, we have to disable the service or it will restart every three minutes. The other two buttons "test ON" and "test OFF" are used to manually control the connected circuit. In practice (after having done the start service) the ON key will make the DTMF sound of the digit “4” and the OFF key the one of the digit “8”. This is useful for setting the right volume for multimedia audio. In fact, there is no volume adjustment on the circuit and therefore you will have to do it on the phone. Start at 50% volume and verify that the ON and OFF work well. Go up in volume a little and check again; stop when, increasing the volume, the circuit no longer works (probably distorts). At this point, take the average between the minimum and maximum volume at which it was functioning correctly and place yourself there. It should be the most reliable position.
You will find the zipped App in the “files” section. Password is: eficara. Check the SHA1 to be sure the file is the original one, not corrupted.
I remind you that I take no responsibility for any problems that may arise with the download and / or installation of the material made available. It is material of a hobby nature and made available free of charge, so you, by using it, take full responsibility. I am not an expert on "legal terms", but I hope the concept is
clear enough.