I partially fried my arduino, help me not do it again

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.

Why 10V ? You can use 6V or 7V.

The diode after the LM317 is okay. I think it is not needed, but it will prevent current running backward.

The diodes at the voltage dividers are not okay.
You could use diodes to clamp the voltage to 5V and GND, and use another resistor of 1K to the Arduino input.
In figure one, where it says "to Arduino A0", a diode (1N4148 or 1N4007) to 5V and a diode to GND, and a extra resistor to A0.

The On/Off switch should be in the (+) line, not the ground.
If you switch the ground and connect it with USB to a PC, it is hard to tell how currents will go, but you could damage the Arduino Nano.

If you want to be sure that the Nano doesn't steal current from the voltage dividers, you could increase the resistor value. For a good analog value, the total impedance should be 10k or less. So resistors of 15k and 33k will be okay.

It is possible that only a single pin, or only a single analog input, or the whole analog section is damaged. But if that happens, other parts of the microcontroller might also have been damaged. It is no longer reliable.

Erdin:
Why 10V ? You can use 6V or 7V.

10V seemed well within the arduino recommended limits which according to this page is 7-12V. However, 6V isn't in that range. What am I missing here?

Erdin:
The diode after the LM317 is okay. I think it is not needed, but it will prevent current running backward.

OK, good, that was my thinking about putting it there.

Erdin:
The diodes at the voltage dividers are not okay.

My thinking was that they would prevent currents running from one analog input to another. Why is that wrong?

Erdin:
You could use diodes to clamp the voltage to 5V and GND, and use another resistor of 1K to the Arduino input.
In figure one, where it says "to Arduino A0", a diode (1N4148 or 1N4007) to 5V and a diode to GND, and a extra resistor to A0.

The On/Off switch should be in the (+) line, not the ground.

Do you mean like in the figure I'm attaching now? I'm not sure I got the diodes right.

Erdin:
If you want to be sure that the Nano doesn't steal current from the voltage dividers, you could increase the resistor value. For a good analog value, the total impedance should be 10k or less. So resistors of 15k and 33k will be okay.

OK, I will change those, as shown in the figure I'm attaching. But I'm not sure I understand why. According to what I read, in a DC circuit impedance is the same as resistance. How does increasing resistor values, decrease impedance?

Erdin:
It is possible that only a single pin, or only a single analog input, or the whole analog section is damaged. But if that happens, other parts of the microcontroller might also have been damaged. It is no longer reliable.

Yes, I'm not going to use that arduino any more. I don't mind much, I see this as part of the learning process. Still, I don't want to fry my other arduino nano though.

The schematic in Fig4.png looks very good.
The 1N4148 are very fast, and will protect against nasty voltage spikes.
The 1N4001 ... 1N4007 have a larger capacitance, which is not a problem in this circuit.
One more thing, it is adviced to have 100nF at the input of the LM317. You can add it, or replace the 100uF with 100nF. I don't know if that is the minimum capacitor or if it is needed for the LM317 internal regulator circuit.

Okay, 6V is too low. If the regulated 5V on the Nano board is not accurate, it will influence the value of analogRead().
But 7V or 8V is better than 10V.
With 10V the voltage regulator of the Nano has to regulate the 10V to 5V. It will get hotter with higher input voltages, and it is only a small component.

The diodes in Fig3.png are not good. The inputs of the Arduino have very high impedance. For good analog values, the impedance of the circuit should be 10k or less. The diode makes the circuit impedance very high (in one direction) and the diodes have a capacitance. I don't even know what that will do with the signal.
And the diodes will not protect against voltages that are too high. The current is still going into the analog pin to the 5V.

The impedance is not decreased. Using 15k and 33k will increase the impedance of the circuit.
But up to 10k is still safe for a good analog value.
I assume that the V1, V2, V3, V4 measure something with a low impedance.
So the impedance of the voltage divider is 33k parallel 15k.
The 1K increases the impedance more, but it is still okay.
Calculator: 1/(1/33 + 1/15) + 1 - Google Search

Erdin:
The schematic in Fig4.png looks very good.
The 1N4148 are very fast, and will protect against nasty voltage spikes.
The 1N4001 ... 1N4007 have a larger capacitance, which is not a problem in this circuit.

OK, so I will use the 1N4148, I have a bunch of them anyway.

Erdin:
One more thing, it is adviced to have 100nF at the input of the LM317. You can add it, or replace the 100uF with 100nF. I don't know if that is the minimum capacitor or if it is needed for the LM317 internal regulator circuit.

I don't really remember where I got the 100uF capacitor from, it must have been an online tutorial or something. I see that in the datasheet a 100nF is mentioned instead as you say. I will replace it.

