One note: I just realised in drawing this a slight mistake. The Vin and GND to the Arduino are not on that side of the circuit as shown, but connected across the + and - of the 12V battery on the other side of the circuit.
QuoteOne note: I just realised in drawing this a slight mistake. The Vin and GND to the Arduino are not on that side of the circuit as shown, but connected across the + and - of the 12V battery on the other side of the circuit.In that case the whole circuit is probably flawed. Please send a clear drawing of how the circuit actually is. The MOSFETsource needs to be at the ground potential of the Arduino if the Arduino is drving the gate. Which MOSFET are you using?
The problem I see with your circuit is that you are charging your battery with a 15V rectangular wave with no peak current limiting other than the internal resistance of the 15V supply and the battery (and the 1.5milliohm shunt). Therefore you will get very high peak currents, which will probably damage the battery, and perhaps other components too. You need to change the circuit so that the battery is charged in such a way that the peak current limited to a suitable value. There are two ways to do this:
1. Run the mosfet in the linear mode, by feeding it from an analog output pin followed by an RC network to smooth the PWM. Ramp the PWM up slowly, monitoring the current, until you reach the desired maximum charging current. The mosfet will dissipate a lot of power, so it will need a good heatsink, and the circuit will not be very efficient.2. Smooth the PWM output using an inductor and flyback diode. You will need to increase the PWM frequency to a much higher value in order to use a low enough value of inductor for this to be feasible. The advantage of this approach is that it doesn't waste a lot of power. However, because of the higher switching frequency, you may need to use a mosfet driver in order to keep the mosfet switching losses low, otherwise you will need a heatsink again.
If you were to change the circuit to use high side switching (which will be easier of you use a mosfet driver chip), then you could monitor the battery voltage as well, which will help you tell when charging is complete.
I agree with MarkT that your current circuit is flawed. The Arduino will not be able to turn the mosfet off in that configuration unless the charging voltage is only slightly greater than the battery voltage. I suggest you use a circuit with high side switching, similar to the one you posted, but add a mosfet driver chip between the microcontroller output and the mosfet gate (TC4420 will do if the charging voltage won't exceed 18V). You can add your shunt and current monitor between the capacitor and the battery +ve terminal. Alternatively, if you don't need a common ground, then you can put the shunt in series with the battery negative terminal, and use an op amp to amplify the voltage drop sufficiently to feed into an Arduino analog input.
I would have thought you could stick with the N channel mosfet, but as other posters have said, it's ground needs to been connected to the arduino's ground.