In the circuit displayed below, I have a microcontroller supplying current to the base of a NPN 2N2222 transistor. When the battery is at 9V, this setup works great: the microcontroller can supply 5mA and fully open the transistor.
When the battery drops voltage over time, however, this causes a massive change the amount of current required by the microcontroller/base to open the transistor. (see diagrams below)
What my goal is:
I want to use PWM supplied from the microcontroller to the base to control my 6V motors, which are being powered from a 9V battery, using somewhere around 2-12mA of current from the microcontroller. I have read up on base biasing, but I have not been able to reproduce the results I want on my own. I have a feeling that this will all boil down to some basic V=IR logic, but despite my best efforts I haven't been able to think of a way to do so.
Does anyone have any advice on how they would change this circuit to achieve that goal? I really appreciate your time.