Erdin:
Okay, 6V is too low. If the regulated 5V on the Nano board is not accurate, it will influence the value of analogRead().
But 7V or 8V is better than 10V.
With 10V the voltage regulator of the Nano has to regulate the 10V to 5V. It will get hotter with higher input voltages, and it is only a small component.

Ah, so it's not for taxing the internal regulator of the Nano too much and offload the job to the LM317 instead. Thanks for explaining.

Erdin:
The diodes in Fig3.png are not good. The inputs of the Arduino have very high impedance. For good analog values, the impedance of the circuit should be 10k or less. The diode makes the circuit impedance very high (in one direction) and the diodes have a capacitance. I don't even know what that will do with the signal.
And the diodes will not protect against voltages that are too high. The current is still going into the analog pin to the 5V.

OK, so no diodes there, as per figure 4.

Erdin:
The impedance is not decreased. Using 15k and 33k will increase the impedance of the circuit.
But up to 10k is still safe for a good analog value.
I assume that the V1, V2, V3, V4 measure something with a low impedance.
So the impedance of the voltage divider is 33k parallel 15k.
The 1K increases the impedance more, but it is still okay.
Calculator: 1/(1/33 + 1/15) + 1 - Google Search

I'm still confused by this. You say that up to 10k is safe. By using a 33K and a 15K as you propose and the calculation you linked to, the impedance is:

1/(1/33 + 1/15) + 1 = 11.3125

but by using the 10K and 4K7 ones I currently have, that should be:

1/(1/10 + 1/4.7) + 1 = 4.1973

shouldn't the latter be preferable?

The impedance at 11k or 4k, that is not very important.
If it is 1M, the ADC value could be less accurate. The 10k is a rule of thumb.

The accuracy can be increased by averaging a number of samples in software. In practice, the average of only 5 samples will increase accuracy with 1 bit (one whole extra bit is a lot with small signals).

If the circuit is in an environment with a lot of electric noise, you might need to lower the impedance of the circuit. Or add a small capacitor (1nF or 10nF) to the ground to filter the high frequencies. But that is only in some special cases.
If the circuit would be 1M impedance, I would add 1nF or 10nF to the analog input and ground. In the sketch I would take the average of about 25 samples. The result would still be fairly accurate.

OK, that is very helpful. Thank you very much for all your explanations and proposals and for your patience. :slight_smile:

Erdin:
Okay, 6V is too low. If the regulated 5V on the Nano board is not accurate, it will influence the value of analogRead().
But 7V or 8V is better than 10V.
With 10V the voltage regulator of the Nano has to regulate the 10V to 5V. It will get hotter with higher input voltages, and it is only a small component.

I have a question on the input voltage. You point out 10 volts is to high or pushing it but the specs page recommends you use between 7 and 12 volts and says it can handle up to 20 volts.
http://arduino.cc/en/Main/ArduinoBoardNano
This caught my attention as I have some automotive Arduino projects I'm working on and had intended to hook them up directly to the 12 volt supply in the car which will at times be as high as 14.5 volts but still well within the 20 volt max rating. I'm always happy to learn from others though with some real world experience rather than just reading the specs sheets.

It all depends on how much current is used.
If a number of leds or relays are connected, the 14V might be too high.

gapan already used a LM317, so it is easy to let the LM317 take the heat.

This how to test it: if you can not keep your finger on the voltage regulator, it is too hot, and you should lower the input voltage.

The best solution is to use a DC/DC converter to lower the voltage. The DC/DC converters are very efficient and produce almost no heat and they have a large range for the input voltage.

Hmm... I still have a question about that voltage clamp. Reading this and assuming the voltage drop of the diodes is 0.7V, does that mean that I can only measure voltages ranging from 0.7V to 4.3V? And that if I have anything lower than 0.7V, it will still read as 0.7V or if I have anything over 4.3V, it will still read as 4.3V? Because that is definitely bad, I don't want that.

No, the diode has a voltage drop of 0.6 or 0.7 Volt.
The diodes start passing current if the voltage is -0.7V (current to ground), or with +5.7V (current to the 5V). The extra resistor of 1k protects that too negative or too positive voltage from the input pin. The input pin has also voltage clamp diodes inside the microcontroller, but they can handle only a little current.

So you have the full range of 0V to 5V for the analog input, as it should be.

Ah, thanks, I get it now. It's not that Vmax=5V and Vmin=0V, but it's Vmax-0.7=5V and Vmin+0.7V=0V!

Are those resister values in fig 4 on each of the arduino inputs the final values? I have a similar project and this thread has been very helpful to me. Also after the voltage divider why is there an additional 1k resister to the arduino input?

