I am trying to use an Arduino Nano, to create a voltage meter in order to measure four different battery voltages (V1-V4), that would also switch four relays respectively, according to how much the voltage is for each one. I'm still very new to electronics and I might be misunderstanding something, so I will try to explain in detail what I'm doing, so please bear with me.
I'm powering my arduino through another 12V battery (nominal) that I know will output a maximum of ~14.5V. I know that is outside the Nano's limits, so I'm using an LM317 voltage regulator as shown in attached figure 1, to bring the voltage down to ~10V that should be suitable for the Nano. I'm feeding those 10V to the Nano's Vin pin.
According to my tests, if I feed 10V to the arduino Vin pin and then connect the USB cable to my PC, it will still keep on drawing power from the Vin pin and the 5V pin will have a solid 5V output (so does the AREF pin), so that helps with accuracy in analog reads. If I only use the USB cable to power the arduino the 5V output will only have ~4.6V. Since I don't want to have the arduino connected to my PC all the time and I want a stable AREF, I think I'm safe in using the arduino this way, feeding 10V through the Vin and for testing purposes, connecting it to my PC's USB port. Please tell me if I'm wrong in this.
For each one of the four voltages that I'm reading (these are separate sources from the one I'm using to power the arduino), I'm using a voltage divider as shown in figure 1, to bring the voltage under the 5V limit of the arduino. V1-V4 should also output something between 11-14.5V. All ground connections are tied together.
The first problem I encountered, was that I needed a way to switch the arduino off. I was astonished to find that if I disconnected the (+) cable from the battery that I'm using to power the Nano, it would still keep on working! Somehow it received power throught the A0-A3 pins, nothing else was connected. I wasn't aware that this could happen. My idea, which in retrospect probably wasn't that good, was to disconnect the GND connection instead. So I disconnected the ground from the entire circuit using an on/off switch as shown in figure 2. That certainly made the arduino turn off but I should probably have used a multimeter to check if anything else was happening between the pins that stayed connected.
I left the arduino connected like this overnight (GND disconnected, everything else connected) and next morning I found that it would not be powered through the Vin pin anymore. I'm measuring 10V in the Vin pin, but the arduino will just not switch on. At the same time, I'm measuring ~0.8V at the 5V pin. So I probably fried something there. But, the arduino will still work if I power it through the USB connection to my PC. I also found that the readings I get from the A0 pin are a lot lower than they should be. For example if I connect V1 (through the voltage divider) to A0, I get an analog reading of ~400 (0-1023 scale), but if I connect it, through the same voltage divider to any other analog input, I get an analog reading of ~900. All other analog inputs seem to be working. So, I probably fried A0 too.
My next idea on how to prevent this from happening again is to fit diodes (1N4007), to every (+) input I have, as shown in figure 3. Would that work? Any other ideas on how to prevent this from happening again? What am I doing wrong? I have another Nano that I can use, but I don't want to fry that one too.