Also the two diodes you have across each input. Are they zener or voltage clipping diodes or just generic diodes. I saw you guys hashing it out above but wasn't quite sure on the final answer. Are they really required or just an additional layer of protection?

MalcolmV8:
Are those resister values in fig 4 on each of the arduino inputs the final values?

Yes, these are what I'm using now.

MalcolmV8:
Also after the voltage divider why is there an additional 1k resister to the arduino input?

Erdin:
The extra resistor of 1k protects that too negative or too positive voltage from the input pin.

MalcolmV8:
Also the two diodes you have across each input. Are they zener or voltage clipping diodes or just generic diodes. I saw you guys hashing it out above but wasn't quite sure on the final answer. Are they really required or just an additional layer of protection?

I have 1N4148 switching diodes, which as I understand it, will protect against voltage spikes and are an additional layer of protection. Just making sure that you won't get a too high (or too low) voltage in the arduino input pins.

Thanks!

If the extra 1k resistor is omitted, the clamping diodes would be parallel to the internal clamping diodes of the microcontroller. A current could damage the microcontroller because no one knows which diode would take the most current.

The 33k reduces the current so much, the internal clamping diodes should be able to take care of it. So the 1N4148 clampling diodes and the 1k resistor is just to be sure. If you connect the 33k to the mains voltage, the 33k starts smoking but the Arduino will be okay.

So, I have set everything up like in figure 4, as we talked about and I guess that the arduino is better protected now. But, there is still an issue. The arduino is still being powered by the analog pins that I'm using to measure V1-V4, so I can't turn it off with the on/off switch I have put before the Vin pin.

To give you an idea of what happens, if everything is connected (Vin and V1-V4), removing power from Vin, will not switch the arduino off.

Also, having everything disconnected (Vin and V1-V4), if I connect V1, nothing seems to happen. If I also connect V2, the arduino power led is very dimly lit. If I also connect V3, the arduino power led is fully lit.

One way I thought of solving this, is using four relays, one for each of V1-V4 and switching them on/off using the same on/off switch I use for Vin. I'm guessing that will work, but is there maybe a better way of handling this?

So the current through four 33k resistors make the led lit ?
I did not expect that.

If the V0...V4 are at 14 V, my guess is that 1.5mA is injected into the Nano board with four 33k resistors.

Do you have a multimeter ? How much is the voltage if it is turned off ?

Could you do a test ? Connect a resistor of 470 ohm to the 5V pin and GND pin of the Nano. The 470 ohm pulls the voltage below 1V at 1.5mA. The led should stay off after that.

I had never a problem like this, so I have not a ready-to-use solution.
Is it a big problem ?
The Nano is not running I suppose, only the led is lit.
You can remove the led.
You can increase the voltage divider resistors to 47k and 100k (at the cost of a less accurate analog value).
Four relays would work. You could use four small 5V reed relays.

I don't have it with me at the moment, but from what I remember, the voltages on each one of the analog pins that I'm using to measure V1-V4 was 4-4.5V and the voltage on the 5V pin on the arduino was probably about 0.6-0.7V.

I don't know if it's a big problem. One potential problem could be that because everything is running from batteries, it would be good to not draw any power when it's not being used.

I'll try the resistor you're talking about tomorrow. I'm going to use a 560 ohm one as I don't think I have any 470 ohm ones at hand. I'm guessing that's not a problem.

And I think I'm going to go with the relays anyway, it feels safer to me to just cut everything off.

You were right. I added a 560 ohm resistor between the 5V and and GND pins and the led went off. And you were also right that the arduino wasn't really on. It wouldn't do anything, it's just that the led was on.

But I have a different kind of problem now. In my first post I mentioned that I'm going to use the nano to switch four relays, according to the measurements I get in the analog inputs. The problem is that I get a voltage drop in the 5V pin as soon as I switch 3 or 4 relays on. Having 1 or 2 relays on, the 5V pin of the arduino measures at exactly 5.03V with my multimeter. However, switching on a third relay, will bring the voltage down to 4.6V and switching the fourth relay on, will bring it down to 3.7V! Of course my analog reads are messed up if 3 or 4 relays are on, with the added effect that if I have 4 relays on, the voltage clamp comes into play and the voltage in the analog input pins is clamped at ~4.3V. Taking into account that I plan to also add a couple of leds in there and probably also a buzzer this is only going to get worse.

So what are my options? So far I have thought about isolating the switching part of the relays as described in this page and feed the relays with a separate 5V line. I use a couple of relays that are similar to the one pictured in that page. I also thought about using MOSFETs to drive the relays. I'm not sure which one is the best (probably the first one I guess) or if there is a better solution. Any pointers here?